﻿$(document).ready(function () {
    //$('#content-container').height($('#content-container').height());
    $('html').height($('html').height() - 110);
    $('.navigation > ul > li > a').each(function (index) {
        navText = $(this).text();
        $(this).html('<span>' + navText + '</span>');
    });

    $('.navigation .parent').each(function (index) {

        var parentLI = $(this);

        $('ul li', this).each(function (index) {

            if ($(this).hasClass('active')) {
                parentLI.addClass('active');
            }

        });
    });

    $('#ctl00_Banners_ctl00_ListDialog1').before('<div class="pager-container"><div class="pager">').cycle({
        fx: 'fade',
        timeout: 8000,
        pager: '.pager',
        pagerAnchorBuilder: function (idx, slide) {
            return '<a href="#"></a>';
        }
    });

    var config = {
        sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
        interval: 0, // number = milliseconds for onMouseOver polling interval    
        over: expandMenu, // function = onMouseOver callback (REQUIRED)    
        timeout: 0, // number = milliseconds delay before onMouseOut    
        out: collapseMenu // function = onMouseOut callback (REQUIRED)    
    };

    $(".navigation > ul > li").hoverIntent(config);

    function expandMenu() {
        jQuery(this).find("> ul").show();
    }

    function collapseMenu() {
        jQuery(this).find("> ul").hide();
    }

    function centerBanner(a, b) {
        if (a < b) {
            $("#ctl00_Banners_ctl00_ListDialog1").css("left", ((b - a) / 2) * -1);
        } else {
            $("#ctl00_Banners_ctl00_ListDialog1").css("left", "");
        }
    }

    $(window).load(function () {
        centerBanner($(this).width(), $("#ctl00_Banners_ctl00_ListDialog1").width());
    });

    $(window).resize(function () {
        centerBanner($(this).width(), $("#ctl00_Banners_ctl00_ListDialog1").width());
    });

});
