(function ($) { // encapsulated $
    $(function () { // Dom Ready Shortcut

        if ($.browser.msie == true) {
            var back_x = $('#cHeader .logo').css('background-position-x'),
				back_y = $('#cHeader .logo').css('background-position-y'),
				back_position = back_x + " " + back_y;
        } else {
            var back_position = $('#cHeader .logo').css('background-position');
        }

        if ($('#cHeader .logo').length != 0) {

            var back_image = $('#cHeader .logo').css('background-image'),
			width = $('#cHeader .logo').width(),
			height = $('#cHeader .logo').height(),
			index1 = back_image.indexOf('http'),
			index2 = back_image.indexOf('.jpg');

            back_position = back_position.split(" ");
            back_image = back_image.substring(index1, (index2 + 4));

            $('#cHeader .left').append('<div class="printLogo" style="height:53px; width: 650px; overflow: hidden;"><img src="' + back_image + '" width="650"/></div>');
            //$('#cHeader .left .printLogo').css('width', width).css('height', height).css('overflow', 'hidden');

            $('#cHeader .left .printLogo img')
			.css('margin-left', back_position[0])
			.css('margin-top', back_position[1]);

        }
        //FOR THE ACTIVE STATE ON THE CRAYON NAV
        $('#crayonSubNav a#groupPurchasing').addClass('inactive');
        $('#crayonSubNav div#groupPurchasing').css({ 'display': 'none' })
        $('#crayonSubNav a#oncology').addClass('inactive');
        $('#crayonSubNav div#oncology').css({ 'display': 'none' })
        $('#crayonSubNav a#pension').addClass('inactive');
        $('#crayonSubNav div#pension').css({ 'display': 'none' })
        $('#crayonSubNav a#unemployment').addClass('inactive');
        $('#crayonSubNav div#unemployment').css({ 'display': 'none' })
        $('#crayonSubNav a#investments').addClass('inactive');
        $('#crayonSubNav div#investments').css({ 'display': 'none' })

        if ($('#cContainer').hasClass("groupPurchasing")) {
            $('#crayonSubNav a#groupPurchasing').removeClass('inactive');
            $('#crayonSubNav a#groupPurchasing').addClass('active');
            $('#crayonSubNav div#groupPurchasing9').css({ 'display': 'block' })
        }

        if ($('#cContainer').hasClass("oncology")) {
            $('#crayonSubNav a#oncology').removeClass('inactive');
            $('#crayonSubNav a#oncology').addClass('active');
            $('#crayonSubNav div#oncology9').css({ 'display': 'block' })
        }

        if ($('#cContainer').hasClass("pension")) {
            $('#crayonSubNav a#pension').removeClass('inactive');
            $('#crayonSubNav a#pension').addClass('active');
            $('#crayonSubNav div#pension9').css({ 'display': 'block' })
        }

        if ($('#cContainer').hasClass("unemployment")) {
            $('#crayonSubNav a#unemployment').removeClass('inactive');
            $('#crayonSubNav a#unemployment').addClass('active');
            $('#crayonSubNav div#unemployment9').css({ 'display': 'block' })
        }

        if ($('#cContainer').hasClass("investments")) {
            $('#crayonSubNav a#investments').removeClass('inactive');
            $('#crayonSubNav a#investments').addClass('active');
            $('#crayonSubNav div#investments9').css({ 'display': 'block' })
        }

        $(".SearchBox").css({ "border": "0" });

        // CRAYON NAVIGATION
        //----------------------------------------------------------------------------------------------------------//

        //        //if ($("#cSplashBanner #crayonNav a#groupPurchasing").hasClass("inactive")) {
        //        $("#cSplashBanner #crayonNav a#groupPurchasing").css({ "background-position": "-332px 0" });
        //        // }

        //        // if ($("#cSplashBanner #crayonNav a#oncology").hasClass("inactive")) {
        //        $("#cSplashBanner #crayonNav a#oncology").css({ "background-position": "-332px -99px" });
        //        // }

        //        //if ($("#cSplashBanner #crayonNav a#pension").hasClass("inactive")) {
        //        $("#cSplashBanner #crayonNav a#pension").css({ "background-position": "-332px -202px" });
        //        //}

        //        // if ($("#cSplashBanner #crayonNav a#unemployment").hasClass("inactive")) {
        //        $("#cSplashBanner #crayonNav a#unemployment").css({ "background-position": "-332px -305px" });
        //        // }

        //        $("#cSplashBanner #crayonNav a").hover(
        //		function () {

        //		    $("#defaultPanel").fadeOut("fast");

        //		    if ($(this).siblings("a").hasClass("inactive") == false) {
        //		        $(this).siblings("a").toggleClass("inactive");
        //		    }

        //		    if ($(this).hasClass("active") == false) {
        //		        $(this).toggleClass("active");
        //		    }

        //		    $(this).siblings("a").removeClass("active");


        //		    // GROUP PURCHASING
        //		    if ($("#cSplashBanner #crayonNav a#groupPurchasing").hasClass("active") == false) {
        //		        $("#cSplashBanner #crayonNav a#groupPurchasing").css({ "background-position": "-332px 0" });
        //		        $("#groupPurchasingPanel").fadeOut("fast");
        //		    }
        //		    else {
        //		        $("#cSplashBanner #crayonNav a#groupPurchasing").css({ "background-position": "-1px 0" });
        //		        $("#groupPurchasingPanel").fadeIn("fast");
        //		    }

        //		    // ONCOLOGY
        //		    if ($("#cSplashBanner #crayonNav a#oncology").hasClass("active") == false) {
        //		        $("#cSplashBanner #crayonNav a#oncology").css({ "background-position": "-332px -99px" });
        //		        $("#oncologyPanel").fadeOut("fast");
        //		    }
        //		    else {
        //		        $("#cSplashBanner #crayonNav a#oncology").css({ "background-position": "-1px -99px" });
        //		        $("#oncologyPanel").fadeIn("fast");
        //		    }

        //		    // PENSIONS
        //		    if ($("#cSplashBanner #crayonNav a#pension").hasClass("active") == false) {
        //		        $("#cSplashBanner #crayonNav a#pension").css({ "background-position": "-332px -202px" });
        //		        $("#pensionPanel").fadeOut("fast");
        //		    }
        //		    else {
        //		        $("#cSplashBanner #crayonNav a#pension").css({ "background-position": "-1px -202px" });
        //		        $("#pensionPanel").fadeIn("fast");
        //		    }

        //		    // UNEMPLOYMENT
        //		    if ($("#cSplashBanner #crayonNav a#unemployment").hasClass("active") == false) {
        //		        $("#cSplashBanner #crayonNav a#unemployment").css({ "background-position": "-332px -305px" });
        //		        $("#unemploymentPanel").fadeOut("fast");
        //		    }
        //		    else {
        //		        $("#cSplashBanner #crayonNav a#unemployment").css({ "background-position": "-1px -305px" });
        //		        $("#unemploymentPanel").fadeIn("fast");
        //		    }
        //		});


        //        $('#cSplashBanner').mouseleave(function () {
        //            $("#defaultPanel").fadeIn("fast");
        //            $("#cSplashBanner #crayonNav a#groupPurchasing").css({ "background-position": "-332px 0" });
        //            $("#cSplashBanner #crayonNav a#oncology").css({ "background-position": "-332px -99px" });
        //            $("#cSplashBanner #crayonNav a#pension").css({ "background-position": "-332px -202px" });
        //            $("#cSplashBanner #crayonNav a#unemployment").css({ "background-position": "-332px -305px" });
        //        });

        // Report Viewer modal
        //----------------------------------------------------------------------------------------------------------//
        $(".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")
            });
        });


        // Secure file link
        //----------------------------------------------------------------------------------------------------------//
        //        $("a.securedFileLink").mouseover(function () {
        //            $(this).click(function (e) {
        //                e.preventDefault();
        //                $.ajax({
        //                    url: '/layouts/champs/securefileprocessor.aspx',
        //                    data: 'file=' + $(this).attr("href"),
        //                    success: function(result){
        //                        document.write(result);
        //                    }
        //                });
        //            });
        //        });

        $("a.securedFileLink").mouseover(function () {
            $(this).click(function (e) {
                e.preventDefault();
                $.download('/layouts/champs/securefileprocessor.aspx', 'file=' + $(this).attr("href"));
            });
        });



        //        $("a.securedFileLink").append('<form id="MyForm"></form>');
        //        $("a.securedFileLink").mouseover(function () {
        //            $(this).click(function(e) { e.preventDefault(); $("#MyForm").attr( { action : '/layouts/champs/securefileprocessor.aspx?test=champseventsexport' }).submit(); }); 
        //        });

        // 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).width() + 10;
                //alert(groupWidth);
                if ($(this).height() > groupHeight) {
                    groupHeight = $(this).height();
                }
            });

            $(this).css({ "width": groupWidth });
            $(this).find(".group").css({ "height": groupHeight });

            groupWidth = 40;
            groupHeight = 0;
        });

        $("#cNavigation > ul > li > ul").css({ "visibility": "visible", "display": "none" });


        $("#cNavigation ul > li > ul > li").eq(0).hover(
		function () {
		    $(this).parents("li.groupPurchases").find(".arrow").css({ "display": "block" });
		},
		function () {
		    $(this).parents("li.groupPurchases").find(".arrow").css({ "display": "none" });
		}
	);

        $("#cNavigation ul > li > ul > li").eq(1).hover(
		function () {
		    $(this).parents("li.oncology").find(".arrow").css({ "display": "block" });
		},
		function () {
		    $(this).parents("li.oncology").find(".arrow").css({ "display": "none" });
		}
	);

        $("#cNavigation ul > li > ul > li").eq(2).hover(
		function () {
		    $(this).parents("li.pension").find(".arrow").css({ "display": "block" });
		},
		function () {
		    $(this).parents("li.pension").find(".arrow").css({ "display": "none" });
		}
	);

        $("#cNavigation ul > li > ul > li").eq(3).hover(
		function () {
		    $(this).parents("li.unemployment").find(".arrow").css({ "display": "block" });
		},
		function () {
		    $(this).parents("li.unemployment").find(".arrow").css({ "display": "none" });
		}
	);

        //		$("#cNavigation ul > li > ul > li").eq(4).hover(
        //		function () {
        //		    $(this).parents("li.investments").find(".arrow").css({ "display": "block" });
        //		},
        //		function () {
        //		    $(this).parents("li.investments").find(".arrow").css({ "display": "none" });
        //		}
        //	);

        $("#cNavigation ul > li:eq(0)").hover(
		function () {
		    $(this).find(".arrow").css({ "background": "url('/images/buttons_SPRITE.png') no-repeat 0px 0px", "display": "block" });
		},
		function () {
		    $(this).find(".arrow").css({ "display": "none" });
		}
	);

        $("#cNavigation ul > li:eq(1)").hover(
		function () {
		    $(this).find(".arrow").css({ "background": "url('/images/buttons_SPRITE.png') no-repeat -28px 0px", "display": "block" });
		},
		function () {
		    $(this).find(".arrow").css({ "display": "none" });
		}
	);

        $("#cNavigation ul > li:eq(2)").hover(
		function () {
		    $(this).find(".arrow").css({ "background": "url('/images/buttons_SPRITE.png') no-repeat -56px 0px", "display": "block" });
		},
		function () {
		    $(this).find(".arrow").css({ "display": "none" });
		}
	);

        $("#cNavigation ul > li:eq(3)").hover(
		function () {
		    $(this).find(".arrow").css({ "background": "url('/images/buttons_SPRITE.png') no-repeat -84px 0px", "display": "block" });
		},
		function () {
		    $(this).find(".arrow").css({ "display": "none" });
		}
	);

        //		$("#cNavigation ul > li:eq(4)").hover(
        //		function () {
        //		    $(this).find(".arrow").css({ "background": "url('/images/buttons_SPRITE.png') no-repeat -84px 0px", "display": "block" });
        //		},
        //		function () {
        //		    $(this).find(".arrow").css({ "display": "none" });
        //		}
        //	);

        // ARROW
        //----------------------------------------------------------------------------------------------------------//

        $(".arrow").each(function () {
            var width = $(this).parent("span").width();
            width = Math.round((width / 2) + 4);

            $(this).css({ "left": width });
        });

        // 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 });
            }
        }

        // 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" });


        // SUB PAGE NAVIGATION
        //----------------------------------------------------------------------------------------------------------//
        if ($("#crayonSubNav a#groupPurchasing").hasClass("inactive")) {
            $("#crayonSubNav a#groupPurchasing").css({ "background-position": "0 -295px" });
        }
        else {
            $("#crayonSubNav a#groupPurchasing").css({ "background-position": "0 -590px" });
        }

        if ($("#crayonSubNav a#oncology").hasClass("inactive")) {
            $("#crayonSubNav a#oncology").css({ "background-position": "0 -370px" });
        }
        else {
            $("#crayonSubNav a#oncology").css({ "background-position": "0 -664px" });
        }

        if ($("#crayonSubNav a#pension").hasClass("inactive")) {
            $("#crayonSubNav a#pension").css({ "background-position": "0 -445px" });
        }
        else {
            $("#crayonSubNav a#pension").css({ "background-position": "0 -740px" });
        }

        if ($("#crayonSubNav a#unemployment").hasClass("inactive")) {
            $("#crayonSubNav a#unemployment").css({ "background-position": "0 -520px" });
        }
        else {
            $("#crayonSubNav a#unemployment").css({ "background-position": "0 -815px" });
        }

        if ($("#crayonSubNav a#investments").hasClass("inactive")) {
            $("#crayonSubNav a#investments").css({ "background-position": "0 -520px" });
        }
        else {
            $("#crayonSubNav a#investments").css({ "background-position": "0 -815px" });
        }


        $("#crayonSubNav a#groupPurchasing").hover(
		function () {
		    if ($(this).hasClass("inactive")) {
		        $("#crayonSubNav a#groupPurchasing").css({ "background-position": "0 0" });
		    }
		    else if ($("#crayonSubNav a#groupPurchasing").hasClass("active") == false) {
		        $("#crayonSubNav a#groupPurchasing").css({ "background-position": "0 -590px" });
		    }
		},
		function () {
		    if ($(this).hasClass("inactive")) {
		        $("#crayonSubNav a#groupPurchasing").css({ "background-position": "0 -295px" });
		    }
		    else {
		        $("#crayonSubNav a#groupPurchasing").css({ "background-position": "0 -590px" });
		    }
		}
	);


        $("#crayonSubNav a#oncology").hover(
		function () {

		    if ($(this).hasClass("inactive")) {
		        $("#crayonSubNav a#oncology").css({ "background-position": "0 -75px" });
		    }
		    else if ($("#crayonSubNav a#oncology").hasClass("active") == false) {
		        $("#crayonSubNav a#oncology").css({ "background-position": "0 -664px" });
		    }
		},
		function () {
		    if ($("#crayonSubNav a#oncology").hasClass("inactive")) {
		        $("#crayonSubNav a#oncology").css({ "background-position": "0 -370px" });
		    }
		    else {
		        $("#crayonSubNav a#oncology").css({ "background-position": "0 -664px" });
		    }
		}
	);


        $("#crayonSubNav a#pension").hover(
		function () {
		    if ($(this).hasClass("inactive")) {
		        $("#crayonSubNav a#pension").css({ "background-position": "0 -150px" });
		    }
		    else if ($("#crayonSubNav a#pension").hasClass("active") == false) {
		        $("#crayonSubNav a#pension").css({ "background-position": "0 -740px" });
		    }
		},
		function () {
		    if ($(this).hasClass("inactive")) {
		        $("#crayonSubNav a#pension").css({ "background-position": "0 -445px" });
		    }
		    else {
		        $("#crayonSubNav a#pension").css({ "background-position": "0 -740px" });
		    }
		}
	);

        $("#crayonSubNav a#unemployment").hover(
		function () {
		    if ($(this).hasClass("inactive")) {
		        $("#crayonSubNav a#unemployment").css({ "background-position": "0 -225px" });
		    }
		    else if ($("#crayonSubNav a#unemployment").hasClass("active") == false) {
		        $("#crayonSubNav a#unemployment").css({ "background-position": "0 -815px" });
		    }
		},
		function () {
		    if ($(this).hasClass("inactive")) {
		        $("#crayonSubNav a#unemployment").css({ "background-position": "0 -520px" });
		    }
		    else {
		        $("#crayonSubNav a#unemployment").css({ "background-position": "0 -815px" });
		    }
		}
	);

        $("#crayonSubNav a#investments").hover(
		function () {
		    if ($(this).hasClass("inactive")) {
		        $("#crayonSubNav a#investments").css({ "background-position": "0 -225px" });
		    }
		    else if ($("#crayonSubNav a#investments").hasClass("active") == false) {
		        $("#crayonSubNav a#investments").css({ "background-position": "0 -520px" });
		    }
		},
		function () {
		    if ($(this).hasClass("inactive")) {
		        $("#crayonSubNav a#investments").css({ "background-position": "0 -520px" });
		    }
		    else {
		        $("#crayonSubNav a#investments").css({ "background-position": "0 -225px" });
		    }
		}
	);

        //	$("#crayonSubNav a").mouseover(function(){
        //		$(this).next("div").slideToggle("fast").siblings("div").slideUp("fast");
        //		$(this).toggleClass("active");
        //		$(this).siblings("a").toggleClass('inactive');	
        //	});

        // 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 ul li ul li").each(function () {
            $(this).not(":last-child").css({ "marginBottom": "20px" });
        });


        $('a.newsroom').attr("href", "/Corporate/Newsroom.aspx")
        $('.groupPurchasing a.newsroom').attr("href", "/Corporate/Newsroom.aspx?cat=GroupPurchasing")
        $('.oncology a.newsroom').attr("href", "/Corporate/Newsroom.aspx?cat=Oncology")
        $('.pension a.newsroom').attr("href", "/Corporate/Newsroom.aspx?cat=Pension")
        $('.unemployment a.newsroom').attr("href", "/Corporate/Newsroom.aspx?cat=UnemploymentCompensation")
        $('.investments a.newsroom').attr("href", "/Corporate/Newsroom.aspx?cat=Investment")
        $('.corporate a.newsroom').attr("href", "/Corporate/Newsroom.aspx")


        //});

        $("#cSubPage .right .rightModule:last").addClass("rightColumnLast");
        $("#cSubPage #LeftColumnItems .LeftColumnItem:last").css("border", "none");

        $("img[align=right]").css("float", "right");


        /*  GOOGLE SEARCH 
        ______________________________________*/

        if ($(".googleBox").val() == '') {
            $(".googleBox").addClass('GoogleBoxBackground');
        }
        else {
            $(".googleBox").removeClass('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 the SPLASH PAGE
        var moduleHeight = 0;
        $('#cNewsEventsCareers li').each(function () {
            if ($(this).height() > moduleHeight) {
                moduleHeight = $(this).height();
            }
        });

        //moduleHeight += 10;
        // $('#cNewsEventsCareers li').css("height", moduleHeight);
        // $('#cNewsEventsCareers a.viewAll').css({ 'position': 'absolute', 'top': moduleHeight - 15 + 'px' });

    });
})(jQuery);            // Passing it as the param 
