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.visibility = "visible";
}

var popupbox_height = 0;
function PopupBoxShow(boxmode, id){
	popupbox_content.innerHTML = "Loading...";
	popupbox.style.height = "";
	popupbox.style.width = "450px";
	popupbox_height = 147;
	
	if (boxmode == "news_appetizer"){
		jQuery.ajax({
			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"){
		jQuery.ajax({
			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"){
		jQuery.ajax({
			type: "GET", url: "index_clean.php?show=popupbox&choice=loadcalendarday&unixt=" + id,
			complete: function(data){
				popupbox_content.innerHTML = data.responseText;
			}
		});
	}else if(boxmode == "text"){
		popupbox_content.innerHTML = id;
	}
}

function PopupBoxHide(){
	popupbox.style.visibility = "hidden";
	popupbox.style.top = "1px";
	popupbox.style.left = "1px";
}

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";
	}
}

function mainGoTo(tha_url){
	setTimeout("if (!subclicked){location.href='" + tha_url + "';}", 150);
}

var modal_opts = {
	overlay: 99,
	overlayCss: {backgroundColor: "#000000"},
	containerId: "simplemodal_box",
	onOpen: function(dialog){
		dialog.overlay.fadeIn(400, function(){
			dialog.container.fadeIn(0, function(){
				dialog.data.fadeIn(400, function(){
					
				});
			});
		});
	},
	onClose: function(dialog){
		$("#flowplayer").html("&nbsp;");
		
		dialog.data.fadeOut(400, function(){
			dialog.container.fadeOut(0, function(){
				dialog.overlay.fadeOut(400, function(){
					$.modal.close();
				});
			});
		});
	}
};

function modal(paras){
	modalOpen(paras);
}

function modalOpen(paras){
	tha_style = "";
	
	if (paras["width"]){
		tha_style += "width: " + paras["width"] + ";";
	}
	
	if (paras["height"]){
		tha_style += "height: " + paras["height"] + ";";
	}
	
	if (paras["url"]){
		$.ajax({type: "GET", url: paras["url"], cache: false, async: false,
			complete: function(data){
				paras["content"] = data.responseText;
			}
		});
	}
	
	tha_html = "";
	tha_html += "<div class=\"simplemodal_box\" style=\"" + tha_style + "\">";
	tha_html += "<table class=\"designtable\"><tr>";
	tha_html += "<td><div class=\"simplemodal_header\">" + paras["title"] + "</div></td>";
	tha_html += "<td style=\"text-align: right;\"><a href=\"javascript: modalClose();\">[" + locale_strings["close"] + "]</a></td>";
	tha_html += "</tr></table>";
	tha_html += "<div>" + paras["content"] + "</div></div>";
	
	$.modal(tha_html, modal_opts);
}

function modalClose(){
	$.modal.close();
}

$(document).ready(function(){
	$(".hovermenu div").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";
			});
		}
	});
	
	$(".menu > .hovermenu > div > table td").hover(function(){
		this.style.backgroundColor = '#ffffff';
	}, function(){
		this.style.backgroundColor = '';
	});
	
	$(".menu > .hovermenu > div > table td").mousedown(function(){
		subclicked = true;
		location.href = this.getElementsByTagName("a")[0].href;
	});
	
	$(".menu > .hovermenu a").mousedown(function(){
		subclicked = true;
	});
});
