nadpisyC=new Array("Kdo jsme","Služby","Prodej","Ubytování","Aktuality","Kontakt","Osoby a obsazení","Plemenný hřebec")
nadpisyD=new Array("Wer wir sind","Service","Verkauf","Unterkunft","Aktuelles","Kontakt","Personen und Besetzung")
odkazy=new Array("kdojsme.html","sluzby.html","prodej.html","ubytovani.html","aktuality.html","kontakt.html","osoby.html","hrebec.html")

scrll=false
leftArr=new Image
leftArrA=new Image
rightArr=new Image
rightArrA=new Image
loadImg=new Image

leftArr.src="obrazky/menu_left.png"
leftArrA.src="obrazky/menu_leftA.png"
rightArr.src="obrazky/menu_right.png"
rightArrA.src="obrazky/menu_rightA.png"
loadImg.src="obrazky/loading.gif"

var bodyWidth;
var bodyHeight;

var nadpisy
var odkazy

if(document.cookie.indexOf("german")>-1){
	if(document.styleSheets[0].cssRules){
		document.styleSheets[0].insertRule("#cz {display:none}",0);		
	}
	else if(document.styleSheets[0].rules){
		document.styleSheets[0].addRule("#cz","display:none",0);		
	}
}
else{
	if(document.styleSheets[0].cssRules){
		document.styleSheets[0].insertRule("#de {display:none}",1);
	}
	else if(document.styleSheets[0].rules){		
		document.styleSheets[0].addRule("#de","display:none",1);
	}
}

function setCookie(cookieName,cookieValue,nDays) {
	var today = new Date();
	var expire = new Date();
	if (nDays==null || nDays==0) nDays=1;
	expire.setTime(today.getTime() + 3600000*24*nDays);
	document.cookie = cookieName+"="+escape(cookieValue)+";expires="+expire.toGMTString();
}


function czech(){
	setCookie("language","czech");
	writeMenu()
}

function german(){
	setCookie("language","german");	
	writeMenu()
}

function resizePage(){
	cont=document.getElementById("content")
	w = document.body.clientWidth>1280 ? 1280 : document.body.clientWidth
	w*=0.82
	
	cont.style.width=w
	
	mainD=document.getElementById("main")
	h=document.body.clientHeight
	
	mainD.style.height=h-mainD.offsetTop-9;
	
	if(navigator.appName.indexOf("Opera")>-1) document.body.onscroll=function(){ document.body.scrollTop=0 }
	
	if(navigator.appName.indexOf("Internet Explorer")>-1) c=96
	else if(navigator.userAgent.toLowerCase().indexOf("chrome")>-1) c=142
	else if(navigator.appName.indexOf("Opera")>-1) c=144
	else c=143
	
	iFr=document.getElementById("ifr")	
	iFr.style.height=h-c
	
	nabidka=document.getElementById("menuBar")
	nabidka.style.width=w
		
	if(nabidka.scrollWidth<=Math.ceil(w)){
		document.getElementById("sbL").style.visibility="hidden"
		document.getElementById("sbR").style.visibility="hidden"
	}
	else{
		document.getElementById("sbL").style.visibility="visible"
		document.getElementById("sbR").style.visibility="visible"
	}
	
	pUrl=navigator.userAgent.toLowerCase().indexOf("chrome")>-1 ? document.location.href : window.location.href;	
	if(pUrl.indexOf("?s=")>-1){
		nabidka.scrollLeft=parseInt(pUrl.split("?s=")[1]);		
	}
		
	if(document.getElementById("langSel")!=null){
		lang=document.getElementById("langSel");
		l=596+(document.body.clientWidth-1280)/2
		t=120
		
		lang.style.left=l
		lang.style.top=t	
	}
		
}


function writeMenu(){
	bodyWidth=document.body.clientWidth
	bodyHeight=document.body.clientHeight

	if(document.cookie.indexOf("german")>-1){
		nadpisy=nadpisyD
	}
	else{
		nadpisy=nadpisyC
	}

	nabidka=document.getElementById("menuBar")
	
	nabidka.innerHTML=""
	nabidka.innerHTML+='<a href="."><img src="obrazky/itemH.png" align="absmiddle">'
	for(i=0;i<nadpisy.length;i++){
		nabidka.innerHTML+='<span class="menuItem"><a href="'+odkazy[i]+'" onMousedown="this.setAttribute(\'href\',this.getAttribute(\'href\')+\'?s=\'+document.getElementById(\'menuBar\').scrollLeft); window.location.href=this.getAttribute(\'href\');return false">'+nadpisy[i]+'</a></span><img src="obrazky/itemN.png" align="absmiddle">'
	}	
	
	prepareGalleries()
	resizePage()
}

function hide(obj){
obj.style.display="none"
i=document.getElementById("origImg");
i.width=40;
i.height=40;

s=document.getElementById("scrollSpace");
s.style.width="";
s.style.height="";
maximized=false;
}

