var myNavigator = new Component("navigator");
app.registerComponent(myNavigator);
myNavigator.isClicking = false;
myNavigator.on("load", function(){ 
	$("#masterMenuLoading_sidebarheader").show();
    $("#masterMenuLoading").css("height","50px");
    this.showLoading("masterMenuLoading");
    return myNavigator.render(
    		'template/navigator.html', 
    		'masterMenu2', 
    		{}
    ).done(function(){
    	$("#masterMenuLoading_sidebarheader").hide();
        $("#masterMenuLoading").css("height","0px");
        $("#loadingDiv").empty().remove();
		app.user.role.checkHtmlElements();
		//app.user.role.checkPortfolioRole();
		
		$(".menu dt").die().live("click",function(){
			var id = $(this).find("a").attr("cid"),
				eventid = $(this).find("a").attr("eventid");
			app.trigger('menuClick', $(this).find("a").attr("cid"), this, eventid || "load");

		});
		
		$("[loadAnnouncements]").on("resolve",function(){
			app.loadScriptsById("announcement");
		});
	    $("#contactUs").live("click", function(){
	    	trackAction("ContactUs - View");
	    	ajaxCall({url: app.EPWEB_CONTEXT_ROOT + "contactUs.html" , dataType:"html"}, true)
	    	.done( function(data) {
	    		dialog.set({
	        		header: lang.getMessage('titlePopupContactUs'),
	        		height: "190px",
	        		width: "400px"
	        	}).show(data);	    		
	    	});
	    	/*dialog.set({
        		header: "ContactUs",
        		height: "190px",
        		width: "400px"
        	}).show();    	
        	$("#alertMsgContainer").load("/WMD/ePlatform/contactUs.html");*/
	    });
		$('#demoLink').click(function(){
			window.open('/WMD/ePlatform/tour/','siteTour','directories=no,titlebar=no,toolbar=no,location=no,status=no,menubar=no,resizable=yes,width=1028,height=790');
		});
		$('#managerUserGroup').click(function(){
			var url = app.MANAGER_USERID_URL;
			window.open(url);
			//window.open('/technology/entitlement/administration/folder.jsf?folderId=%2FNef%2FWMD%2F');
		});
	});
});


myNavigator.select = function(menu){
	if ( myNavigator.selected ){
		myNavigator.selected.find("a").toggleClass("selected");
	}
	$(menu).find("a").toggleClass("selected");
	myNavigator.selected = $(menu);
};
//navigator.on("reloadNavigator", function(){
//    $("#psubmenu dt").each(function(){
//        $(this).hide(); 
//    });
//    var bekey = "";
//    if($.isArray(app.user.bpKey)) {
//        bykey = app.selectBpKey;
//    }else {
//        bykey = app.user.bpKey;
//    }
//    var asofdate = app.selectDateValue;
//    var url = "businessPartners/menu/" + bykey + "?asOfDate=" + asofdate;
//    ajaxCall({ url: app.EPRESTAPI_CONTEXT_ROOT + url, dataType: "json"}, false).done(function(data){
//        $("#psubmenu dt").each(function(i,d){
//            var text = $(d).find("div[class=linktext]").text(),
//                role = $(d).attr("WMD_Role");
//            if($.isArray(data.data.result) && data.data.result.indexOf(text)!= -1 && app.user.role.checkRole(role)){
//               $(d).show();  
//            } 
//        });
//    });
//});




