
	/**
	 * Retorna objeto de XMLHttpReuqest de acordo com o browser,
	 * ou retorna falso caso o browser nao suporte.
	 */
	function getXmlhttp(){
		try{
		    xmlhttp = new XMLHttpRequest();
		}catch(ee){
		    try{
		        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		    }catch(e){
		        try{
		            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		        }catch(E){
		            xmlhttp = false;
		        }
		    }
		}
		return xmlhttp;
	}

	/**
	 * Recupera o conteudo da pagina especificada, atualiza menu e topo (se necesséario),
	 * e atualiza o bg e conteudo de acordo com o objeto recuperado.
	 */
	function setContain(menu){
        var contain = document.getElementById("contain");
        contain.innerHTML='<div class="loading">loading...</div>';
        
        var containBg 	= document.getElementById("containBg");
        //var topLeft 		= document.getElementById("topLeft");
        //var topRight 		= document.getElementById("topRight");
        //var imgTop		= document.getElementById("imgTop");

        //var topLeftValue 		= "topLeftMain";
        //var topRightValue 	= "topRightMain";
        //var imgTopValue		= "../imgs/img_main.jpg";
        pg = "";
        switch (menu){
        	case "home":
        		pg = "../index/home.php";
        		containBg.setAttribute("class","guitarContainBg");
        		break;
        	case "history":
        		pg = "../history/index.php";
        		containBg.setAttribute("class","peopleContainBg");
        		break;
        	case "press" :
        		pg = "../press/index.php";
        		containBg.setAttribute("class","peopleContainBg");
        		break;
        	case "lyrics" :
        		pg = "../lyrics/index.php";
        		containBg.setAttribute("class","guitarContainBg");
						//topLeftValue 	= "topLeftLiberty";
						//topRightValue 	= "topRightLiberty";
						//imgTopValue		= "../imgs/img_liberty.jpg";
        		break;
        	case "media" :
        		pg = "../media/index.php";
        		containBg.setAttribute("class","playingContainBg");
        		break;
        	case "gallery" :
        		pg = "../gallery/index.php";
        		containBg.setAttribute("class","playingContainBg");
        		break;
        	case "support" :
        		pg = "../support/index.php";
        		containBg.setAttribute("class","playingContainBg");
        		break;
        	case "links" :
        		pg = "../links/index.php";
        		containBg.setAttribute("class","playingContainBg");
        		break;
        	case "contact" :
        		pg = "../contact/index.php";
        		containBg.setAttribute("class","guitarContainBg");
        		break;
        	case "merch" :
        		pg = "../merch/index.php";
        		containBg.setAttribute("class","playingContainBg");
        		break;
        }
    		//topLeft.setAttribute("class",topLeftValue);
    		//topRight.setAttribute("class",topRightValue);
    		//imgTop.setAttribute("src",imgTopValue);
	    //Abre a url
	    xmlhttp = getXmlhttp();
	    xmlhttp.open("GET", pg,true);
	
	    //Executada quando o navegador obtiver o código
	    xmlhttp.onreadystatechange=function() {
	
	        if (xmlhttp.readyState==4){
	
	            //Lê o texto
	            var texto=xmlhttp.responseText;
	
	            //Desfaz o urlencode
	            texto=texto.replace(/\+/g," ");
	            texto=unescape(texto);
	            //Exibe o texto no div conteúdo
	            contain.innerHTML=texto;
	            makeMenu(menu);
	            if(menu == "lyrics") lyricNova(1);
	        }
	    }
	    xmlhttp.send(null)
	}
	
	/** Set HOME paging */
	function setHomePaging(sub){
      var contain = document.getElementById("contain");
      contain.innerHTML='<div class="loading">loading...</div>';
    	pg = "../index/home.php?sub="+sub;
	    xmlhttp = getXmlhttp();
	    xmlhttp.open("GET", pg,true);
	
	    //Executada quando o navegador obtiver o código
	    xmlhttp.onreadystatechange=function() {
	
	        if (xmlhttp.readyState==4){
	
	            //Lê o texto
	            var texto=xmlhttp.responseText;
	
	            //Desfaz o urlencode
	            texto=texto.replace(/\+/g," ");
	            texto=unescape(texto);
	            //Exibe o texto no div conteúdo
	            contain.innerHTML=texto;
	        }
	    }
	    xmlhttp.send(null)
	}
	
	function makeMenu(m){
        	var i=0; var n=8; var e=null;
        	var menuList = new Array(n);
        	menuList[i++] = "home";
        	menuList[i++] = "history";
        	menuList[i++] = "press";
        	menuList[i++] = "lyrics";
        	menuList[i++] = "gallery";
        	menuList[i++] = "links";
        	menuList[i++] = "contact";
        	menuList[i++] = "merch";
		for(i=0;i<n;i++){
			e = document.getElementById(menuList[i]);
			if(e==null) alert(menuList[i]);
			e.src = '../imgs/menu/m_'+menuList[i]+'.png';
			e.onmouseout = MM_swapImgRestore;
			e = null;
		}
		var mItem = document.getElementById(m);
		mItem.src = '../imgs/menu/over_m_'+m+'.png';
		mItem.onmouseout = "";
	}

	function lyric(i,lyricDiv,folder){
        var contain = document.getElementById(lyricDiv);
        contain.innerHTML='loading...';
	    xmlhttp = getXmlhttp();
	    xmlhttp.open("GET", "../lyrics/functions.php?folder="+folder+"&i="+i,true);
	
	    //Executada quando o navegador obtiver o codigo
	    xmlhttp.onreadystatechange=function() {
	
	        if (xmlhttp.readyState==4){
	
	            //Lê o texto
	            var texto=xmlhttp.responseText;
	
	            //Desfaz o urlencode
	            texto=texto.replace(/\+/g," ");
	            texto=unescape(texto);
	            //Exibe o texto no div conteúdo
	            contain.innerHTML=texto;
	        }
	    }
	    xmlhttp.send(null)
	}
	
	function lyricGa(i){
		lyric(i,'lyricGa','ga');
	}
	function lyricNova(i){
		lyric(i,'lyricGa','nova');
	}

	function setElementContent(eleId,pg){
        var contain = document.getElementById(eleId);
        contain.innerHTML='loading...';
	    xmlhttp = getXmlhttp();
	    xmlhttp.open("GET", "../index/ajax.php?pg="+pg,true);
	
	    //Executada quando o navegador obtiver o codigo
	    xmlhttp.onreadystatechange=function() {
	
	        if (xmlhttp.readyState==4){
	
	            //Lê o texto
	            var texto=xmlhttp.responseText;
	
	            //Desfaz o urlencode
	            texto=texto.replace(/\+/g," ");
	            texto=unescape(texto);
	            //Exibe o texto no div conteúdo
	            contain.innerHTML=texto;
	        }
	    }
	    xmlhttp.send(null)
	}


	/**
	 * Seta evento de clique do menu principal
	 */
	function menuClick(m){
	    setContain(m);
	    return false;
	}

	function init(){
		setContain("home");
	}


