﻿//
// Inicializace událostí vytvořených pomocí knihovny jquery.js
//
$(document).ready(function() {

    // přepsání prvků checkbox, radiobutton
    $('input[type=checkbox],input[type=radio]').prettyCheckboxes();

    // zobrazí/skryje okno pro přihlášení zákazníka
    $("#customerlogin, #customerlogin-box .close").click(function() {
        $("#customerlogin-box").animate({ "height": "toggle" }, 200);
        $("#customerlogin-box .chyba").css("display", "none");
    });


    // fancybox - zobrazování obrázků
    $("a.fancybox").fancybox({
        'autoScale': true,
        'titleShow': true,
        'titlePosition': 'over',
        'overlayOpacity': 0.5,
        'overlayColor': '#222',
        'transitionIn': 'elastic',
        'transitionOut': 'elastic'
    });


    // FADE OUT - postupné skrytí tagu
    $(".fadeOut").fadeOut(5000);


    // AKTUALITY na homepage
    $("#aktuality #navigator .switch:first").addClass("switch-aktual");
    //$("ul.hpAktualita:first").show(); aby byla vidět první novinka i při zakázaném javascriptu, nastavuje se u první "display:block;" přímo při vytváření

    $("#aktuality #navigator .switch").click(function() {

        var id = ($(this).attr("id")).replace("switch_", "");

        //pokud se jedná o aktuálně zobrazenou aktualitu
        if ($("#aktuality #aktualita_" + id).is(":visible")) {
            return;
        }
        else {
            $("#aktuality #navigator .switch").removeClass("switch-aktual");
            $("#aktuality #navigator #switch_" + id).addClass("switch-aktual");
            $("#aktuality .aktualita").hide();
            $("#aktuality #aktualita_" + id).fadeIn(1000);
            $("#aktuality #aktualita_" + id).show();
        }
    });



    // HELP - zobrazení okna s nápovědou nad/pod ikonkou help
    $('.help').each(function() {

        var $this = $(this);
        var text = $this.attr('title');
        var title = this.previousSibling.nodeValue;
        var ikonka = {
            height: 13,
            width: 12
        };
        var time = null;
        var $cover = $("<div style='width:100px'><span></span></div>");
        var $helpbox = $('<div class="helpBox"><div class="spc"><h4></h4><p></p><span></span></div></div>');


        $this.attr('title', '').find('img').attr('alt', '');
        $helpbox.css({ 'position': 'absolute', 'z-index': '100' });

        $this.bind('mouseenter', function(e) {

            $('.helpBox').remove();

            time = setTimeout(function() {
                $helpbox.css({ 'opacity': '0' }).appendTo('body').find('p').text(text).end().find('h4').text(title);

                var top = e.clientY < $helpbox.outerHeight() ? $this.offset().top + $this.height() + ikonka.height : $this.offset().top - $helpbox.outerHeight() - (ikonka.height / 2);
                var left = $this.offset().left - (ikonka.width / 2);

                //e.clientY < $helpbox.outerHeight() ? $helpbox.removeClass('reverse') : $helpbox.addClass('reverse');
                $helpbox.css({ 'top': top, 'left': left });
                $helpbox.css({ 'opacity': '' }).show();
            }, 250);

            return false;
        });

        $this.bind('mouseleave', function(e) {
            time = clearTimeout(time);
            $('.helpBox').hide().remove();
        });

    });

});



// PROMO BANNERY
function ChangePromoBanner(Direction, ManualChange) {
    
    clearTimeout(promoTimeOut);
    
    var ToIndex;
    var CurrentIndex = $("#promo-box > .promo-banner").index($("#promo-box > .promo-banner:visible"));
    if (Direction == -1)
        ToIndex = (CurrentIndex == 0) ? 4 : CurrentIndex - 1;
    else
        ToIndex = (CurrentIndex == 4) ? 0 : CurrentIndex + 1;

    if (ManualChange) {
        $("#promo-box > .promo-banner:eq(" + CurrentIndex + ")").hide();
        $("#promo-box > .promo-banner:eq(" + ToIndex + ")").show();
    }
    else {
        $("#promo-box > .promo-banner:eq(" + CurrentIndex + ")").css("zIndex", "2").fadeOut(2000, function() { $(this).css("zIndex", "1"); $(this).hide(); });
        $("#promo-box > .promo-banner:eq(" + ToIndex + ")").css("zIndex", "1").show().fadeIn(2000);
    }

    promoTimeOut = setTimeout("ChangePromoBanner(1, false)", 10000);
}

$(document).ready(function() {
    $("#promo-box .promo-banner-navig-left").click(function() { ChangePromoBanner(-1, true); });
    $("#promo-box .promo-banner-navig-right").click(function() { ChangePromoBanner(1, true); });

    promoTimeOut = setTimeout("ChangePromoBanner(1, false)", 10000);
});






function Tisk()
{
    bV = parseInt(navigator.appVersion)
    if (bV >= 4) self.print()
}


function LM_Toogle( nodeID ) {

  node = document.getElementById("VD_" + nodeID);
  node.style.display = (node.style.display == "block") ? "none" : "block";
}


function SP_Uzel( idskupiny ) {
  skupina = document.getElementById("sp_" + idskupiny);
  
  if (skupina.style.display == 'block') {
    skupina.style.display = 'none';
  }
  else {
    // sbalí všechny skupiny
    skupiny = skupina.parentNode.parentNode.getElementsByTagName("ul");
	  for (i=0; i < skupiny.length; i++)
	  {
		  skupiny[i].style.display = 'none'
	  }
  	
    // zobrazi danou skupinu
    skupina.style.display = 'block';
  }
 
}


