jQuery.fn.exists = function() { return jQuery(this).length > 0; }
$(document).ready(function() {
    $("a#donate").bind("click", function() {
        $("#donate_form").submit()
    });

    $(".fancyslike").fancybox({
        'zoomOpacity': true,
        'overlayShow': false,
        'zoomSpeedIn': 500,
        'zoomSpeedOut': 500
    });

    $("a.group").fancybox({
        'hideOnContentClick': false
    });

    $(function() {
        // Option set as a global variable
        $.fn.loopedSlider.defaults.addPagination = false;

        $('#loopedSlider').loopedSlider({
            autoStart: 3500,
            hoverPause: true,
            containerClick: false
        });
    });
    HandleMenu();
});


// Anketa
function ViewPollResults(afterVoting, siteUrl, language) {
    var rbgAnswers = document.getElementsByName("IDAnketaOdgovor");

    var pollId = document.getElementById("hfPollId");

    var checkedAnswerId;
    for (i = 0; i < rbgAnswers.length; i++) {
        if (rbgAnswers[i].checked) {
            checkedAnswerId = rbgAnswers[i].value;
            break;
        }
    }
    if (afterVoting) {

        window.location.href = siteUrl + "/PollResults.aspx?PollId=" + pollId.value + "&AnswerId=" + checkedAnswerId + "&l=" + language;
    }
    else {
        window.location.href = siteUrl + "/PollResults.aspx?PollId=" + pollId.value + "&l=" + language;
    }
}

function HandleMenu() {

    var currentGroupId = $("#hfproductGroupId").val();

    if (currentGroupId != "") {

        
        var selectedLi = $("#grp" + currentGroupId);

        if (!selectedLi.exists()) {
            return;
        }

        var parentUl = $(selectedLi).parent("ul");

        var childUl = $(selectedLi).children("ul");

        var startUl = childUl.exists() ? childUl : parentUl;

        if (!startUl.exists()) {
            return;
        }

        if (!($(startUl).hasClass("second-nav"))) {

            Expand(startUl);
        }
    }
}
function Expand(parentUl) {

    $(parentUl).show();
    //$(parentUl).prev().addClass("active");

    var parentParentUl = $(parentUl).parent().parent("ul");

    if (!($(parentParentUl).hasClass("second-nav"))) {
        Expand(parentParentUl);
    }
}

