﻿(function ($) { // encapsulated $


    $(function () { // Dom Ready Shortcut

        $(".SearchBox").css({ "border": "0" });

        // NAVIGATION
        //----------------------------------------------------------------------------------------------------------//

        $('#cNavigation ul').droppy();

        // groupWidth starting number calculated by the padding of the parent li + margin-right of each group
        var groupWidth = 40;
        var groupHeight = 0;

        $("#cNavigation > ul > li > ul > li").each(function () {
            $(this).find(".group").each(function () {
                groupWidth += $(this).outerWidth(true) + 10;

                if ($(this).height() > groupHeight) {
                    groupHeight = $(this).height();
                }
            });

            $(this).css({ "width": groupWidth });
            $(this).find(".group").css({ "height": groupHeight });

            groupWidth = 40;
            groupHeight = 0;

            $(this).find('div.group').last().css({ "border-right": "0" });

        });

        $("#cNavigation > ul > li > ul").css({ "visibility": "visible", "display": "none" });

        // SUB PAGE 
        //----------------------------------------------------------------------------------------------------------//

        var mainHeight = $("#cSubPage .main").height();
        var rightHeight = $("#cSubPage .right").height();

        if (mainHeight > rightHeight) {
            if ($.browser.msie && $.browser.version.substr(0, 1) < 8) {
                $("#cSubPage .right").css({ "height": mainHeight });
            }
            else {

                $("#cSubPage .right").css({ "min-height": mainHeight });
            }
        }
        else {
            if ($.browser.msie && $.browser.version.substr(0, 1) < 8) {
                $("#cSubPage .main").css({ "height": rightHeight });
            }
            else {

                $("#cSubPage .main").css({ "min-height": rightHeight });
            }
        }

	$(".reportModal").mouseover(function() {
		$(this).fancybox({
                centerOnScroll: false,
                frameWidth: 875,
                frameHeight: 675,
                overlayShow: true,
                hideOnOverlayClick: true,
                hideOnContentClick: false,
                enableEscapeButton: true,
                showCloseButton: true,
                href: "/ReportViewer/ReportViewer.aspx?Report=" + $(this).attr("href")
            });
	});


        // RIGHT COLUMN LOGIN
        //----------------------------------------------------------------------------------------------------------//
        if ($(".username").size() > 0) {
            $(".username").defaultValue({ value: "Username" });
            $(".password").defaultValue({ value: "Password" });
        }

        // RIGHT COLUMN LOGIN
        //----------------------------------------------------------------------------------------------------------//

        $("#cRecentNews p:last-child").css({ "margin": "0" });

        // FOOTER NAV
        //----------------------------------------------------------------------------------------------------------//

        $("#cFooterNav .expand").click(function (e) {
            e.preventDefault();
            $("#cFooterNav .bottom").slideToggle();
            $(this).toggleClass("active");

        });

        $("#cFooterNav .bottom div.section").hover(
		    function () {
		        $(this).css({ "background": "#e3eff8" });
		    },
		    function () {
		        $(this).css({ "background": "none" });
		    }
	    );


        $("#cFooterNav .bottom a").hover(
		    function () {
		        $(this).parents("div.section").css({ "background": "#e3eff8" });
		    },
		    function () {
		        //$(this).parents("div.section").css({"background":"none"});
		    }
	    );

        $("#cFooterNav .bottom div.section").each(function () {
            $("ul li ul li").not(":last-child").css({ "marginBottom": "20px" });
        });

        $("#cSubPage .right .rightModule:last").css("border", "none");
        $("#cSubPage #LeftColumnItems .LeftColumnItem:last").css("border", "none");


        /*  GOOGLE SEARCH 
        ______________________________________*/

        if ($(".googleBox").val() == '') {
            $(".googleBox").addClass('GoogleBoxBackground');
        }

        $(".googleBox").click(function () {
            if ($(".googleBox").val() == '') {
                $(".googleBox").removeClass('GoogleBoxBackground');
            }
        });

        $(".googleBox").blur(function () {
            if ($(".googleBox").val() == '') {
                $(".googleBox").addClass('GoogleBoxBackground');
            }
        });

        // THIS IS FOR THE MODULES AT THE BOTTOM OF EVERY PAGE
        var moduleHeight = 0;
        $('#cSplashModules li').each(function () {
            if ($(this).height() > moduleHeight) {
                moduleHeight = $(this).height();
            }
        });

        moduleHeight += 10;
        $('#cSplashModules li').css("height", moduleHeight);
        //$('#cSplashModules a.viewAll').css({ 'position': 'absolute', 'top': moduleHeight - 15 + 'px' });
        $('#cSplashModules a.viewAll').css({ 'position': 'absolute', 'bottom': '0', 'left':'0' });

        $(".SubHeaderCHA").css({ "font-size": "18px", "font-family": "tahoma" });

    });
})(jQuery);                     // Passing it as the param 
