define(function(require){
	var $ = require('jquery');
	var IFA = require('util'); 
	var contextPath = $('#contextPath').val();
	require('uriTemplate')($);
	require('validation')($);
	require('dialog')($);
	require('cookie')($);
	require("../../../styles/cim/jquery-ui-1.8.14.custom.css");
	require('../../../styles/cim/validation.css');

		//顶部按钮显示
		  var url = "topMenu.do";
		  $.ajax({
				type:"get",
				url : url,
				success:function(response) {
			      var topmenu =response.menuList; 
			  	   if(topmenu){
				    $.each( topmenu,function(i,authority){
					    	var a = $('<a href="#"></a>');
					    	a.attr("id",authority.code);
					    	a.attr("data",authority.topMenu);
					    	a.html(i18n[authority.name]);
					    	a.bind("click",{id:authority.code},show);
			                $('#topmenu').append(a);
					});
				    initFirstLeftMenu();
			  	   }else{
			  		   var url = $("#loginUrl").val();
			  		   location.href = url;
			  	   }
				}
			});
			
		  
				

//topMenu的切换
		function show(event)
		{    
			$('#topmenu a').each(function(i,sub)
					{
				       $(sub).removeClass('topfocus');
			});
			var param = event.data.id;
			$('#'+param).addClass('topfocus');
		    var hiddenUrl = $('#menuShowByRemarkUrl').val();
			var urlStr =  new $.Template(hiddenUrl); 
		 	var urlParam = {"topId":param};
		  	var url = urlStr.expand(urlParam);
			  $.ajax({
					type:"get",
					url : url+".json",
					success:function(response) {
				    $('#leftMenu').empty();
					$.each(response.menuList,function(i,node){
						  if(node.url !='#'&& node.url !='N'){
						         var li = $('<li class ="level1" ></li>');
						         var a = $('<a href='+contextPath+node.url+' id="'+node.name+'"></a>');
						         a.html(i18n[node.name]);
//						         a.bind('click',function(){
//						        	 location.replace(contextPath+node.url);
//							         });
						         a.appendTo(li);
						         $('#leftMenu').append(li);
						  }
				  		});  
			  }
			  });
			  showLeftMenu();
		  	}
		
		function showLeftMenu(){
			var sideBar	= $("#sideBarCon");
			if(sideBar.css("display")=="none"){
				var tbodyCon = $("#tbodyCon");
				var switchImage = $("#switchImage");
				sideBar.show();
				tbodyCon.css("padding-left","200px");
				switchImage.attr("src",seajs.contextPath+"/images/btn_arrow01.gif");
				document.cookie="hidebar=false; path=/";
			}
		}
		
		function getNightserviceStatus(){
			if(document.getElementById("nightserviceStatus")==null){
				return false;
			}
			var url = $('#nightServiceUpdateUrl').val();
			$.get(url+'.json',null,
				function(response){
					serviceStatus=response.newStatus;
					document.getElementById("nightserviceStatus").innerHTML=response.currentStatus;
			});
		}
		function changeStatus(){
			if(document.getElementById("nightserviceStatus")==null){
				return false;
			}
			var str =i18n['Page.changeToNormal'];
			if(serviceStatus=="ON"){
				str =i18n['Page.changeToNightservice'];
			}
			$.msg.confirm(i18n['Page.Dialog.title'],str,function(result){
				if(result)
					{
					var jsonData={"nightserviceStatus":serviceStatus,'_method':'PUT'};
					var url = $('#nightServiceUpdateUrl').val();
					$.ajax({url:url+'.json',type:'post',data:jsonData,
							success:function(response){ 
								serviceStatus=response.newStatus;
								document.getElementById("nightserviceStatus").innerHTML=response.currentStatus;
					}});				
					}
				
			});

		}
		
});