function prepareGalleries(){
	if(navigator.appName.indexOf("Internet Explorer")==-1){
		pic=document.getElementsByTagName("a");	
		for(i=0;i<pic.length;i++){
			hr=pic[i].getAttribute("href");
			if(hr!=null)
				hr=hr.toLowerCase();
				if(hr!=null){
					if(hr.indexOf("javascript:")==-1 && hr.indexOf(".jpg")>-1 || hr.indexOf(".png")>-1){
						pic[i].setAttribute('href','javascript:showImage("'+hr+'")');
					}
				}
		}
	}
}

function showImage(file){
	
	myImg=new Image();
	myImg.src=file;
	
	resized=false
	
	if(document.getElementById("fotoFrame")==null)
			document.body.innerHTML+='<div id="fotoBackground"><div id="fotoFrame"><div id="fotoBar" align=right><a href="javascript:hide(document.getElementById(\'fotoBackground\'))" style="text-decoration:none;font-size:10pt;color:#000000;font-family:Tahoma;font-weight:bold">X</a></div><div id="scrollSpace"><img id="origImg" src=""></div></div></div>';
	
	l=document.getElementById("origImg")
	l.src=loadImg.src;
	f=document.getElementById("fotoFrame");
	posLeft=(bodyWidth-f.offsetWidth)/2
	posTop=(bodyHeight-f.offsetHeight)/2
	f.style.left=posLeft;
	f.style.top=posTop;
		
	document.getElementById("fotoBackground").style.display="block";
	
	myImg.onload=function(){
		picWidth=myImg.width;
		picHeight=myImg.height;
		
		bodyWidth=document.body.clientWidth;
		bodyHeight=document.body.clientHeight;
		
		if(picWidth>bodyWidth || picHeight>bodyHeight){
			resized=true
			aspectRatio=picWidth/picHeight;
			if(aspectRatio>bodyWidth/bodyHeight){
				picWidth=bodyWidth-2;
				picHeight=Math.ceil(picWidth/aspectRatio);
			}
			else{
				picHeight=bodyHeight-18;
				picWidth=Math.ceil(picHeight*aspectRatio);
			}
		}
		
		posLeft=(bodyWidth-picWidth-2)/2
		posTop=(bodyHeight-picHeight-18)/2
		
		
		i=document.getElementById("origImg");
		i.src=myImg.src;
		i.width=picWidth;
		i.height=picHeight;
		i.style.cursor="auto";
		i.onclick="void()";
		if(resized){
			i.style.cursor="url('obrazky/magnify.cur'), move";
			maximized=false;
			i.onclick=function(){
				bodyWidth=document.body.clientWidth;
				bodyHeight=document.body.clientHeight;
				if(!maximized){
					s=document.getElementById("scrollSpace");
					
					frameWidth=myImg.width>bodyWidth-2 ? bodyWidth-2 : myImg.width+17;
					frameHeight=myImg.height>bodyHeight-18 ? bodyHeight-18 : myImg.height+17;
					
					frameWidth=frameWidth>bodyWidth-2 ? bodyWidth-2 : frameWidth;
					frameHeight=frameHeight>bodyHeight-18 ? bodyHeight-18: frameHeight;
					
					i=document.getElementById("origImg");
					i.width=myImg.width;
					i.height=myImg.height;
					i.style.cursor="url('obrazky/minimize.cur'), move";
					
					s.style.width=frameWidth;
					s.style.height=frameHeight;
					s.style.overflow="auto";
					
					f=document.getElementById("fotoFrame");
					posLeft=(bodyWidth-f.offsetWidth)/2
					posTop=(bodyHeight-f.offsetHeight)/2
					f.style.left=posLeft;
					f.style.top=posTop;
					
					
					maximized=true;
				}
				else{
					i=document.getElementById("origImg");
					i.width=picWidth;
					i.height=picHeight;
					i.style.cursor="url('obrazky/magnify.cur'), move";
					f=document.getElementById("fotoFrame");
					posLeft=(bodyWidth-picWidth-2)/2
					posTop=(bodyHeight-picHeight-18)/2
					f.style.left=posLeft;
					f.style.top=posTop;
					
					s=document.getElementById("scrollSpace");
					s.style.width="";
					s.style.height="";
					maximized=false;
				}
			}
		}		
		
		f=document.getElementById("fotoFrame");
		f.style.left=posLeft;
		f.style.top=posTop;
		
	}
}

function mScroll(v,c){
	if(scrll){
		document.getElementById("menuBar").scrollLeft+=v
		c++
		if(c%2==0 && c<16) v=v>0?v+1:v-1
		setTimeout("mScroll("+v+","+c+")",25)		
	}
}

function menuScroll(i,v){
	if(v==-1){
		scrll=false
		i.src=leftArr.src
	}
	else if(v==1){
		scrll=false
		i.src=rightArr.src
	}
	else if(v==-2 && document.getElementById("menuBar").scrollLeft>0){	
		scrll=true
		i.src=leftArrA.src
		mScroll(v+1,0)		
	}
	else if(v==2 && document.getElementById("menuBar").scrollLeft<document.getElementById("menuBar").scrollWidth-document.getElementById("menuBar").offsetWidth){
		scrll=true
		i.src=rightArrA.src
		mScroll(v-1,0)
	}	
}

