// Predstahujem obrazky pro menu hover 
var oImagePreloader1;
var oImagePreloader2;

function OnLoad(){
	Preload1();
	SetSpodekHeight();
	AddClass(document.body, "no_collapse");
	RemClass(document.body, "no_collapse");
}

function OnResize(){
	SetSpodekHeight();
}

function SetSpodekHeight(){
	return; // Vypnuto - dela jedine bordel...
	var iWinHei = GetWindowHeight();
	var oDiv = document.getElementById("katalog");
	if(oDiv){
		var iKatHei = oDiv.offsetTop;
		//alert((iWinHei-500) + "px");
		oDiv.style.height = (iWinHei - 228) + "px"; // 225 s footerem 
		//alert(oDiv.style.height);
	}
}


function Preload1(){
	var asImgUrls = new Array();
	//var asKeywords = "akce dopl jedn noze obuv ocil ochr zast".split(" ");
	var asKeywords = "koca auto post jide preb leha alar hrac osta akce".split(" ");;
	for(var i in asKeywords){
		asImgUrls.push("img/menu/menu-"+asKeywords[i]+"-b.gif");
		asImgUrls.push("img/menu/menu-"+asKeywords[i]+"-c.gif");
	}
	oImagePreloader1 = new cImagePreloader(asImgUrls, null);
}

function OnPreload1(){
	var asImgUrls = new Array();
	var asKeywords = /*"akce "+*/ "dopl jedn noze obuv ocil ruka zast".split(" ");
	for(var i in asKeywords){
		asImgUrls.push("img/header/header_left-"+asKeywords[i]+".jpg");
	}
	oImagePreloader2 = new cImagePreloader(asImgUrls, null);
}

function OnPreload2(){ alert("Loaded 2nd."); }




// Menu hover handler 
function MenuImg(oElement, bMouseOver){
	oElement.src = bMouseOver ? oElement.src.replace("_a.", "_b.") : oElement.src.replace("_b.", "_a.");
}



/** Kliknuti na "Zpět nahoru" */
function ScrollTop(){
	//DumpObjectEx(window.document.body, 'scroll');///
	window.scrollTo(window.document.body.scrollLeft, 0);
	return false;
}





/**  Kliknutí na malou fotku   */
function Thb(xEvent, sImgFile, sZboziNazev){
	//DumpObjectEx(xEvent);///
	
	if(bMSIE){
		OpenFotkaWindow(sImgFile, xEvent.screenX - 450, xEvent.screenY + 50);
	}
	else{
		if(0 != LoadFotkaScript(sImgFile, sZboziNazev, xEvent.clientX, xEvent.clientY) )
			alert("Nepodařilo se načíst snímek.");
	}
	//alert(33); /// Zobrazi se, takze chyba nenastava. 
}


/**  Otevře okno s danou fotkou na zadaných souřadnicích.  */
function OpenFotkaWindow(sImgFile, x, y){
	var sUrl = "fotka.php4?foto="+encodeURIComponent(sImgFile);
	var sProperties = "resizable=yes,scrollbars=yes,status=yes,width=200,height=160,left="+(x)+",top="+(y);
	window.oWndFoto = window.open(sUrl, "repo_fotka", sProperties);
	if(window.oWndFoto == null || window.oWndFoto.closed){
	}else{
		window.oWndFoto.moveTo(x, y);
		window.oWndFoto.focus();
	}
	if(null == window.oWndFoto) alert("Nepodařilo se otevřít okno pro fotku. Povolte prosím otevírání pop-up oken.");
}



/**  Nahraje skript pro danou fotku  */
function LoadFotkaScript(sImgFile, sZboziNazev, iClickX, iClickY){
	//alert("1: clientX: " + iClickX +", clientY: "+ iClickY);///
	
	//debugger; ///
	
	var oFotoDiv = document.getElementById("foto_big");
	if(!oFotoDiv) return 1001;
	
	
	// Set the header's text 
	var oFotoHeader = oFotoDiv.getElementsByTagName("div")[0];
	oFotoHeader.childNodes[0].innerHTML = sZboziNazev; // <div class="header"><span>...</span></div> 

	// Save the click coordinates 
	oFotoDiv.style.display = "none";
	oFotoDiv.style.top    = iClickY + "px";
	oFotoDiv.style.left   = iClickX + "px";
	
	var sScriptSrc = "fotka_js.php4" + "?foto=" + encodeURIComponent(sImgFile);
	LoadScript(sScriptSrc);
	return 0;
}

/**  Vola se z nahraného skriptu  */
function FotkaScriptLoadHandler(oFotoInfo){
	//alert("Triggered FotkaScriptLoadHandler()."); ///
	
	var oFotoDiv = document.getElementById("foto_big");
	if(!oFotoDiv) return false;	
	
	var oFotoImg = oFotoDiv.getElementsByTagName("img")[0];
	oFotoImg.src    = oFotoInfo.sFileUrl;
	oFotoImg.width  = oFotoInfo.iWid;
	oFotoImg.height = oFotoInfo.iHei;

	var iClickY = parseInt(oFotoDiv.style.top);
	var iClickX = parseInt(oFotoDiv.style.left);
	
	var iFotoY = Math.max(0, iClickY - oFotoInfo.iHei - 50);
	var iFotoX = Math.max(0, iClickX - oFotoInfo.iWid - 10);
	
	//alert("2: \tclientX: " + iClickX +", \tclientY: "+ iClickY + "\n2: \tFotoX: " + iFotoX +", \tFotoY: "+ iFotoY );///
	
	//oFotoDiv.style.top     = window.document.body.scrollTop  + 10 + "px";
	//oFotoDiv.style.left    = window.document.body.scrollLeft + 10 + "px";
	oFotoDiv.style.top     = window.document.body.scrollTop + iFotoY + "px";
	oFotoDiv.style.left    = iFotoX + "px";
	oFotoDiv.style.width   = oFotoInfo.iWid + (bMSIE ? 60 : 55);
	oFotoDiv.style.height  = oFotoInfo.iHei + (bMSIE ? 60 : 60);
	
	oFotoDiv.style.display = "block";
	oFotoDiv.onclick = function(){ this.style.display = "none"; }
}


/**  Nahraje skript ze zadané URL */
function LoadScript(sScriptSrc){
	
	//document.getElementById("dynamic_js_load").src = sScriptSrc; // jinak:
	var sScriptId = "ajax_js";
	
	var oHead = document.getElementsByTagName("head")[0];	
	var oAjax = document.getElementById(sScriptId);
	if(oAjax){
		//DumpObjectEx(oAjax);///
		oHead = oAjax.parentNode || oAjax.parentElement;
		oHead.removeChild(oAjax);
	}
	
	var oScriptElement = document.createElement("script");
	oScriptElement.type = "text/javascript";
	oScriptElement.src = sScriptSrc;
	oScriptElement.id =  sScriptId;
	oHead.appendChild(oScriptElement);
	
}



function OnKeyUp_Document(xEvent){
	if(!xEvent) xEvent = window.event;
	if(xEvent.keyCode == 27) // Esc 
		document.getElementById("foto_big").style.display = "none";
}




//window.document.onkeyup = OnKeyUp_Document;
window.onload   = OnLoad;
window.onresize = OnResize;