/* Counted on page load (count of related pod divs for comparison when hiding related accordion */
var countPodDivs = 0;
//incremented and compared to countPodDivs. If they are equal (no related docs) then hide related accordion.
var countHiddenRelatedPods = 0;

/*Hides parent div on related docs if there aren't any for each doc type. If all */
function hideParent(thisId) {
    $('#' + thisId).parent().css('display', 'none');
    countHiddenRelatedPods++;
    //if number of related pods is equal to the number that are hidden, hide the whole related accordion
    if (countPodDivs == countHiddenRelatedPods) {
        $("#relatedHeader").css('display', 'none');
        $("#relatedDocuments").css('display', 'none');
        $("#content_right").css('margin-top', '-5px');
    }
}




$(document).ready(function() {

    $(function() {
        $(".MainContent img").lazyload({
            placeholder: ResolveUrl("~/App_Themes/Website/images/grey.gif"),
            effect: "fadeIn"
        });

        $("#content_right img").lazyload({
            placeholder: ResolveUrl("~/App_Themes/Website/images/grey.gif"),
            effect: "fadeIn"
        });


    });

    /******* RIGHT NAV ********/
    //Only for related docs header as this is hard coded
    $('#relatedHeader').click(function() {
        $('#relatedDocuments').slideToggle('slow', function() {
            // Animation complete.
        });
    });

    //only for custom headers as these are dynamic
    $('.rightNavHeader').click(function() {
        var paneID = $(this).attr('id') + "Content";
        if ($(this).hasClass("rightNavHeaderActive")) {
            $(this).removeClass("rightNavHeaderActive");
        }
        else {
            $(this).addClass("rightNavHeaderActive");
        }

        $('#' + paneID).stop(true, true).slideToggle('slow', function() {
            // Animation complete.
            $.rerunLazyload();
        });
    });







    /******** RELATED PODS ************/

    $('#viewAllImages').click(function() {
        $('#viewAllImagesDiv').slideToggle('slow', function() {
            // Animation complete.
            $.rerunLazyload();
        });
    });

    $('#viewAllAudio').click(function() {
        $('#viewAllAudioDiv').slideToggle('slow', function() {
            // Animation complete.
            $.rerunLazyload();
        });
    });

    $('#viewAllVideo').click(function() {
        $('#viewAllVideoDiv').slideToggle('slow', function() {
            // Animation complete.
            $.rerunLazyload();
        });
    });

    $('#viewAllPages').click(function() {
        $('#viewAllPagesDiv').slideToggle('slow', function() {
            // Animation complete.
            $.rerunLazyload();
        });
    });

    $('#viewAllPeople').click(function() {
        $('#viewAllPeopleDiv').slideToggle('slow', function() {
            // Animation complete.
            $.rerunLazyload();
        });
    });

    $('#viewAllLearning').click(function() {
        $('#viewAllLearningDiv').slideToggle('slow', function() {
            // Animation complete.
            $.rerunLazyload();
        });
    });


    countPodDivs = $('.relatedPod').size();










    /******** Feature image **********/

    var zoomed = false;
    var firstzoom = true;
    $('#featureImgZoomBtn').click(function(e) {
        zoomed = !zoomed;

        if (firstzoom) {
            $(".featureImgZoom").jqzoom();
            firstzoom = false;
        }
        if (zoomed) {
            $('.jqZoomPup').css('display', 'block');
            $('div.jqZoomWindow').css('display', 'block');
            $(".featureImgZoom").css({ 'cursor': 'crosshair' });
            $('#featureImgZoomBtn img').attr("src", ResolveUrl("~/App_Themes/Website/images/btn_StopZoom.png"));
        }
        else {
            $('.jqZoomPup').css('display', 'none');
            $('div.jqZoomWindow').css('display', 'none');
            $(".featureImgZoom").css({ 'cursor': 'pointer' });
            $('#featureImgZoomBtn img').attr("src", ResolveUrl("~/App_Themes/Website/images/btn_Zoom.png"));
        }
        //$(".jqZoomWindow").bind("contextmenu", function(e) { e.preventDefault(); });
        return false;
    });


    $(".featureImgZoom").hover(function(e) {
        if (!zoomed) {
            /* Use if lensreset = true in zoom js file*/
            /*
            $('.jqZoomPup').css('display', 'none');
            $('div.jqZoomWindow').css('display', 'none');
            */
            $(".featureImgZoom").css({ 'cursor': 'default', 'position': 'relative', 'display': 'block' });
        }
    });

    $('.featureImgZoom').click(function(e) {
        e.preventDefault();
    });

    $(document).click(function(e) {
        if (zoomed) {
            zoomed = !zoomed;
            $('.jqZoomPup').css('display', 'none');
            $('div.jqZoomWindow').css('display', 'none');
            $(".featureImgZoom").css({ 'cursor': 'pointer' });
            $('#featureImgZoomBtn img').attr("src", ResolveUrl("~/App_Themes/Website/images/btn_Zoom.png"));
        }
    });







});


function ResolveUrl(url) {
    if (url.indexOf("~/") == 0) {
        url = baseUrl + url.substring(2);
    }
    return url;
}
