$(document).ready(function($) {
   $('a[rel*=facebox]').facebox();
   ready_menu(); 
});

function ready_menu() {
   $(".dynm").each(function() {
        
        $(this).hover(function(e) {
            var id = $(this).attr("rel");
            $(".popup_menu").hide();
            $("#popup_"+id).show().mouseenter(function(e) {
                $("#popup_"+id).mouseleave(function(e) {
                    $("#popup_"+id).hide();
                });
            });
        }, function(e) {
            var id = $(this).attr("rel");
            var pl_menu = $(this).position().left + $("#center").position().left;
            
            //konrolujeme sirku
            if((e.pageX >= pl_menu) && (e.pageX <= (pl_menu + $("#popup_"+id).width()))) {
                //kontrolujeme vysku, staci, pokud je nad menu, pod menu je to ok
                if(e.pageY > $("#menu").position().top) return;
            }
            $(".popup_menu").hide();
        });
   });
}


function check_checkbox(check_target_input, check_target_id, radio) {
    if($("input[name='" + check_target_input + "']").is(":checked")) {
        $("input[name='" + check_target_input + "']").removeAttr("checked");
        $("#" + check_target_id).removeClass("checked_checkbox");
    } else {
        if(radio != null) { //jelikoz se jedna o radio, vsechny checked musime odcheckovat
            $("input:checked").removeAttr("checked");
            $(".checked_checkbox").removeClass("checked_checkbox");
        }
        $("input[name='" + check_target_input + "']").attr("checked", "checked");
        $("#" + check_target_id).addClass("checked_checkbox");
    }
    return false;
}

$(document).ready(function() {
    var selected_card = "";
   $("#cards_choice > img").mousemove(function() {
      var name = $(this).attr("id");
      $(this).attr("src", "/design/cards/l" + name + ".gif");
   }).mouseout(function() {
      var name = $(this).attr("id");
      if(name != selected_card) $(this).attr("src", "/design/cards/g" + name + ".gif");
   }).click(function() {
      var name = $(this).attr("id");
      selected_card = name;
      $("#cards_choice > img").trigger("mouseout");
      $(this).trigger("mousemove");
      $("#your_choice").html("Vybrali jste <span>platební kartu " + $(this).attr("class") + "</span>. Nyní můžete pokračovat.");
      $("#pay_card a").click(function() {
         $("#pay_card").attr("action", "https://3dsecure.csas.cz/transaction").submit();
         //$("#pay_card").attr("action", "http://www.it-bedna.cz/test.php").submit();
      });

      $("input[name='brand']").val($(this).attr("class"));
   }).css("cursor", "pointer");
});

function inArray(array, needle) { for(i = 0; i < array.length; i++) { if(array[i] == needle) return true; } return false; }

function faq() {
    /*
    var id = $.cookies.get("faq_main");
    if(id != null) {
        //neco bylo otevreno
        var index = $.cookies.get("faq_main_index");
        if($(o).text() == "zobrazit") {
            $(o).text("skrýt");
            $.cookies.set("faq_main", id);
        } else {
         $(o).text("zobrazit");
         $.cookies.del("faq_main", id);
      }
      $("#" + id).slideToggle();
    }
    */  
        
    
    $("strong").each(function(index, element) {
        $(this).bind('click', function() {
            $(this).parent().first().parent('.hidden').first().children(".hidden").hide();
            $.cookies.set("faq_main_index", index);
            var show = true;
            $(this).parent().nextAll().each(function() {
                if($(this).hasClass('hidden') && show) {
                    $(this).show().css("margin", "0 0 15px 15px");
                }
                if($(this).children().first().is("strong")) show = false;
            });
            
        }).css("text-decoration", "underline").css("cursor", "pointer");
    });
    
}

function zmen_dph(url) {
    $.cookies.set("page_reloaded", window.location.href);
    $.cookies.set("top", $(document).scrollTop());
    
    $("#form-zmen-dph input[name=url]").val(url);
    $("#form-zmen-dph").submit();
}

$(document).ready(function() {
    //po zmene dph kontrola, kde jsme
    var page = $.cookies.get("page_reloaded");
    var top = $.cookies.get("top");
    
    $.cookies.del("page_reloaded");
    $.cookies.del("top");
    
    if((page != null) && (page == window.location.href)) {
        $(document).scrollTop(top);
    } 
});

$.extend({
  getUrlVars: function(){
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
      hash = hashes[i].split('=');
      vars.push(hash[0]);
      vars[hash[0]] = hash[1];
    }
    return vars;
  },
  getUrlBash: function(){
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('#');
    return hashes[1];
  },
  getUrlVar: function(name){
    return $.getUrlVars()[name];
  }
}); 
