function hotkeys(evt) {
	evt = (evt) ? evt : ((event) ? event : null);
	switch(evt.keyCode) {
		case(27):
			hideLB();
			break;
	}
}

// img preload
$.preloadImages = function() {
  for(var i = 0; i < arguments.length; i++) {
    $("<img>").attr("src", arguments[i]);
  }
}

$.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);
	});
}

$(document).ready(function(){
	
	$(".lbox").click(function(){
		showLB(this);
		return false;
	})
	
});

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() + 50) + "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;
}