Menu = {
	xmlObject: "/Util/Xml/MenuPrincipal.xml",
	xslPrincipal: "/Util/Xml/MenuPrincipal.xslt",
	hasChildren: null,
	subMenu: null,
	init: function(e, settings) {
		var matchUrl = window.location.pathname.match(/^\/([a-zA-Z])+/);
		if(null != matchUrl) {
			this.subMenu = matchUrl[0].toLowerCase().replace("/","");
			
		}
		this.loadMenu();
	},
	loadMenu: function() {
		$('#divMenuPrincipal').transform({
			xml: Menu.xmlObject, 
			xsl: Menu.xslPrincipal,
			erro: function() { alert('Ocorreu um erro ao carregar o XML'); },
			success: function() {
				
				
				/*$('#divMenuPrincipal > ul li').click(
					function(e) {
						e.preventDefault();
						if($('.submenu:visible',this).length != 0)
							$('.submenu',this).hide();
						else
							$('.submenu',this).show();
					}
				);*/
				
				if(!Menu.hasChildren) { Menu.acendeMenus(); Menu.changeBackgroundMenu(); }
			}
		});		
		
		
				
	},
	acendeMenus: function() {
		var currentPage = $.browser.msie ? window.location.href : window.location.pathname;

		var principal = $("#divMenuPrincipal ul li a[href="+currentPage+"]").parents("li");
		
		//HOME
		if(principal.length == 0)
			$("#divMenuPrincipal ul li.bemvindo .submenu").css('display','block');
			
				
		principal.each(function() {
			this.className = this.className + 'On';
		});
	},
	
	changeBackgroundMenu: function(){
		var currentPage = $.browser.msie ? window.location.href : window.location.pathname;
			
		var ulMenu = $("#divMenuPrincipal ul li a[href="+currentPage+"]").parent().parent();	
	
		ulMenu.attr('class',currentPage.replace(/-/g,'').replace('.html','').substr(currentPage.lastIndexOf("/")+1));
	}
}
