$(document).ready(function(){
  Shadowbox.init({
    handleOversize: "drag",
    modal: true
  });
  var paras = $('#nasi-zakaznici ul li');
  var rand = Math.floor(Math.random() * paras.length);
  paras.eq(rand).addClass('active');
  $('#nasi-zakaznici ul li').shuffle();
	/* schovani o-firme */

		$("#odkryj-blok").click(function(event) {  
		   event.preventDefault();  
		   $("#schovany-blok").slideToggle();  
		});  
		$("a#zavrit").click(function(event) {  
		   event.preventDefault();  
		   $("#schovany-blok").slideUp();  
		});  
	/* konec schovani */

  /* sekce-menu */
  $("#menu-sekce a").hover(
		function () {
			$(this).find(".inner-btn").animate({
				"height": "+=30px"
			}, 800, "easeOutElastic");
		}, 
		function () {
			$(this).find(".inner-btn").animate({
				"height": "-=30px"
			}, 1500, "easeOutBounce");
		}
	);
  /* sekce-menu konec */
  
  /* srovnani vysky uvodnich sloupcu 
  
  vyskaLeft = $("#top-projekt").height();
  vyskaRight = $("#sloupek").height();
	if (vyskaLeft > vyskaRight) {
		$("#sloupek").css("height",vyskaLeft);
	} else {
		$("#top-projekt").css("height",vyskaRight);
	}
  */
  /* srovnani vysky uvodnich sloupcu konec */
  
  $(function(){
	  $("a[rel^='lightbox']").lightbox();
	});
	
	/* rozchodnik reference */
	
	$("#ref-rozchodnik a").hover(
		function () {
			$(this).find("img").css("z-index","10").animate({
				"width": "385px",
				"height": "185px",
				"marginLeft": "-64px",
				"marginTop": "-31px"
			}, 300, "easeOutExpo");
		}, 
		function () {
			$(this).find("img").css("z-index","1").animate({
				"width": "257px",
				"height": "123px",
				"marginLeft": "0px",
				"marginTop": "0px"
			}, 300, "easeOutExpo");
		}
	);
	
		$("#ref-rozchodnik2 a").hover(
		function () {
			$(this).find("img").css("z-index","10").animate({
				"width": "385px",
				"height": "185px",
				"marginLeft": "-64px",
				"marginTop": "-31px"
			}, 300, "easeOutExpo");
		}, 
		function () {
			$(this).find("img").css("z-index","1").animate({
				"width": "190px",
				"height": "91px",
				"marginLeft": "0px",
				"marginTop": "0px"
			}, 300, "easeOutExpo");
		}
	);
	
	/* pf 2010 */
	$("#pf img").hover(
		function () {
			$(this).css("z-index","10").animate({		
				"width": "424px",
				"height": "600px",
				"marginLeft": "-64px",
				"marginTop": "-31px"
			}, 300, "easeOutExpo");
		}, 
		function () {
			$(this).css("z-index","1").animate({
				"width": "320px",
				"height": "453px",
				"marginLeft": "0px",
				"marginTop": "0px"
			}, 300, "easeOutExpo");
		}
	);
	/* konec pf 2010 */
	
  
});
 /* slideshow */
function slideSwitch() {
	var $active = $('#nasi-zakaznici li.active');
	if ( $active.length == 0 ) $active = $('#nasi-zakaznici li:last');
	var $next =  $active.next().length ? $active.next()
		: $('#nasi-zakaznici li:first');
	$active.addClass('last-active');
	$next.css({opacity: 0.0})
		.addClass('active')
		.animate({opacity: 1.0}, 1000, function() {
			$active.removeClass('active last-active');
		});
}	

$(function() {
	setInterval( "slideSwitch()", 3000 );
});
/* slideshow - konec */
 /* slideshow april*/

function slideSwitch2() {
	var $active = $('#april li.active');
	if ( $active.length == 0 ) $active = $('#april li:last');
	var $next =  $active.next().length ? $active.next()
		: $('#april li:first');
	$active.addClass('last-active');
	$next.css({opacity: 0.0})
		.addClass('active')
		.animate({opacity: 1.0}, 1000, function() {
			$active.removeClass('active last-active');
		});
}	

$(function() {
	setInterval( "slideSwitch2()", 2000 );
});
/* slideshow april - konec */


function zavriVsechny() {
	document.getElementById('menu-cepi').style.display = "none";
	document.getElementById('menu-mixer').style.display = "none";
	document.getElementById('menu-wphaton').style.display = "none";
	document.getElementById('menu-rhtechnik').style.display = "none";
}

