$(document).ready(function(){
	
	$(".lbox").click(function(){
		showLB(this);
		return false;
	})
	
	$(".trevent").mouseover(function(){
		$(this).addClass("emph " + $(this).attr("class"));
		
	});
	
	$(".trevent").mouseout(function(){
		$(this).removeClass("emph");
	})
	
	$(".offBlock").mouseover(function(){
		$(this).addClass("emph " + $(this).attr("class"));
	})
	
	$(".offBlock").mouseout(function(){
		$(this).removeClass("emph");
	})
	
	$(".gStep").click(function(){
		gstep($(this).attr("id"));
		return false;
	});
	
	// jidelni listek
	secOn = false;
	$(".jsHide").toggle();
	$(".jsHide:first").toggle();
	$(".sideMenu:first").toggleClass("emph");
	$(".sideMenu").click(function(){
		$(".jsHide").hide();
		$( $(this).attr("href") ).toggle();
		$(".sideMenu").removeClass("emph");
		$(this).toggleClass("emph");
		return false;
	});
	$(".mnList > dd:odd, .mnList > dt:odd").toggleClass("odd");
	
	// index sideBlocks
	$(".sideBlock").click(function(){
		location.href = $(this).children("p").children("a").attr("href");
		return false
	});
	
	
});

$.fn.image = function(src, id, f){
	return this.each(function(){
		var i = new Image();
		i.src = src;
		i.id = id;
		i.onload = f;
		this.appendChild(i);
	});
}

function showLB(a) {
	
	document.onkeydown = hotkeys;
	
	var im = new Image();
	im.id = "lbimg";
	im.src = a.href;
	
	// osetreni onload / cache kvuli casovani
	if(im.complete) {
		loadLB();
	} else {
		im.onload = loadLB;
	}
	
	function loadLB() {
		
		$("body").append('<div id="lb"><div id="lbcontent"><div id="lbTop"></div><div id="lbBot" class="clear"><span class="desc">' + a.title + '</span><a id="closeButton" class="close" href="#" title="Zavřít / Close">Zavřít / Close</a></div></div></div>');
		$("#lbTop").append(im);
		
		pg = getPageSize();
		// tmave pozadi (nastaveni vysky podle nactene stranky)
		$("#lb").css("height", pg[1] + "px");
		$("#lb").click(hideLB);
		// samotny box
		$("#lbcontent").css("marginTop", (getPageScroll() + 70) + "px");		// (podle nactene stranky nastavit horni okraj)
		$("#lbcontent").css("width", ($("#lbimg").width()) + "px");				// nastavit sirku boxu podle nacteneho obrazku (aby se vycentrovalo)
		$("#lbcontent").css("background","#eee");								// donastavit boxu sedobilou na pozadi, kvuli problikavani ve FF
		
		/* fov = new FlashObject(path, "swf_" + nick, swfWidth, swfHeight, "8", "#ffffff");
		fov.addParam("quality", "high");
		fov.write(nick + "Movie"); */
	}
}

function hideLB(){
	$("#lb").remove();
	document.onkeydown = "";
}

//
// getPageSize()
// Returns array with page width, height and window width, height
// Code from - quirksmode.org & Lightbox JS by Lokesh Dhakar
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		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
		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 = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

//
// getPageScroll()
// Returns y page scroll values.
// Code from - quirksmode.org & Lightbox JS by Lokesh Dhakar
//
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	return yScroll;
}

function hotkeys(evt) {
	evt = (evt) ? evt : ((event) ? event : null);
	switch(evt.keyCode) {
		case(27):
			hideLB();
			break;
	}
}

function gstep(id) {
	
	art = $(".gSection").get();
	for(i = 0; i < art.length; i++) {
		if(art[i].className.indexOf("emph") != -1) {
			act = parseInt(art[i].id.substring(4, 5));
		}
	}
	
	if(id == "sNext") {
		newact = (act == art.length - 1) ? 0 : act + 1;
	} else {
		newact = (act == 0) ? art.length - 1 : act - 1;
	}
	
	
	$("#gSec" + act).toggleClass("emph");
	$("#gSec" + newact).toggleClass("emph");
	
}
