var IE=navigator.appName=="Microsoft Internet Explorer"?true:false;
var menu=0;
var close_menu=-1;
function rozbal_menu_simple(idmenu)
{
	if (menu==0)
	{
		close_menu=idmenu;
		menu=1;
		document.getElementById(idmenu).style.display='block';
		document.getElementById(idmenu+"2").style.backgroundImage='url("/share/img/nahoru2'+postfix+'.gif")';
		showOverlay();
	}
	else if(menu>0)
	{
		document.getElementById(idmenu+"2").style.backgroundImage='url("/share/img/dolu2'+postfix+'.gif")';
		document.getElementById(idmenu).style.display='none';
		if(document.getElementById('overlay2').style.display=='block'){
			document.getElementById('overlay2').style.display='none';
		}
		document.getElementById('overlay').style.display='none';
		menu=0;
	}
	else
	{
		if(document.getElementById('overlay2').style.display=='block'){
			document.getElementById('overlay2').style.display='none';
		}
		document.getElementById('overlay').style.display='none';
		menu=0;
	}
	if(idcenik)
	{
		document.getElementById("cenik"+idcenik).style.display='none';
		idcenik=0;
		if(highlightedHotel>0)
			highlightHotelTimeout=setTimeout("highlighFadeout("+highlightedHotel+");highlightedHotel=0;", 2000);
	}
	if(bShowFotoHotel)
	{
		document.getElementById('fotoBox').style.display='none'
		bShowFotoHotel=0;
		if(highlightedHotel>0)
			highlightHotelTimeout=setTimeout("highlighFadeout("+highlightedHotel+");highlightedHotel=0;", 2000);
	}
}
function showOverlay(opacity)
{
	if(opacity)
	{
		document.getElementById('overlay').style.opacity=0.4;
		document.getElementById('overlay').style.filter='alpha(opacity=40)';
		document.getElementById('overlay2').style.opacity=0.4;
		document.getElementById('overlay2').style.filter='alpha(opacity=40)';
	}
	else
	{
		document.getElementById('overlay').style.opacity=0;
		document.getElementById('overlay').style.filter='alpha(opacity=0)';
		document.getElementById('overlay2').style.opacity=0;
		document.getElementById('overlay2').style.filter='alpha(opacity=0)';
	}

	document.getElementById('overlay').style.display='block';
	var arrayPageSize=getPageSize();
	document.getElementById('overlay').style.width=arrayPageSize[0] + 'px';
	document.getElementById('overlay').style.height=Math.min(arrayPageSize[1],2500) + 'px';
	if(arrayPageSize[1]>2500)
	{
		document.getElementById('overlay2').style.display='block';
		document.getElementById('overlay2').style.height=(arrayPageSize[1]-2500) + 'px';
		document.getElementById('overlay2').style.top='2500px';
		document.getElementById('overlay2').style.width=arrayPageSize[0] + 'px';
	}
//	document.getElementById('overlay').style.height=arrayPageSize[1] + 'px';
}
function showCustomOverlay(opacity)
{
	if(opacity)
	{
		document.getElementById('Customoverlay').style.opacity=0.4;
		document.getElementById('Customoverlay').style.filter='alpha(opacity=40)';
		document.getElementById('Customoverlay2').style.opacity=0.4;
		document.getElementById('Customoverlay2').style.filter='alpha(opacity=40)';
	}
	else
	{
		document.getElementById('Customoverlay').style.opacity=0;
		document.getElementById('Customoverlay').style.filter='alpha(opacity=0)';
		document.getElementById('Customoverlay2').style.opacity=0;
		document.getElementById('Customoverlay2').style.filter='alpha(opacity=0)';
	}

	document.getElementById('Customoverlay').style.display='block';
	var arrayPageSize=getPageSize();
	document.getElementById('Customoverlay').style.width=arrayPageSize[0] + 'px';
	document.getElementById('Customoverlay').style.height=Math.min(arrayPageSize[1],2500) + 'px';
	if(arrayPageSize[1]>2500)
	{
		document.getElementById('Customoverlay2').style.display='block';
		document.getElementById('Customoverlay2').style.height=(arrayPageSize[1]-2500) + 'px';
		document.getElementById('Customoverlay2').style.top='2500px';
		document.getElementById('Customoverlay2').style.width=arrayPageSize[0] + 'px';
	}
}

