function PopupBoxUpdate(event){
	if (in_browser == "chrome" || in_browser == "safari" || in_browser == "ie" && (in_browser_v == "6" || in_browser_v == "5")){
		scroll_top = document.body.scrollTop;
		scroll_left = document.body.scrollLeft;
	}else{
		scroll_top = document.documentElement.scrollTop;
		scroll_left = document.documentElement.scrollLeft
	}
	
	if (popupbox_height > 0){
		popbox_height = popupbox_height;
	}else{
		popbox_height = parseInt(popupbox.style.height);
	}
	
	popbox_width = parseInt(popupbox.style.width);
	pos_top = event.clientY + scroll_top + 17;
	pos_left = event.clientX + scroll_left + 10;
	
	if (in_browser == "ie"){
		sh = document.body.offsetHeight + scroll_top;
		sw = document.body.offsetWidth + scroll_left;
	}else{
		sh = window.innerHeight + scroll_top;
		sw = window.innerWidth + scroll_left;
	}
	
	popbox_bottom_pos = pos_top + popbox_height + 30;
	popbox_right_pos = pos_left + popbox_width + 35;
	
	if (popbox_bottom_pos > sh){
		pos_top = event.clientY + scroll_top - popbox_height;
	}
	
	if (popbox_right_pos > sw){
		pos_left = event.clientX + scroll_left - popbox_width - 25;
	}
	
	popupbox.style.left = pos_left + "px";
	popupbox.style.top = pos_top + "px";
	popupbox.style.display = "block";
}

var popupbox_height = 0;
function PopupBoxShow(boxmode, id){
	$(popupbox).stop();
	popupbox_content.innerHTML = "Loading...";
	popupbox.style.height = "";
	popupbox.style.width = "450px";
	popupbox.style.display = "block";
	popupbox_height = 147;
	
	if (boxmode == "news_appetizer"){
		$.ajax({async: false,
			type: "GET", url: "index_clean.php?show=popupbox&choice=loadnewsappetizer&news_id=" + id,
			complete: function(data){
				popupbox_content.innerHTML = data.responseText;
			}
		});
	}else if(boxmode == "event"){
		$.ajax({async: false,
			type: "GET", url: "index_clean.php?show=popupbox&choice=loadevent&event_id=" + id,
			complete: function(data){
				popupbox_content.innerHTML = data.responseText;
			}
		});
	}else if(boxmode == "calendar_day"){
		$.ajax({async: false,
			type: "GET", url: "index_clean.php?show=popupbox&choice=loadcalendarday&unixt=" + id,
			complete: function(data){
				popupbox_content.innerHTML = data.responseText;
			}
		});
	}
	
	$(popupbox).fadeTo(250, 1);
}

function PopupBoxHide(){
	$(popupbox).stop();
	$(popupbox).fadeTo(250, 0, function(){
		popupbox_content.innerHTML = "";
		popupbox.style.width = "1px";
		popupbox.style.height = "1px";
		popupbox.style.display = "none";
	});
}

function unixt(date_ob){
	return Math.floor(date_ob.getTime() / 1000);
}

var subclicked = false;
var hiddeneles = Array();

function showSubMenu(id){
	hiddeneles = Array();
	
	embed_eles = document.getElementsByTagName("object");
	for(i = 0; i < embed_eles.length; i++){
		embed_ele = embed_eles[i];
		embed_ele.style.display = "none";
		hiddeneles[i] = embed_ele;
	}
	
	document.getElementById("divmenu_" + id).style.display = "block";
}

function hideSubMenu(id){
	document.getElementById("divmenu_" + id).style.display = "none";
	
	for(i = 0; i < hiddeneles.length; i++){
		ele = hiddeneles[i];
		ele.style.display = "block";
	}
}

$(document).ready(function(){
	$("#popupbox").fadeTo(0, 0);
	PopupBoxHide();
	
	$(".hovermenu > div").fadeTo(0, 0);
	$(".menuitem").fadeTo(0, 0);
	
	$(".menu").hover(function(){
		this.style.backgroundImage = "url('images/menu_bg_active.jpg')";
		var tha_div = $(this).find("div")[1];
		
		if (tha_div){
			$(tha_div).stop();
			tha_div.style.visibility = "visible";
			$(tha_div).fadeTo(250, 1);
		}
	}, function(){
		this.style.backgroundImage = "url('images/menu_bg.jpg')";
		var tha_div = $(this).find("div")[1];
		
		if (tha_div){
			$(tha_div).stop();
			$(tha_div).fadeTo(250, 0, function(){
				tha_div.style.visibility = "hidden";
			});
		}
	});
	
	$(".tdmenuitem").hover(function(){
		var tha_div = $(this).find(".menuitem")[0];
		
		if (tha_div){
			$(tha_div).stop();
			tha_div.style.visibility = "visible";
			$(tha_div).fadeTo(250, 1);
		}
	}, function(){
		var tha_div = $(this).find(".menuitem")[0];
		
		if (tha_div){
			$(tha_div).stop();
			$(tha_div).fadeTo(250, 0, function(){
				tha_div.style.visibility = "hidden";
			});
		}
	});
	
	$(".menu > .hovermenu > div > table td").hover(function(){
		this.style.backgroundColor = '#ffffff';
	}, function(){
		this.style.backgroundColor = '';
	});
	
	$(".menu > .hovermenu > div > table td").mousedown(function(){
		if (!subclicked){
			subclicked = true;
			location.href = this.getElementsByTagName("a")[0].href;
		}
	});
	
	$(".menu > .hovermenu a").mousedown(function(){
		subclicked = true;
	});
});
