//VARS - Globals //////////////////////////////////////////////////////////////////////////


//--Date()
var lastUpDate=new Date(2006,06,22);
lastUpDate = lastUpDate.toLocaleDateString();
lastUpDate = lastUpDate.charAt(0).toUpperCase() + lastUpDate.substring(1);

//document host location
var baseURL="http://"+location.host+"/";

//variáveis para escrita da table do menu
//serão usadas na construção do menu
var strCurrSec,strLema;
      
      //strCurrSec tem o nome da secção corrente para imprimir topo esquerdo da pagina
      strCurrSec="";
      
      //strLema guarda o lema do site , presente em todas as páginas
      strLema="LuzHenriques.com.PT Uma Página ao Serviço da Arte.";
      
  
      
 

//FUNCS//////////////////////////////////////////////////////////////////////////


function CreateSectionMap() {

   var sectionObj = new SecMap();  

   function SecMap(){ 
      var map = new Object();
      var length = 0 ;
      
      //Method Accessors
      this.GetMap = getMap;
      this.AddSection = addSection;
      this.GetSecPath = getSecPath;
      this.GetImgPath = getImgPath;
      this.GetLength = getLength;
      
      //Methods
      function getMap(){
         return map;
      }
      function addSection(name,path,imagepath){
         var pair = new Array();
         
         pair[0]=path;
         pair[1]=imagepath;
         
         map[name] = pair;
         
         length++;
      }
      function getSecPath(name){
         return map[name][0];
      }
      function getImgPath(name){
         return map[name][1];
      }
      function getLength(){
         return length;
      }
   };
   
return sectionObj;
}


function print_navbar()
{
	
	//mapSection
	var mapSection = CreateSectionMap();
	
	mapSection.AddSection("Início","/");
	mapSection.AddSection("Novidades","/novidades/");
	mapSection.AddSection("Galeria Virtual","/galerias/index.html");
	mapSection.AddSection("Eventos","/eventos/index.html");
	mapSection.AddSection("Colecções Particulares","/galerias/ExposicaoPermanente/index.html");
	mapSection.AddSection("Curriculum","/curriculum/");
	mapSection.AddSection("Links","/links/links.htm");
  
   var tr = document.getElementById('navbar');
 
   if(tr) {
      if(tr.hasChildNodes())
         tr.removeChild(tr.firstChild);
         
      var path = location.pathname;
      
      for(var secName in mapSection.GetMap() ) 
      {
         var secPath = mapSection.GetSecPath(secName);
        
         var isCurrSection = false;
         
         var sub = secPath.substr(1); //removes initial slash
         sub = sub.split("/")[0];
         
         if(path.length >= secPath.length){
            isCurrSection = ( path == secPath || path.indexOf(sub) == 1 ) ;
            //alert((path.indexOf(sub) == 1)+" sub : "+sub);
         }
         
         //Menu elements 
         var td=document.createElement("td");
         var a = document.createElement("a");
         var img = document.createElement("img");
         
         //Element properties
         td.height = 22;
         tr.height=td.height; //roww height same as TD
         
         td.valign = "middle";
         td.align="center";
         td.nowrap = true;
         
         a.innerHTML = "&nbsp;" + secName + "&nbsp;";
         
         img.src = mapSection.GetImgPath(secName);
         img.border=0;
         img.hspace = 3;
         
         //checks if is current Section
         if(isCurrSection) {
            
            td.className = "menuTDcurrsection";
            
            a.href = "#";
            a.className = "top-menu-white";
            
           if(mapSection.GetImgPath(secName) && mapSection.GetImgPath(secName)!= "" ) 
               a.insertBefore(img,a.firstChild);
               
           td.appendChild(a);
            
         } else {
            td.className = "menuTD";
            
            td.onmouseover=new Function("flip(this);");
            td.onmouseout=new Function("unflip(this);");
            td.onclick = new Function("location=(this.getElementsByTagName(\"a\")[0]).href");
            
            a.href = secPath;
            a.className = "top-menu";
            
           if(mapSection.GetImgPath(secName) && mapSection.GetImgPath(secName)!= "" ) 
               a.insertBefore(img,a.firstChild);
               
           td.appendChild(a);
            
         }
            tr.appendChild(td);
      } 
         tr.style.visibility="visible";
   }
   
};


//funções que mudam o texto dentro da TD do menu
function flip(element){
   element.className="menuTDrev";
   element.firstChild.style.color="#FFFFFF";
   element.firstChild.style.backgroundColor="#999999"; 
}

function unflip(element){
   element.className="menuTD";
   element.firstChild.style.color="#FFFFFF";
   element.firstChild.style.backgroundColor="#000000"; 
   
}

//função que retorna a string da data por extenso
function translateDate(country)
{
   var mes=new Array();
   
   var date=lastUpDate.split("-");
   var day=date[0];
   var month=date[1];
   var year=date[2];
   var fullDate="";
   
   switch(country)
   {
   case ("pt" || "" || null):
   {
	   mes[1]="Janeiro";
	   mes[2]="Fevereiro";
	   mes[3]="Março";
	   mes[4]="Abril";
	   mes[5]="Maio";
	   mes[6]="Junho";
	   mes[7]="Julho";
	   mes[8]="Agosto";
	   mes[9]="Setembro";
	   mes[10]="Outubro";
	   mes[11]="Novembro";
	   mes[12]="Dezembro";
	   
	   fullDate=day+" de "+mes[parseInt(month)]+" de "+year;
	   break;
   }
   case "en":
   {
	   mes[1]="January";
	   mes[2]="February";
	   mes[3]="March";
	   mes[4]="April";
	   mes[5]="May";
	   mes[6]="June";
	   mes[7]="July";
	   mes[8]="August";
	   mes[9]="September";
	   mes[10]="October";
	   mes[11]="November";
	   mes[12]="December";
	   
	   fullDate=mes[parseInt(month)]+" "+day+" "+year;
	   break;
   }
   }

   return fullDate;

}


 
//função que imprime o nome da secção corrente no canto esquerdo da página
//a variavel é actualizada na chamada de print_top_menu()
function printCurrSecTitle()
{
document.write(strCurrSec); 
};


//Lema ou slogan do site
function printLema()
{
document.write(strLema);
};



//imprime a última actualização do site
function printLastUpdate()
{
	var out="<b><font size='3' color='#000000'>&Uacute;ltima Actualiza&ccedil;&atilde;o do site:&nbsp;</font></b>";
	out=out+lastUpDate;
	
	document.write(out);
};

//imprime a última actualização do site , alterando a côr da font
function printLastUpdateByColor(fontColor, printType) 
{
	var out="<b><font color='"+fontColor+"' face='Verdana, Arial, Helvetica, sans-serif' size='2'>&Uacute;ltima Actualiza&ccedil;&atilde;o do site:&nbsp;</font></b>";
	out=out+lastUpDate;
	
	if(printType)
		document.write(out);
	else 
		return out;
	
};

