$(document).ready(function(){
    var id = "";
    var buttons = {};
        buttons.prev = $("#faq .faq-content .navigation-buttons a:first");
        buttons.next = $("#faq .faq-content .navigation-buttons a:last");
        buttons.hidden = {};
        buttons.hidden.prev = null;
        buttons.hidden.next = null;
    
    // Zjištění který obsah se má vložit
    var location = window.location.toString();
    if (location.indexOf("#") != -1) {
        location = location.substring(location.indexOf("#"));
    } else {
        location = "#faq-subscription-vs-credits";
    }
    
    // Nastavení obsahu podle parametru v odkazu stránky
    $(location).show();
    $("#faq .steps ol li a[href="+ location +"]").addClass("active");
    
    buttons.hidden.prev = $(location + " input[name=prev]");
    buttons.hidden.next = $(location + " input[name=next]");
    setUpButtons();

    
    // Přepínání záložek
    $("#faq .steps ol li a").bind("click", switching);
    $("#faq .faq-content .navigation-buttons a").bind("click", switching);
    $("#l-tips a").bind("click", switching);

    // Hlavní funkce pro přepínání obsahu
    function switching(){
        id = $(this).attr("href").substr($(this).attr("href").indexOf("#"));
        
        $("#faq .steps ol li a").removeClass("active");
        $("#faq .steps ol li a[href="+ id +"]").addClass("active");
        
        buttons.hidden.prev = $(id + " input[name=prev]");
        buttons.hidden.next = $(id + " input[name=next]");
        
        setUpButtons();
        
        $("#faq .faq-content .items .faq-item").hide();
        $(id).show();
        
        window.location = "#" + id;
        //$("#faq .faq-content .navigation-buttons a").bind("click", switching);
    }
    
    // Nastvení odkazů a textů u navigačních tlačítek
    function setUpButtons() {
        if (typeof(buttons) == 'object') {
            buttons.prev.attr("href", buttons.hidden.prev.val());
            buttons.prev.html("&lt;&lt; Previous: "+ (buttons.hidden.prev.attr("title")));

            buttons.next.attr("href", buttons.hidden.next.val());
            buttons.next.html("Next: "+ (buttons.hidden.next.attr("title")) +" &gt;&gt;");
         }
    }
})