function hideCustomOverlay()
{
	document.getElementById('Customoverlay').style.display='none';
	document.getElementById('Customoverlay2').style.display='none';
}
function winH() {
	if (window.innerHeight) return window.innerHeight;
	else if (document.documentElement && document.documentElement.clientHeight)
		return document.documentElement.clientHeight;
	else if (document.body && document.body.clientHeight)
		return document.body.clientHeight;
	else return null;
}
function getPageSize() {

     var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth;
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = xScroll;
	} else {
		pageWidth = windowWidth;
	}

	return [pageWidth,pageHeight];
}
function menu_submit(id,idmenu,inner)
{
	if (idmenu == null){
		idmenu = "hidden_misto";
		idmenu2="JS_option";
	}
	else
	{
		idmenu2="id_"+idmenu;
	}
	document.getElementById(idmenu).value=id;
	try
	{
		document.getElementById(idmenu2).style.display='none';
		document.getElementById(idmenu2+"2").style.backgroundImage='url("/share/img/dolu2'+postfix+'.gif")';
		if(inner!=null)
		{
			document.getElementById(idmenu2+"2").innerHTML=inner;
		}
		document.getElementById('overlay').style.display='none';
		menu=0;
	}
	catch(err){}
	form_submit();
}
function getScrollY() {
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	return scrOfY;
}
function showFotoHotel(slozka,foto_string,n,id)
{
	highlightHotel(id);
	bHotelOut=false;
	var fotoBox=document.getElementById('fotoBox');
	var page=n;
	if(foto_string.charAt(0)%2==1){
		page=n+1;
		if(n==foto_string.length){
			page=1;
		}
	}
	var i=foto_string.charAt(page-1);
	var x=0,y=0,width=0;
	switch(i){
		case "1":
			x=200;
			y=140;
			width=200;
			break;
		case "2":
			x=500;
			y=350;
			width=500;
			break;
		case "3":
			y=200;
			x=140;
			width=200;
			break;
		case "4":
			y=500;
			x=350;
			width=500;
			break;
	} // switch
	switch(mutace){
		case "":
			var z="z";
			var foto="foto";
			var zavrit="zavøít";
			break;
		case "gr":
			var z="aus";
			var foto="foto";
			var zavrit="schließen";
			break;
		case "gb":
			var z="out of";
			var foto="photo";
			var zavrit="close";
			break;
		case "pl":
			var z="z";
			var foto="zdjêcie";
			var zavrit="zamkn¹æ";
			break;
		case "it":
			var z="/";
			var foto="foto";
			var zavrit="chiudere";
			break;
	} // switch
	fotoBox.style.display="block";
	pagesize=getPageSize();
	fotoBox.style.top=Math.round(winH()/2+getScrollY()-y/2)+"px";
	fotoBox.style.top=getCenterAtPos(y+40,document.getElementById("hotel"+id).offsetTop+50)+"px";
	fotoBox.style.left=Math.round((pagesize[0]/2)-(x/2)-5)+"px";
//	fotoBox.style.left=Math.round((pagesize[0]/2)-(width/2)-5)+"px";
//	fotoBox.style.width=(x)+"px";
	if(IE && document.compatMode!="CSS1Compat"){
		fotoBox.style.width=(x+2)+"px";
	}
	else{
		fotoBox.style.width=(x)+"px";
	}
	/*if(IE){
		if(document.compatMode!="CSS1Compat"){
			fotoBox.style.width=(x+20)+"px";
		}
	}*/
	if(y==200){
		fotoBox.style.height=(y+45)+"px";
	}
	else{
		fotoBox.style.height=(y+30)+"px";
	}
	var out="";
	/*out="<div style=\"position:absolute;top:-1px;left:"+(x+4)+"px\"><a href=\"javascript:rozbal_menu_simple(-1)\"><img border=0 src=/share/img/x2.gif></a></div>"+foto+" "+n+" "+z+" "+foto_string.length+"<br><div class=relative>";*/
	out="<div class=relative>";
	if(n>1){
		out+="<a style=\"text-align:left;left:0px;width:"+Math.round(x/2)+"px;height:"+(y+30)+"px;line-height:"+(y+30)+"px;\" class=\"hotelfoto_next\" href=\"javascript:showFotoHotel('"+slozka+"','"+foto_string+"',"+(n-1)+","+id+")\"><img class=schovka style=\"top:"+Math.round(y/4)+"px;\" border=0 src="+linkS+"/share/img/left2.gif><img style=\"position:relative;top:"+(y+8)+"px;\" border=0 src="+linkS+"/share/img/left.gif></a>";
	}
	if(n<foto_string.length){
		out+="<a style=\"text-align:right;left:"+Math.round(x/2)+"px;width:"+Math.round(x/2)+"px;height:"+(y+30)+"px;line-height:"+(y+30)+"px;\" class=\"hotelfoto_next\" href=\"javascript:showFotoHotel('"+slozka+"','"+foto_string+"',"+(n+1)+","+id+")\"><img class=schovka style=\"top:"+Math.round(y/4)+"px;left:"+Math.round(x/2-40)+"px\" border=0 src="+linkS+"/share/img/right2.gif><img style=\"position:relative;top:"+(y+8)+"px;\" border=0 src="+linkS+"/share/img/right.gif></a>";
	}
	out+="<img border=0 width="+x+" height="+y+" ";
	if(x<350)
		out+="src="+base+slozka+"/x"+page+"a.jpg>";
	else
		out+="src="+base+slozka+"/x"+page+".jpg>";
	out+="<br>";
/*	if(n>1){
		out+="<a href=\"javascript:showFotoHotel('"+slozka+"','"+foto_string+"',"+(n-1)+","+id+")\">&lt;&lt;</a>";
	}*/
	if(y==200){
		out+="<table width=100% height=30 style=\"position:relative;color:white\"><tr><td align=center><font color=white>"+n+"/"+foto_string.length+"</font></td></tr></table><br>";
		out+="<a href=\"javascript:rozbal_menu_simple(-1)\" class=\"foto_zavrit\">"+zavrit+"</a>";
	}
	else{
		out+="<table width=100% height=30 style=\"position:relative;color:white\"><tr><td width=50% align=center><font color=white>&nbsp;&nbsp;"+n+"/"+foto_string.length+"</font></td><td width=50%>&nbsp;</td></tr></table>";
		out+="<a href=\"javascript:rozbal_menu_simple(-1)\" class=\"foto_zavrit\">"+zavrit+"</a>";
	}
	/*if(n<foto_string.length){
		out+="<a href=\"javascript:showFotoHotel('"+slozka+"','"+foto_string+"',"+(n+1)+","+id+")\">&gt;&gt;</a>";
	}*/
	fotoBox.innerHTML=out;
	menu=-1;
	bShowFotoHotel=1;
	showOverlay(true);
	preloadi=parseFloat(page)%foto_string.length+1;
	if(n<foto_string.length){
		var preload=new Image(100,25);
		if(foto_string.charAt(preloadi-1)%2==1){
			preload.src=base+slozka+"/x"+preloadi+"a.jpg"
		}
		else{
			preload.src=base+slozka+"/x"+preloadi+".jpg";
		}
	}
}
function getCenterAtPos(offHeight,pos){
	var height=Math.round(offHeight/2);
	var off=pos;
	var scroll=getScrollY();
	var cons=20;
	var top=0;
	if(scroll+winH()<off+height+cons){
		top=scroll+winH()-cons-(height*2);
	}
	if(off-height-cons<scroll || (top!=0 && top-cons<scroll)){
		top=scroll+cons;
	}
	else if (top==0) {
		top=off-height;
	}
	return top;
}
var highlightedHotel=0;
var highlightHotelTimeout;
var clearHotelTimeout;
var bHotelOut=false;
function highlightHotel(id){
	if(highlightedHotel>0){
		document.getElementById("hotel"+highlightedHotel).className="hotellist_highlight0";
	}
	if(highlightHotelTimeout){
		clearTimeout(highlightHotelTimeout);
	}
	document.getElementById("hotel"+id).className="hotellist_highlight";
	highlightedHotel=id;
}
function hotelOver(id){
	if(highlightHotelTimeout && highlightedHotel==id){
		clearTimeout(highlightHotelTimeout);
		bHotelOut=true;
	}
	if (highlightedHotel==id) {
		clearTimeout(clearHotelTimeout);
	}
}
function hotelOut(id){
	if(highlightedHotel==id && bHotelOut){
		clearHotelTimeout=setTimeout("highlighFadeout("+id+");highlightedHotel=0;",10);
		bHotelOut=false;
	}
}
function escClose (event) {
	if (!event) event = window.event; // fix IE
	//alert("esc");
	if (event.keyCode == 27 && menu==-1) {
		rozbal_menu_simple(-1);
	}
}
document.onkeyup=escClose;
var n=0;
var highlighFadeoutInterval;
function highlighFadeout(id){
	n=5;
	highlighFadeoutInterval=window.setInterval("highlighFadeoutInt("+id+")", 100);
}
function highlighFadeoutInt(id){
	document.getElementById("hotel"+id).className="hotellist_highlight"+n;
	n--;
	if(n<0)
		window.clearInterval(highlighFadeoutInterval);
}
