// JavaScript Document
	$(document).ready(function(){ 		
		$('div.vertical').bind('click',function(){
			var $next = $(this).next();
  			if ($next.is(':visible')){
				$(this).parent().parent().find('div.menuSlide').slideUp('slow');
			} else {
 				$(this).parent().parent().find('div.menuSlide').slideUp('slow');
  				$next.slideDown('slow');
			}  
  			return false;
		});
		
		/*$('div.grupo').bind('click',function() {
  			var $next = $(this).next();
  			if ($next.is(':visible')){
	 			$(this).parent().parent().find('div.subgrupo').slideUp('slow');
			} else {
 				$(this).parent().parent().find('div.subgrupo').slideUp('slow');
				$next.slideDown('slow');
			}  
  		return false;
		});*/

		//fecha subGrupos ao clicar no menu principal
		$("div.vertical").click(function (){ 
  			$("img.state1").css("display","inline");
			$("img.state2").css("display","none");
			$(this).parent().parent().find('div.subgrupo').slideUp('slow'); 
   		}); 
	
		//fecha subGrupos ao clicar no grupo1
		$("div.grupo1").click(function (){ 
    		$(this).parent().parent().find('div.subgrupo').slideUp('slow');
		}); 
	}); 
	var idAnt1 = '0';
	var	idAnt2 = '0';
	var	idMenuAnt = '0';
	var loadLoja  = '0';


	
	function state(id1, id2, idMenu){
		if(navigator.appName == "Microsoft Internet Explorer") {
			//alert('ie');
			stateIE(id1, id2, idMenu);
		} else {
			//alert('FF');	
			stateFirefox(id1, id2, idMenu);
		}
	}
	
	function stateIE(id1, id2, idMenu){
		
		if (id1 != idAnt1){ 
			if(idAnt1 != '0'){
				document.getElementById(idAnt1).style.display= "inline";
				document.getElementById(idAnt2).style.display= "none";
			}
			
			if (document.getElementById(id1).style.display == "inline"){
				document.getElementById(id2).style.display= "inline";
				document.getElementById(id1).style.display= "none";
					
			} else if (document.getElementById(id2).style.display == "inline"){
				//alert('2');
				document.getElementById(id2).style.display= "none";
				document.getElementById(id1).style.display= "inline";
				
			}
			
			idAnt1 = id1; 
			idAnt2 = id2;
			//idMenuAnt = idMenu;
		}else{
			if (document.getElementById(id1).style.display == "inline"){
				//alert('3');
				document.getElementById(id2).style.display= "inline";
				document.getElementById(id1).style.display= "none";
			} else if (document.getElementById(id2).style.display == "inline"){
				//alert('4');
				$('div.grupo').parent().parent().find('div.subgrupo').slideUp('slow');
				document.getElementById(id2).style.display= "none";
				document.getElementById(id1).style.display= "inline";
									
			}
		}
	
		$('div.grupo').bind('click',function() {
  			var $next = $(this).next();
  			if (!$next.is(':visible')){
				$(this).parent().parent().find('div.subgrupo').slideUp('slow');
				$next.slideDown('slow');
			}  
  			return false;
		});
		
	}
	
	function stateFirefox(id1, id2, idMenu){
		
		if (id1 != idAnt1){ 
			if(idAnt1 != '0'){
				document.getElementById(idAnt1).style.display= "inline";
				document.getElementById(idAnt2).style.display= "none";
			}
			
			if (document.getElementById(id1).style.display == "inline"){
				//alert(idAnt1);
				document.getElementById(id2).style.display= "inline";
				document.getElementById(id1).style.display= "none";
				if (idAnt1 == '0') 
					$('#'+idMenu+'').slideDown('slow');
				if (idMenuAnt != '0' && loadLoja =='0' ){
					$('#'+idMenuAnt+'').slideUp('slow');
					$('#'+idMenu+'').slideDown('slow');
					loadLoja = '1';
				}
				
			} else if (document.getElementById(id2).style.display == "inline"){
				//alert('2');
				document.getElementById(id2).style.display= "none";
				document.getElementById(id1).style.display= "inline";
				
			}
			
			idAnt1 = id1; 
			idAnt2 = id2;
			//idMenuAnt = idMenu;
		}else{
			if (document.getElementById(id1).style.display == "inline"){
				//alert('3');
				document.getElementById(id2).style.display= "inline";
				document.getElementById(id1).style.display= "none";
			} else if (document.getElementById(id2).style.display == "inline"){
				//alert('4');
				$('div.grupo').parent().parent().find('div.subgrupo').slideUp('slow');
				document.getElementById(id2).style.display= "none";
				document.getElementById(id1).style.display= "inline";
									
			}
		}
	
		$('div.grupo').bind('click',function() {
  			var $next = $(this).next();
  			if (!$next.is(':visible')){
				$(this).parent().parent().find('div.subgrupo').slideUp('slow');
				$next.slideDown('slow');
			}  
  			return false;
		});
		
	}

	function carregando(){        

		var msg;
		

			msg = "<div class='grupo' style='display:inline;'><a href='#'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src='img/space.gif' alt='#' /><img src='img/ajax-loader.gif' alt='#' /></a></div>";
		 
		return msg;
	}
	
	var ID_LOCAL = 'INICIO';
	function openMenuGrupo(url, idLocal, tipo){
		if (idLocal != ID_LOCAL){
			idAnt1='0'; 
			ajaxBusca(url, idLocal, tipo);
			ID_LOCAL= idLocal;
		}		
	}
	
	function ajaxBusca (url, idLocal, tipo){
		var resultadoAjax = document.getElementById(idLocal); 
		var ajax;
		
		if(navigator.appName == "Microsoft Internet Explorer") {
			ajax = new ActiveXObject("Microsoft.XMLHTTP");
		} else {
			ajax = new XMLHttpRequest();
		}
		 
		ajax.open("GET", url, true );     
		 
		ajax.onreadystatechange = function(){        
			if (ajax.readyState==1){
				resultadoAjax.innerHTML = carregando();
			}
			if(ajax.readyState==4){            
				if(ajax.status==200){                
					var recebeDadosDoSelect = ajax.responseText;                
			 		resultadoAjax.innerHTML = recebeDadosDoSelect;  
				}                        
			}    
		}    
		ajax.send(null);
	}