/**
 * @author Alexander Farkas
 * v. 1.02
 */
(function($) {
	$.extend($.fx.step,{
	    backgroundPosition: function(fx) {
            if (fx.state === 0 && typeof fx.end == 'string') {
                var start = $.curCSS(fx.elem,'backgroundPosition');
                start = toArray(start);
                fx.start = [start[0],start[2]];
                var end = toArray(fx.end);
                fx.end = [end[0],end[2]];
                fx.unit = [end[1],end[3]];
			}
            var nowPosX = [];
            nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
            nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];
            fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

           function toArray(strg){
               strg = strg.replace(/left|top/g,'0px');
               strg = strg.replace(/right|bottom/g,'100%');
               strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
               var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
               return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
           }
        }
	});
})(jQuery);


// animace pozadí menu
$(function(){

	$('#menu a')
		.css( {backgroundPosition: "-165px 22px"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(0px 22px)"}, {duration:150})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(-165px 22px)"}, {duration:250, complete:function(){
				$(this).css({backgroundPosition: "-165px 22px"})
			}})
		})
});


// fotky ve fotogalerii
$(function(){

	$('a.foto')
		.css( {backgroundPosition: "-250px 120px"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(0px 120px)"}, {duration:300})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(-250px 120px)"}, {duration:400, complete:function(){
				$(this).css({backgroundPosition: "-250px 120px"})
			}})
		})
});


// fotky ve fotogalerii
$(function(){

	$('#fotogalerie td a')
		.css( {backgroundPosition: "-250px 100px"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(0px 100px)"}, {duration:300})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(-250px 100px)"}, {duration:400, complete:function(){
				$(this).css({backgroundPosition: "-250px 100px"})
			}})
		})
});


// fotky ve fotogalerii
$(function(){

	$('#fotogalerie td a.zip')
		.css( {backgroundPosition: "0px 0px"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(0px 0px)"}, {duration:300})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(0px 0px)"}, {duration:400, complete:function(){
				$(this).css({backgroundPosition: "0px 0px"})
			}})
		})
});


// fotky ve fotogalerii
$(function(){

	$('#fotogalerie td a.nahoru')
		.css( {backgroundPosition: "0px 5px"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(0px 5px)"}, {duration:300})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(0px 5px)"}, {duration:400, complete:function(){
				$(this).css({backgroundPosition: "0px 5px"})
			}})
		})
});


// tlacitko
$(function(){

	$('input.iSubmit')
		.css( {backgroundPosition: "0% 0%"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(0% 20%)"}, {duration:150})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(0% 0%)"}, {duration:150, complete:function(){
				$(this).css({backgroundPosition: "0% 0%"})
			}})
		})
});


// inicializace lightboxu
$(document).ready(function(){
  $("a[rel^='lb']").lightbox();
});


// kontrola formatu e-mailove adresy
function check_email(adresa) {
//	re = /^[^.]+(\.[^.]+)*@([^.]+[.])+[a-z]{2,4}$/;
	re = /^([a-zA-Z0-9._-]+)@([a-zA-Z0-9._-]+)\.([a-zA-Z]{2,5})$/;
	return adresa.search(re) == 0;
}


//	Kontrola kontaktního formuláře
function sendmail() {

	if(document.forms[0].email.value != "") {
    	if (!check_email(document.forms[0].email.value) ) {
    	   alert("Vaše emailová adresa není vyplněna správně!");
    	   document.forms[0].email.focus();
    	   return false;
    	}
	}
	if(document.forms[0].zprava.value == "") {
		alert("Zpráva neobsahuje žádný text!");
		document.forms[0].zprava.focus();
		return false;
	}
	document.forms[0].submit();

}
