var newsId = 0;
var is = new browserCheck();
var showPopup = false;
var isStartPage = true;

window.onresize = placeLoginAndSearch;


function hidePopups(){
       
	if (!showPopup)
	{
		document.getElementById('loginPopup').style.visibility = "hidden";
		document.getElementById('searchPopup').style.visibility = "hidden";
	}
}



function browserCheck(){
	this.agent=navigator.userAgent.toLowerCase()
	this.op=window.opera 
	this.moz=(this.agent.indexOf("gecko")>-1 || window.sidebar)
	this.ie=this.agent.indexOf("msie")>-1 && !this.op
	return this
}



function peliInit(delay){


	 if(delay=="yes")
	 {
	  	 getNews(1);
  		 displayProduct();
		 window.setTimeout("show('header')",0); 
		 window.setTimeout("show('picture-main')",0);
		 window.setTimeout("show('news')",1800);
		 window.setTimeout("show('products-main')",3000);
		 window.setTimeout("show('footer')",3300);
		 window.setTimeout("show('popUps')",3300);
 		 window.setTimeout("show('shopIcon')",3300);
		 window.setTimeout("drawMenu()",3300);
	 }
	 
	 else if(delay=="no")
	 {
	 	getNews(0);
		displayProduct();
	 }
	 
	 else{
		isStartPage = false;
	 }

	 //set position of login and search pop up div
	 placeLoginAndSearch();
}


function getNews(delay){	
	document.getElementById("Novinka").innerHTML = news[newsId];
	newsId++;
	if(newsId==news.length) newsId = 0;
	window.setTimeout("getNews()",delay?5000:3000);
}


function show(element) {   
	if(document.getElementById(element).style.visibility == "hidden")
	{	
		document.getElementById(element).style.visibility = "visible";   
	}
 }
 
 
function drawMenu() {
	if (drawMenu.arguments[0]=="yes") return;
	cmDraw ('myMenuID', myMenu, 'hbr', cmTheme, 'Theme');
}




function getImg(){
  	var imgs = new Array();
  	imgs[0] = '<img src="' + url_root + 'imgs/soldiers.jpg" width="780" height="233" alt="" />';
  	imgs[1] = '<img src="' + url_root + 'imgs/lake.jpg" width="780" height="233" alt="" />';
  	imgs[2] = '<img src="' + url_root + 'imgs/firefighter.jpg" width="780" height="233" alt="" />';
  	/*
  	imgs.push('<img src="imgs/soldiers.jpg" width="780" height="233" alt="" />');	
  	imgs.push('<img src="imgs/lake.jpg" width="780" height="233" alt="" />');	
  	imgs.push('<img src="imgs/firefighter.jpg" width="780" height="233" alt="" />');	  	
  	*/
	document.write(imgs[Math.floor(Math.random()*imgs.length)]);	
}




function placeLoginAndSearch(){


	//alert(document.getElementById('loginPopup').style.offsetHeight);


	var rightEdge;
	var width = 200;
	
	rightEdge = Math.round((document.body.offsetWidth + 780)/2)-width;
	document.getElementById('loginPopup').style.left = rightEdge+"px";
	document.getElementById('searchPopup').style.left = rightEdge+"px";


	if(is.moz)
	{
		document.getElementById('loginPopup').style.top = "58px";
		document.getElementById('searchPopup').style.top = "58px";
	}
	else if(is.op){
		document.getElementById('loginPopup').style.top = "58px";
		document.getElementById('searchPopup').style.top = "58px";
	}
	else{
		document.getElementById('loginPopup').style.top = "56px";
		document.getElementById('searchPopup').style.top = "56px";
	}




	/* correct styles for ie*/

    if (is.ie)
    {
		var myLoginStyle = document.createStyleSheet();
		myLoginStyle.addRule("#loginPopup .submit","height: 18px;");	
		if(isStartPage) myLoginStyle.addRule("#loginPopup .submit","background: white;");	

		myLoginStyle.addRule("#searchPopup .submit","height: 18px;");	
		if(isStartPage) myLoginStyle.addRule("#searchPopup .submit","background: white;");	

    }

    if (is.op)
    {
		document.getElementById('login-submit').style.height = "15px";
		document.getElementById('search-submit').style.height = "15px";
	}

}




function keepPopupShown(){
    showPopup = true;
 	setTimeout("showPopup=false",100);
}


function swapVisibility(object,forceVisibility){

	keepPopupShown();

	if (object=="searchPopup")
	{
		document.getElementById('loginPopup').style.visibility = "hidden";
	}
	else
	{
		document.getElementById('searchPopup').style.visibility = "hidden"
	}	


	document.getElementById(object).style.visibility = (document.getElementById(object).style.visibility == "hidden")?"visible":"hidden";


	if (document.getElementById(object).style.visibility=="visible")
	{
		if (object=="loginPopup")
		{
			document.login.username.focus();
		}
		else
		{
			document.search.q.focus();
		}
	}




	/*  redundadnte pre istotu, aby sa pri refreshe pri prechode na ssl urcite objavil login popup - property forceVisibility
	if(forceVisibility)
	{
		document.getElementById(object).style.visibility = "visible";
	}
	else
	{
		document.getElementById(object).style.visibility = (document.getElementById(object).style.visibility == "hidden")?"visible":"hidden";		
	}
	*/
	


}


//
// get bottom of page information in product page and set the productlist div height
//


var bottom;

function getBottom(){
	bottom =  document.getElementById('bottom').offsetTop;
	if(bottom<550) bottom=550;
	bottom += 20;
	if(document.getElementById('productLeftList') && document.getElementById('product'))
	{
		if(is.moz)
		{
			bottom += -73;
			document.getElementById('productLeftList').style.height = bottom+"px";
			document.getElementById('product').style.height = bottom+"px";
		}
		else
		{
			document.getElementById('productLeftList').style.height = bottom+"px";
			document.getElementById('product').style.height = bottom+"px";
		}
	}
}



