// JavaScript Document

window.onload=iniciar;

function iniciar(){
	bannerAleatorio();
	fundoInicio();
	doComands();
}


//Se acrescentarmos mais uma imagem aqui temos de acrescentar mais um quadradinho no html e fazer a respectiva ligação "onclick"
//<div id="escolhaEsquema">
var imagensFundo=new Array();
imagensFundo[0]="url('/imgs/Esquema1.jpg')";
imagensFundo[1]="url('/imgs/Esquema2.jpg')";
imagensFundo[2]="url('/imgs/Esquema3.jpg')";
imagensFundo[3]="url('/imgs/Esquema4.jpg')";

var coresFundo=new Array();
coresFundo[0]="#08171a";
coresFundo[1]="#200d07";
coresFundo[2]="#151b02";
coresFundo[3]="#27272e";


function fundoInicio(){
	if ( document.cookie.match(eval("/" + 'temaEscolhido' + "=/")) ) {
		var valorCookie = document.cookie.replace(eval("/^.*?" + 'temaEscolhido' + "=([^\\s;]*).*$/"), "$1");
	
		document.body.style.background = imagensFundo[valorCookie];
		document.body.style.backgroundColor = coresFundo[valorCookie];
		document.body.style.backgroundPosition = "center top";
		document.body.style.backgroundRepeat = "no-repeat";
	}
	else {
		mudarFundo(0);
	}
}

function mudarFundo(opcao){
		document.body.style.background = imagensFundo[opcao];
		document.body.style.backgroundColor = coresFundo[opcao];
		document.body.style.backgroundPosition = "center top";
		document.body.style.backgroundRepeat = "no-repeat";
		criarCookie('temaEscolhido', opcao, 365);
}


//-------------------------------------------------------------------------------------------------------------------------------------

function bannerAleatorio(){
	
	var banner;
	banner = document.getElementById("fundoTopo");
	
	//para acrescentar mais uma imagem é preciso alterar o numero da funcao Math.round(3*Math.random()) em vez de 3 pomos 4 ou 5 ...
	var num = Math.round(3*Math.random());
	
	//acrescentar mais uma imagem ao array
	var imagensBanner=new Array();
	imagensBanner[0]="url('/imgs/ImagemTopo1.gif')";
	imagensBanner[1]="url('/imgs/ImagemTopo2.gif')";
	imagensBanner[2]="url('/imgs/ImagemTopo3.gif')";
	imagensBanner[3]="url('/imgs/ImagemTopo4.gif')";
	
	banner.style.background = imagensBanner[num];
	banner.style.backgroundPosition = "center";
	banner.style.backgroundRepeat = "no-repeat";
}

//-------------------------------------------------------------------------------------------------------------------------------------

function criarCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function apagarCookie(name) {
	criarCookie(name,"",-1);
}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_setTextOfLayer(objId,x,newText) { //v9.0
  with (document) if (getElementById && ((obj=getElementById(objId))!=null))
    with (obj) innerHTML = unescape(newText);
}

/***********************************************
* Bookmark site script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/
function bookmarksite(title,url){
	if (window.sidebar) // firefox
		window.sidebar.addPanel(title, url, "");
	else if(window.opera && window.print){ // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} 
	else if(document.all)// ie
		window.external.AddFavorite(url, title);
}


///////////////////// post process

var comands = new Array();

function doComands() {
	for ( var i in comands ) {
		eval(comands[i]);
	}
}



//////////////////////

function toggleLayer( boxID ) {
	/* Obtain reference for the selected boxID layer and its button */
	var box = document.getElementById(boxID);
	var boxbtn = document.getElementById("btn_"+boxID);
	
	/* If the selected box is currently invisible, show it */
	if(box.style.display == "none" || box.style.display=="") {
		box.style.display = "block";
 		boxbtn.src = "/imgs/icon_menos.gif";
	}
	/* otherwise hide it */
	else {
		box.style.display = "none";
		boxbtn.src = "/imgs/icon_mais.gif";
	}
}



///////////////////////////

    function showPic(sUrl,layr){ 
     /*var x,y; 
     x = evt.clientX; 
     y = evt.clientY;
		 
     document.getElementById("Layer1").style.left = x; 
     document.getElementById("Layer1").style.top = y; */
     document.getElementById('Layer0').innerHTML = "<img src=\"" + sUrl + "\">"; 
     document.getElementById('Layer0').style.display = "block"; 
    } 
	
    function hiddenPic(layr){ 
     document.getElementById('Layer0').innerHTML = ""; 
     document.getElementById('Layer0').style.display = "none"; 
    } 




//////////////////////////////////////////////////////////

var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;
var tempX = 0;
var tempY = 0;

function getMouseXY(e) {
	if (IE) { // grab the x-y pos.s if browser is IE
		tempX = event.clientX + document.body.scrollLeft;
		tempY = event.clientY + document.body.scrollTop;
	}
	else {  // grab the x-y pos.s if browser is NS
		tempX = e.pageX;
		tempY = e.pageY;
	}  

tempX += 10;
tempY -= 200;

	if (tempX < 0){tempX = 0;}
	if (tempY < 0){tempY = 0;}
	
	//alert(tempX+'x'+tempY);
	//document.Show.MouseX.value = tempX;
	//document.Show.MouseY.value = tempY;
  document.getElementById("Layer0").style.left = tempX+'px'; 
  document.getElementById("Layer0").style.top = tempY+'px';

	return true;
}// */