function thumb(pictures,styles){
	if(pictures.indexOf(",")>-1){
		picture=pictures.split(",")
		output=""
		for(i=0;i<picture.length;i++){output+='<a href="obrazky/'+picture[i]+'"><img src="nahledy/'+picture[i]+'" style="'+styles+'"></a>'}
	}
	else{
		picture=pictures
		output='<a href="obrazky/'+picture+'"><img src="nahledy/'+picture+'" style="'+styles+'"></a>'
	}
	document.write(output)
}

galleries=0
galPictures=new Array
galPicturesLarge=new Array

function gallery(pictures,gwidth,styles){
	prevButton='<img src="obrazky/prev.png" align=absmiddle border=0>'
	nextButton='<img src="obrazky/next.png" align=absmiddle border=0>'
	galleries++
	galID=galleries
	//galPictures[galID]=pictures.split(",")
	galPictures[galID]=new Array
	galPicturesLarge[galID]=new Array
	gpic=pictures.split(",")
	for(i=0;i<gpic.length;i++){
		galPictures[galID][i]=new Image
		galPictures[galID][i].src="nahledy/"+gpic[i]
		galPicturesLarge[galID][i]="obrazky/"+gpic[i]
	}
	output='<span id="gal'+galID+'" style="'+styles+'"><table style="width:'+(gwidth+10)+'px"><tr><td align=center><a href="'+galPicturesLarge[galID][0]+'"><img src="'+galPictures[galID][0].src+'"></a></td></tr><tr align=center><td><a class="arrow">'+prevButton+'</a> <span class="imgPos">'+1+' / '+galPictures[galID].length+'</span> <a class="arrow" href="javascript:nextPic('+galID+',0)">'+nextButton+'</a></td></tr></table></span>'
	document.write(output)
}

function nextPic(galID,current){
	if(document.getElementById("gal"+galID).firstChild.outerHTML!=undefined){
		gwidth=document.getElementById("gal"+galID).firstChild.outerHTML.split('"')[1]
	}
	else{
		gwidth=document.getElementById("gal"+galID).firstChild.getAttribute("style")
	}
	
	if(current+1==galPictures[galID].length-1){
		output='<table style="'+gwidth+'"><tr><td align=center><a href="'+galPicturesLarge[galID][current+1]+'"><img src="'+galPictures[galID][current+1].src+'"></a></td></tr><tr align=center><td><a class="arrow" href="javascript:prevPic('+galID+','+(current+1)+')">'+prevButton+'</a> <span class="imgPos">'+(current+2)+' / '+galPictures[galID].length+'</span> <a class="arrow">'+nextButton+'</a></td></tr></table>'
	}
	else{
		output='<table style="'+gwidth+'"><tr><td align=center><a href="'+galPicturesLarge[galID][current+1]+'"><img src="'+galPictures[galID][current+1].src+'"></a></td></tr><tr align=center><td><a class="arrow" href="javascript:prevPic('+galID+','+(current+1)+')">'+prevButton+'</a> <span class="imgPos">'+(current+2)+' / '+galPictures[galID].length+'</span> <a class="arrow" href="javascript:nextPic('+galID+','+(current+1)+')">'+nextButton+'</a></td></tr></table>'
	}
	document.getElementById("gal"+galID).innerHTML=output
	prepareGalleries();
}

function prevPic(galID,current){
	if(document.getElementById("gal"+galID).firstChild.outerHTML!=undefined){
		gwidth=document.getElementById("gal"+galID).firstChild.outerHTML.split('"')[1]
	}
	else{
		gwidth=document.getElementById("gal"+galID).firstChild.getAttribute("style")
	}
	
	if(current-1==0){
		output='<table style="'+gwidth+'"><tr><td align=center><a href="'+galPicturesLarge[galID][0]+'"><img src="'+galPictures[galID][0].src+'"></a></td></tr><tr align=center><td><a class="arrow">'+prevButton+'</a> <span class="imgPos">'+(current)+' / '+galPictures[galID].length+'</span> <a class="arrow" href="javascript:nextPic('+galID+',0)">'+nextButton+'</a></td></tr></table>'
	}
	else{
		output='<table style="'+gwidth+'"><tr><td align=center><a href="'+galPicturesLarge[galID][current-1]+'"><img src="'+galPictures[galID][current-1].src+'"></a></td></tr><tr align=center><td><a class="arrow" href="javascript:prevPic('+galID+','+(current-1)+')">'+prevButton+'</a> <span class="imgPos">'+(current)+' / '+galPictures[galID].length+'</span> <a class="arrow" href="javascript:nextPic('+galID+','+(current-1)+')">'+nextButton+'</a></td></tr></table>'
	}
	document.getElementById("gal"+galID).innerHTML=output
	prepareGalleries();
}


