/* funkce, ktera jednak vypise mail pres JS, cimz blokne boty a jednak pouzije entity, cimz je to jeste lepsi :) */
function js_protect_email(var1,var2)
{
    var zavinac = "&#64;";
    var mailto = "mai&#108;&#116;&#111;&#58;";
    var e_mail = var1+zavinac+var2;
    var title = "title='"+e_mail+"'";

    document.write("<a class='email' href='"+mailto+e_mail+"'"+title+">"+e_mail+"</a>");
}

function insertFlash(eleId, swfFile, width, height, alt, wmode, flashVars)
{
    directFlashVars = '';
    if(flashVars != '')directFlashVars = '?'+flashVars;

    flashHtml =
    '<!--[if !IE]> -->'+"\n"+
    '<object type="application/x-shockwave-flash" data="'+swfFile+directFlashVars+'" width="'+width+'" height="'+height+'">'+"\n"+
    '<!-- <![endif]-->'+"\n"+
    '<!--[if IE]>'+"\n"+
    '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+width+'" height="'+height+'">'+"\n"+
    '<param name="movie" value="'+swfFile+directFlashVars+'" />'+"\n"+
    '<!--><!---->'+"\n"+
    '<param name="loop" value="true" />'+"\n"+
    '<param name="menu" value="false" />'+"\n"

    if(wmode)flashHtml += '<param name="wmode" value="transparent" />'+"\n";
    if(flashVars != '')flashHtml += '<param name="flashvars" value="'+flashVars+'" />'+"\n";

    flashHtml += alt+"\n";
    flashHtml += '</object>'+"\n";
    flashHtml += '<!-- <![endif]-->'+"\n";

    obj = document.getElementById(eleId);
    obj.innerHTML = flashHtml;
}






