var tempImg = new Image();
var browser;
var last = 6;

function light(image)
{
	image = decodeURIComponent(image);
	//var splitName = image.split('_m');
	//image = splitName[0] + splitName[1];
	tempImg.src = image;

  	loadCheck();
}

function loadCheck()
{  
	if(tempImg.height == 0)
	{
		var time = setTimeout ("loadCheck();", 100);
	}
	else
	{
		clearTimeout(time);
		createLight();
	}
}

function createLight()
{
	var height = tempImg.height;
	var width = tempImg.width;
	
	var winHeight = window.innerHeight;
	if(!winHeight) winHeight = document.documentElement.clientHeight;
  
	var winWidth = window.innerWidth;
	if(!winWidth) winWidth = document.documentElement.clientWidth;
 
 	if (document.getElementById('menu')) 
		var backHeight = document.getElementById('header').offsetHeight + 415 + document.getElementById('menu').offsetHeight + document.getElementById('bottom').offsetHeight;
	else
		var backHeight = document.getElementById('header').offsetHeight + 130 + document.getElementById('center').offsetHeight + document.getElementById('bottom').offsetHeight;
	/*var backHeight = document.height;
	if(!backHeight || backHeight < 15) backHeight = winHeight;*/

	var top = (winHeight - height) / 2;
	var left = (winWidth - width) / 2;

	if(browser == "other")
	{
		top += window.pageYOffset;
	}
	else
	{
		top += document.documentElement.scrollTop;
	}

	var leftBack = 0;
	var newdiv = document.createElement('img');
	var background = document.createElement('div');

	newdiv.setAttribute("id", "photoBig");
	if(document.all && !window.opera && window.XMLHttpRequest && !document.documentMode || document.documentMode == 7)
		newdiv.setAttribute("onclick", function() { lightClose(); });
	else
		newdiv.setAttribute("onclick", "lightClose();");
  
	if(top < 0)
		top = 0;

	if (width > winWidth)
	{
		var imgWidth = winWidth - 200;
		newdiv.setAttribute("width", imgWidth);
		left = 100;
	}
	
	newdiv.style.position = "absolute";
	newdiv.style.left = left + "px";
	newdiv.style.top = top + "px";
	//newdiv.style.height = height + "px";
	//newdiv.style.width = width + "px";
	//newdiv.style.backgroundImage = "url("+ tempImg.src +")";
	newdiv.style.zIndex = "4";
	newdiv.setAttribute("src", tempImg.src);
	newdiv.setAttribute("alt", tempImg.src);
     
	background.setAttribute("id", "background");
	background.style.position = "absolute";
	background.style.backgroundColor = "#000000";
	background.style.height = backHeight + "px";
	background.style.width = winWidth + "px";
	background.style.left = leftBack + "px";
	background.style.top = "0px";
	background.style.opacity = "0.75";
	background.style.filter = "alpha(opacity=75)";
	background.style.zIndex = "3";
	
	document.body.appendChild(background);
	document.body.appendChild(newdiv);	
}

function lightClose(){  
	var remPhoto = document.getElementById('photoBig');
	var remBackground = document.getElementById('background');
	
	document.body.removeChild(remPhoto);
	document.body.removeChild(remBackground);
}

function browserCheck ()
{
	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent))
	{
		var ieversion=new Number(RegExp.$1);
		if (ieversion>=8)
			browser = "IE8";
		else if (ieversion>=7)
		{
			browser = "IE7";
			if (location.pathname != "/galerie.php")
				document.getElementById('style').href = "./css/styleIE7.css";
		}
	}
	else
		browser = "other";
	
		
	switch (location.pathname)
	{
		case "/":
		case "/index.php":
			document.getElementById('homeBack').style.display = "block";
			document.getElementById('home').src = "./design/menu-home_a.png";
			if (browser == "IE7")
				document.getElementById('specific').href = "./css/indexIE7.css";
			break;
		case "/jidelnilistek.php":
			document.getElementById('jidelnicekBack').style.display = "block";
			document.getElementById('jidelnicek').src = "./design/menu-jidelnilistek_a.png";
			break;
		case "/napojovylistek.php":
			document.getElementById('napojeBack').style.display = "block";
			document.getElementById('napoje').src = "./design/menu-napojovylistek_a.png";
			break;
	}
}

function showOteviracidoba ()
{
	$('#oteviracidoba').fadeOut('slow','');
	$('#oteviracidobaText').fadeIn('slow','');
	//document.getElementById('oteviracidoba').style.display = "none";
	//document.getElementById('oteviracidobaText').style.display = "block";
	setTimeout('hideOteviracidoba();', 5000);
}

function hideOteviracidoba ()
{
	$('#oteviracidoba').fadeIn('slow','');
	$('#oteviracidobaText').fadeOut('slow','');
	//document.getElementById('oteviracidoba').style.display = "block";
	//document.getElementById('oteviracidobaText').style.display = "none";
}

function showMenuAll ()
{
	$('#menuTyden').fadeOut('fast', function () {
		$('#menuAll').slideDown('slow', '');
		//document.getElementById('menuTyden').style.display = "none";
		//document.getElementById('menuAll').style.display = "block";
	});	
}

function hideMenuAll ()
{
	$('#menuAll').slideUp('slow', function () {
		$('#menuTyden').fadeIn('slow','');
		//document.getElementById('menuTyden').style.display = "block";
		//document.getElementById('menuAll').style.display = "none";	
	});
}

function email ()
{
	var mail = prompt ('Prosím zadejte svůj e-mail:');
	var vyraz = /^.+@.+\..{2,4}$/;

	if (mail == null)
	{
		return;
	}
	else if(!vyraz.test(mail))
	{
		alert('Špatně zadaná e-mailová adresa!');
		email ();
	}
	else
	{
		document.getElementById('emailField').value = mail;
		document.getElementById('emailForm').submit();
	}
}

function center()
{
	var winHeight = window.innerHeight;

	if(!winHeight)
		winHeight = document.documentElement.clientHeight;

	var top = (winHeight - 600) / 2;

	document.getElementById('center').style.top = top + "px";
}

function nextSet()
{					
	for(var a = 0; a < 6; a++)
	{			
		document.getElementById('img' + a).src = img[a + last];
		if(!img[a+last])
			document.getElementById('img' + a).style.display = 'none';
		else
			document.getElementById('img' + a).style.display = 'inline';
	}
	last += 6;

	if(last >= img.length)
		document.getElementById('nextSet').style.display = 'none';
	document.getElementById('prevSet').style.display = 'inline';
}

function prevSet()
{
	last -= 12;
	if(last <= 0)
		document.getElementById('prevSet').style.display='none';		
	for(var a = 0; a < 6; a++)
	{			
		document.getElementById('img' +a).src = img[a+last];
		if(!img[a+last])
			document.getElementById('img' +a).style.display='none';
		else
			document.getElementById('img' +a).style.display='inline';
	}
	last += 6;
	document.getElementById('nextSet').style.display='inline';
}