function ukazMenu(id) {
	var jeOtevreny = document.getElementById(id).style.display;
	if (jeOtevreny == "block") {
		zavriVsechny();
	} else {
		zavriVsechny();
		document.getElementById(id).style.display = "block";
	}
}

re = /^[^.]+(\.[^.]+)*@([^.]+[.])+[a-z]{2,4}$/;

function kontrola() {
 if (document.uprav.email.value==""){
			alert("Prosím, vložte svůj e-mail.");
    document.uprav.email.focus();
    document.uprav.email.select();
			return false;
			}
//	Kontrola e-mailu
	if ( document.uprav.email.value !="" ) {
		if (re.test(document.uprav.email.value) == 0) {
			alert ("E-mailová adresa není správná.");
			document.uprav.email.focus();
			document.uprav.email.select();
			return false;
		}
	 }
	 if (document.uprav.oborzajmu.value==""){
		alert("Prosím, vložte obor, o který máte zájem.");
    document.uprav.oborzajmu.focus();
    document.uprav.oborzajmu.select();
		return false;
		}
	 if (document.uprav.poznamka.value== ""){
		alert("Prosím, vložte poznámku.");
    document.uprav.poznamka.focus();
    document.uprav.poznamka.select();
		return false;
		}	

}

function kontrola_en() {
 if (document.uprav.email.value==""){
			alert("Please, enter your email.");
    document.uprav.email.focus();
    document.uprav.email.select();
			return false;
			}
//	Kontrola e-mailu
	if ( document.uprav.email.value !="" ) {
		if (re.test(document.uprav.email.value) == 0) {
			alert ("Email address is not correct.");
			document.uprav.email.focus();
			document.uprav.email.select();
			return false;
		}
	 }
	 if (document.uprav.oborzajmu.value==""){
		alert("Please, enter the field you are interested in.");
    document.uprav.oborzajmu.focus();
    document.uprav.oborzajmu.select();
		return false;
		}
	 if (document.uprav.poznamka.value== ""){
		alert("Please, enter a remark.");
    document.uprav.poznamka.focus();
    document.uprav.poznamka.select();
		return false;
		}	

}
function kontrolareseni() {
 if (document.upravreseni.email.value==""){
			alert("Prosím, vložte svůj e-mail.");
    document.upravreseni.email.focus();
    document.upravreseni.email.select();
			return false;
			}
//	Kontrola e-mailu
	if ( document.upravreseni.email.value !="" ) {
		if (re.test(document.upravreseni.email.value) == 0) {
			alert ("E-mailová adresa není správná.");
			document.upravreseni.email.focus();
			document.upravreseni.email.select();
			return false;
		}
	 }
	 if (document.upravreseni.oborzajmu.value == 0){
		alert("Prosím, zvolte obor, o který máte zájem.");
    //document.upravreseni.oborzajmu.focus();
    //document.upravreseni.oborzajmu.select();
		return false;
		}

}

function kontrolasearch() {

	co=document.hledat.co.value;

if (co == "" || co.length < 3){
			alert("Prosím, vložte minimálně 3 znaky");
		  document.hledat.co.focus();
  		document.hledat.co.select();
			return false;
}
}

// Kontrola formulare v moucnem hospodarstvi

function kontrolamh() {
 if (document.uprav.email.value==""){
			alert("Prosím, vložte svůj e-mail.");
    document.uprav.email.focus();
    document.uprav.email.select();
			return false;
			}
//	Kontrola e-mailu
	if ( document.uprav.email.value !="" ) {
		if (re.test(document.uprav.email.value) == 0) {
			alert ("E-mailová adresa není správná.");
			document.uprav.email.focus();
			document.uprav.email.select();
			return false;
		}
	 }
	 if (document.uprav.oborzajmu.value==""){
		alert("Prosím, vložte obor, o který máte zájem.");
    document.uprav.oborzajmu.focus();
    document.uprav.oborzajmu.select();
		return false;
		}
	 if (document.uprav.poznamka.value== ""){
		alert("Prosím, vložte poznámku.");
    document.uprav.poznamka.focus();
    document.uprav.poznamka.select();
		return false;
		}	

}

(function($){
 
    $.fn.shuffle = function() {
 
        var allElems = this.get(),
            getRandom = function(max) {
                return Math.floor(Math.random() * max);
            },
            shuffled = $.map(allElems, function(){
                var random = getRandom(allElems.length),
                    randEl = $(allElems[random]).clone(true)[0];
                allElems.splice(random, 1);
                return randEl;
           });
 
        this.each(function(i){
            $(this).replaceWith($(shuffled[i]));
        });
 
        return $(shuffled);
 
    };
 
})(jQuery);