$(document).ready(function() {

    $(".mainCat").click(function(event) {
        event.preventDefault();
            /**
            if ($(this).next().is("div.subdiv")) {
                $(this).next().toggle();
                event.preventDefault();
            }
            **/
            $(this).nextAll("div.subdiv").eq(0).toggle();
            

    });

    /* zobrazi aktivni menicko */
    $(".catBoxContent .subdiv .active").parent().show();
    $(".mainCat.active").nextAll("div.subdiv").eq(0).show();




    /* prepinac strednich menu */
    $(".midMenu a:not(.strankovani)").click(function(event) {
        event.preventDefault();
        
        $(".bookDesc").hide();
        $("#desc-2").show(); // diskuze vzdy videt
        $("#"+$(this).attr("href").slice(1)).show();
        $(".midMenu a").removeClass("active");
        $(this).addClass("active");

        
    });

    /*  defaultne rozbali vybrane */
    $(".midMenu a.active").each(function() {
        $("#"+$(this).attr("href").slice(1)).show();
    });
    /*  $("#"+$(".midMenu a.active").attr("href").slice(1)).show(); */


    /* vyprazdnuje searchBar */
    $("#searchBar .text").focus( function() {
        if ($(this).val() == 'hledaný výraz') {
            $(this).val("");
        };
    });


    /* schovava LoginBox */
    $("#loginBoxBackground").click(function () {
        $("#loginBoxBackground").toggle();
        $("#loginBox").toggle();
    });

    $("a.loginShow").click(function(event) {
        event.preventDefault();
        
        $("#loginBoxBackground").toggle();
        $("#loginBox").toggle();

        
    });
    
    $("a.loginHide").click(function (event) {
        event.preventDefault();
        
        $("#loginBoxBackground").toggle();
        $("#loginBox").toggle();
        
    });       
    
    /* schovava feedback */
    $("#feedbackBoxBackground").click(function () {
        $("#feedbackBoxBackground").toggle();
        $("#feedbackBox").toggle();
    });
    
    $("a.feedbackHide").click(function (event) {
        event.preventDefault();
        
        $("#feedbackBoxBackground").toggle();
        $("#feedbackBox").toggle();
        
    });    

    $("a.feedbackShow").click(function(event) {
        event.preventDefault();
        
        $("#feedbackBoxBackground").toggle();
        $("#feedbackBox").toggle();

        
    });    
    

    /* schovava epub */
    $("#epubBoxBackground").click(function () {
        $("#epubBoxBackground").toggle();
        $("#epubBox").toggle();
    });

    $("a.epubShow").click(function(event) {        
        event.preventDefault();      
        
        $("#epubBoxBackground").toggle();
        $("#epubBox").toggle();
           
    });
    
    $("a.epubHide").click(function (event) {
        event.preventDefault();
        
        $("#epubBoxBackground").toggle();
        
        $("#epubBox").toggle();
        
    });    
    
    /*  nastavi vysku na cely screen */
    var screenY = $("html").height();    
    $("#epubBoxBackground").height(screenY);
    $("#feedbackBoxBackground").height(screenY);
    $("#loginBoxBackground").height(screenY);
    
    
  
    
    
    

    //zavirani login escapem
    $(document).keyup(function(event) {
    	  if (event.keyCode == 27) {
    		  $("#loginBoxBackground").trigger('click');
    	  }
    });

    //otvirani loginu po neuspesnem prihlaseni
    if($('div#loginBox.showLogin').length) {        
         $("#loginBoxBackground").toggle(); 
         $("#loginBox").toggle(); 
    	/* /$("a.loginShow").trigger('click'); */
    }


    /*  strankovani */
    $("div.stranka").hide();
    /* $("div.stranka").eq(0).show();  */
    $(".centerBox").each( function() {
        $(this).find("div.stranka").eq(0).show();
    });

    /* prepinac strankovani */
    $("a.strankovani").click(function(event) {
        event.preventDefault();
        
        $(this).parents(".centerBox").find("div.stranka").hide();

        /*  $("div.stranka").hide();*/
        $("#"+$(this).attr("href").slice(1)).show();
        /* $("a.strankovani").removeClass("active"); */
        $(this).parents(".centerBox").find("a.strankovani").removeClass("active");
        $(this).addClass("active");

        
    });
    
    
    /* hlasovani */
    $('.star').rating({ 
        required: 'false',  
        callback: function(value, link){
            this.form.submit();
            /*  alert(value); */
        }        
    });
     
    

    /* dhtml banner */
    var changer = $('div.changer');

    if(changer.length) {
    	var dur = 5000;
    	var lis = changer.find('li');
    	var go = false;

    	if(lis.length > 1) {
	    	lis.hide().eq(0).show();

	    	changer.data('index', 0);
	    	changer.data('timeout', null);

	    	var html = '<div class="pager">';
	    	html += '<a href="#" class="controll pause"><span>pause</span></a>';

	    	lis.each(function(i, ele){
	    		html += '<a href="#">'+(i+1)+'</a>';
	    	});

	    	html += '</div>';

	    	changer.prepend(html);

	    	var pager = changer.find('div.pager');
	    	var pages = pager.find('a');

	    	/* pager.css('margin-left', changer.width() - pager.outerWidth() - parseInt(pager.css('padding-right'))); */

	    	pages.css('opacity', 0.7).click(function(event){
	    		event.preventDefault();
	    		if($(this).hasClass('controll')) {
	    			if($(this).hasClass('pause')) {
	    				$(this).removeClass('pause').addClass('play');
	    				window.clearTimeout(changer.data('timeout'));
	    			} else {
	    				$(this).removeClass('play').addClass('pause');
	    				setChanger();
	    			}
	    		} else {
	    			var index = changer.data('index');
		    		var cur = lis.eq(index);
		    		var ni = parseInt($(this).html()) - 1;
		    		var next = lis.eq(ni);

		    		changer.data('index', ni);
		    		pages.css('opacity', 0.7);
		    		$(this).css('opacity', 1);

		    		cur.fadeOut();
		    		next.fadeIn();
	    		}
	    	}).eq(1).css('opacity', 1);

	    	function setChanger(){
	    		if(go) {
		    		var index = changer.data('index');
		    		var cur = lis.eq(index);
		    		var next = null;

		    		pages.css('opacity', 0.7);

		    		if(index == lis.length - 1) {
		    			next = lis.eq(0);
		    			changer.data('index', 0);
		    			pages.eq(1).css('opacity', 1);
		    		} else {
		    			next = lis.eq(index + 1);
		    			changer.data('index', ++index);
		    			pages.eq(index + 1).css('opacity', 1);
		    		}

		    		cur.fadeOut();
		    		next.fadeIn();
	    		}

	    		changer.data('timeout', window.setTimeout(setChanger, dur));
	    		go = true;
	    	};

	    	setChanger();
    	}
    }
    
    
    
    
    
    
    
    
    /* FILTR NA CTECKY */
    $("#cteckaButton").click( function(event) {
        event.preventDefault();
        this.blur();
        
        if ( $("#cteckaSelector").is(":hidden") ) {
            $("#cteckaSelectorBox").css("width","286px");
            $("#cteckaSelector").slideDown("slow");
        } else {        
            $("#cteckaSelector").slideUp("slow");
            $("#cteckaSelectorBox").css("width","107px"); 
        }
        
       
    });
    
    
    
    
    
    
    
    

});
