$(document).ready(function() {
    var $_WORK = true;

	/** nacitavanie obsahu stranky **/
	jQuery.fn.stranka = function(url) {
		$.post(url, {"ajax":"true"}, function(data) { setTimeout(function () {$(".body").html(data); }, 350);});
	};

    $(".lang-menu a").fadeTo(0, 0.5, function () {
        $(".lang-menu a.active").fadeTo(1500, 1);
        $(".lang-menu a:not(.active)").mouseover(function () {  $(this).fadeTo(500, 1);     });
        $(".lang-menu a:not(.active)").mouseout(function () {   $(this).fadeTo(500, 0.5);   });   
    });
    $(".lang-menu a.active").click(function () { return false; });      
    /*
    $(".lang-menu a").click(function () {
        $.post("/", {"ajax":"true", "lang":$(this).attr("title") }, function(data) {
            document.location.reload();
            });
        return false;
    });  
    */  
    
    /** FOOT GALLERY --> **/ 
    var pocet= $("#pracovali-sme-pre a").length;
    if(pocet>0) {
        var pocet_boxov = Math.floor(pocet/5);    
        if(pocet_boxov!=pocet/5) { pocet_boxov++; }   
        
        var output = '';
        for(var i=1; i<=pocet_boxov; i++) {
            output += '<div style="display:inline-block;text-align:center;">';
            var x = 5 * (i-1);
            for(var j=1; j<=5; j++) {
                if( $("#pracovali-sme-pre a").eq(x+(j-1)).length == 1 ) {
                     output += $("#pracovali-sme-pre a").eq(x+(j-1)).outerHTML();   
                }
            }
            output += '</div>';        
        }
        $("#pracovali-sme-pre").html('<div style="width:3775px;">'+output+'</div>');
        var s = 0;
        var next_id = 2;
        $("#pracovali-sme-pre div:last a").each(function(i) {   s = s + $(this).width();    });
        $("#pracovali-sme-pre div:last").width(s + 'px');
        
    	function galeria_timer() {
            var next_sirka = $("#pracovali-sme-pre div").eq(next_id).width();
            var posunute = $("#pracovali-sme-pre div:first").css("margin-left").replace("px","");
            var posun = posunute-next_sirka;
            
            if(next_id==1) {posun = 0;}
            if(next_id==pocet_boxov) {next_id=1;} else {next_id++;}
            $("#pracovali-sme-pre div:first").animate({"margin-left":""+posun+"px"},2000);
    		setTimeout(function () {galeria_timer();}, 8650);
    	}
    	setTimeout(function () {galeria_timer();}, 6650);
    }
    /** FOOT GALLERY <-- **/
    
    
    function slideSwitch() {
        var $active = $('#slideshow IMG.active');
        if ( $active.length == 0 ) $active = $('#slideshow IMG:last');
    
        var $next =  $active.next().length ? $active.next()
            : $('#slideshow IMG:first');
    
        //random
        // var $sibs  = $active.siblings();
        // var rndNum = Math.floor(Math.random() * $sibs.length );
        // var $next  = $( $sibs[ rndNum ] );
    
    
        $active.addClass('last-active');
    
        $next.css({opacity: 0.0})
            .addClass('active')
            .animate({opacity: 1.0}, 2050, function() {
                $active.removeClass('active last-active');
            });
        setTimeout(function () {slideSwitch();}, 2850);
    }
    setTimeout(function () {slideSwitch();}, 2850);
    
    
});
