$.noConflict();

jQuery(document).ready(function ($) {

    /***************** MAIN NAVIGATION START ***********************/
    $(".outerListItem .mnContainmentArea").hide();

    $(".outerListItem").hover(
        function () {
            $(this).children("div").children("a").addClass("hover");
            if (inPageEditorMode() == "False")
                $(this).children(".mnContainmentArea").show();
        },
        function () {
            $(this).children("div").children("a").removeClass("hover");
            if (inPageEditorMode() == "False")
                $(this).children(".mnContainmentArea").hide();
        }
    );
	
	// This section is for the Ipad etc. who don't have the hover functionality.
	$(document).bind('click', function(e){
		var $clicked = $(e.target);
		if (!($clicked.is('.outerListItem') || $clicked.parents().is('.outerListItem'))) {
			$(".outerListItem").children("div").children("a").removeClass("hover");
            if (inPageEditorMode() == "False")
                $(".outerListItem").children(".mnContainmentArea").hide();		
		}
	});
		
    $(".innerListItem").hover(
        function () {
            $(this).addClass("hover");
        },
        function () {
            $(this).removeClass("hover");
        }
    );
       

    $("#pipedNavigation li:first").addClass("first");

    $("#pipedNavigation li").hover(
        function () {
            $(this).children("a").addClass("hover");
        },
        function () {
            $(this).children("a").removeClass("hover");
        }
    );

    $("#tabbedNavigation li").not(".selected").hover(
        function () {
            $(this).children("a").addClass("hover");
        },
        function () {
            $(this).children("a").removeClass("hover");
        }
    );

    /***************** MAIN NAVIGATION END ***********************/

    /***************** TOP NAVIGATION START ***********************/

        jQuery(document).ready(function () {

            jQuery("#languageSelector li ul").hide();

            jQuery("#languageSelector li.selector").hover(
                function () {
                    jQuery(this).addClass("hover");
                    jQuery(this).children("ul").show();
                }, function () {
                    jQuery(this).removeClass("hover");
                    jQuery(this).children("ul").hide();
                });

        }); 

    /***************** TOP NAVIGATION END ***********************/

});

// This function is for the Ipad etc. who don't have the hover functionality.
function OpenCloseMenu(element){	   
	var menuStatus = 0;
	if(jQuery(element.parentNode).children("div").children("a").hasClass("hover")){
		menuStatus = 1;
	};
	jQuery("[class='"+element.parentNode.className+"']").each(function() {
		jQuery(this).children("div").children("a").removeClass("hover");
        
		if (inPageEditorMode() == "False"){
			jQuery(this).children(".mnContainmentArea").hide();
		}            
	});
   	if(menuStatus==0){
		jQuery(element.parentNode).children("div").children("a").addClass("hover");
    	if (inPageEditorMode() == "False"){
			jQuery(element.parentNode).children(".mnContainmentArea").show();
		}
	}   
}


function inPageEditorMode() {

    return jQuery("#hfPageEditMode").val();
}
