/** codigo para formulário do contacto directo */
  var color_in = "#000000";
  var color_out = "#86898a";
  var bgcolor_in = "#eeeeee";
  var bgcolor_out = "#cbc5b5";
  
  function active (name, cname_text) {
	doc = document.getElementsByName(name)[0];
	  doc.style.color = color_in;
	  doc.style.backgroundColor = bgcolor_in;
	  if (doc.value == cname_text) {
		doc.value = "";
	  }
  }
  function inactive (name, cname_text) {
	doc = document.getElementsByName(name)[0];
		 doc.style.color = color_out;
	  doc.style.backgroundColor = bgcolor_out;
	  if (doc.value == "") {
		doc.value = cname_text;
	  }
  }
/** acaba codigo para formulário do contacto directo */

var numpics = 5;
var directory ='data/girls_left/';
var picsrc = new Array(numpics)
picsrc[0] = 'girl0.png';
picsrc[1] = 'girl1.png';
picsrc[2] = 'girl2.png';
picsrc[3] = 'girl3.png';
picsrc[4] = 'girl4.png';

/**
 *  Função que escolhe uma imagem aleatória para o div 'left'
 *  A imagem sera sempre diferente da anterior (é guardada uma cookie durante 24h)
 */
function assignRandomGirlLeft() {
  tempNumb = (getCookie("randNumb") == null) ? 0: getCookie("randNumb");
  now = new Date();
  now.setTime(now.getTime() + 24 * 60 * 60 * 1000);
  number = -1;
  do {
	number = Math.floor(Math.random() * numpics);
  } while (tempNumb == number);
  /* fix para IE, se preloading do index.html falha, faz preloading... */
  var imgNew = new Image();
  imgNew.src = directory + picsrc[number]; //preload next image
  /* end fix */
  setCookie("randNumb", number, now);  
  document.getElementById('left').style.background = "url('" + directory + picsrc[number] + "')";
}

function fIn(id) {
  document.getElementById(id).style.background = "white";
  fadeIn(id, 0, 40, 5);
}
function fOut(id) {
  fadeOut(id, 40, 0, 5)
}

	   
function hovIn(id) {
  document.getElementById(id).style.color = "#d4cdc6";
  document.getElementById(id).style.border = "3px solid #4b4b4b";
}

function hovOut(id) {
  document.getElementById(id).style.border = "3px solid #ffffff";
  document.getElementById(id).style.color = "#ffffff";
}

/**
 * Funções que trabalham os dados dos serviços
 */
function loadData(id) {
  document.getElementById("precario").style.display = "block";
  document.getElementById("imagens").style.display = "block";
  document.getElementById("subPageDescrText").style.width = "253px";
  document.getElementById("subPageDescrText").style.height = "70px";
  document.getElementById("subPageDescrText").style.marginTop = "15px";
  document.getElementById("subPageDescrText").style.paddingLeft = "13px";
  document.getElementById("subPageDescrText").style.textAlign = "left";
  document.getElementById("subPageDescrImg").style.display = "block";
  document.getElementById("precario").innerHTML= "Preçario";
  document.getElementById("subPageDescrTitle").innerHTML= nomeserv[id];
  document.getElementById("subPageDescrText").innerHTML= textserv[id];
  document.getElementById("subPageDescrImg").style.backgroundImage = 'url("' + fotoserv[id] + '")';
}

function getPrecario() {
  if (window.document.location.toString().indexOf(separator) != -1) {
    index = window.document.location.toString().indexOf(separator) + separator.length;
    id = window.document.location.toString().substring(index);
    if(document.getElementById("precario").innerHTML == "Preçario") {
	  document.getElementById("subPageDescrText").innerHTML = "";
      document.getElementById("subPageDescrImg").style.display = "none";
	  document.getElementById("subPageDescrText").style.width = "266px";
	  document.getElementById("subPageDescrText").style.height = "160px";
	  document.getElementById("subPageDescrText").style.marginTop = "0px";
	  document.getElementById("subPageDescrText").style.paddingLeft = "0px";
	  document.getElementById("precario").innerHTML= "Descrição";
	  tmp = document.getElementById("subPageDescrText");
	  setTimeout("tmp.innerHTML = precserv[id]",20);
    } else {
	  loadData(id);
    }
  }
}

function getImages () {
  if (window.document.location.toString().indexOf(separator) != -1) {
    index = window.document.location.toString().indexOf(separator) + separator.length;
    id = window.document.location.toString().substring(index);
      document.getElementById("subPageDescrImg").style.display = "none";
	  document.getElementById("subPageDescrText").style.width = "265px";
	  document.getElementById("subPageDescrText").style.height = "166px";
	  document.getElementById("subPageDescrText").style.marginTop = "-6px";
	  document.getElementById("subPageDescrText").style.paddingLeft = "1px";
	  tmp = document.getElementById("subPageDescrText");
	  setTimeout("tmp.innerHTML = imagens[id]",20);
  }
}

/**
 * Função que muda de página em função do botão que foi carregado
 */
function switchTo(i) {
  switch (i) {
	case '1': window.location = "/";break;
	case '2': window.location = "main.php?page=2";break;
	case '3': window.location = "servicos.php?serv=cabelos";break;
	case '4': window.location = "servicos.php?serv=corpo";break;
	case '5': window.location = "portfolio.php?page=5&first=0";break;
	case '6': window.location = "contactos.php?page=6";break;
  }
}


function custom_load_start_1() {
  assignRandomGirlLeft();
  fadeOut('girl_left', 90, 0, 10);
  if (window.document.location.toString().indexOf(separator) != -1) {
    index = window.document.location.toString().indexOf(separator) + separator.length;
    id = window.document.location.toString().substring(index);
    loadData(id);
  }
}

/**
 * Fix para heightdo IE
 */
function adjustHeight() {
  document.getElementById('down').style.height = (windowSize()[1] - 543) + 'px';
  downH = parseInt(document.getElementById('down').style.height); //190px
}

/**
 * Função que devolve o tamanho do ecrã
 */
function windowSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  var size = new Array();
  size[0] = myWidth;
  size[1] = myHeight;
  return size;
}



var ns4=document.layers
var ns6=document.getElementById&&!document.all
var ie4=document.all
Xoffset = 5;    // modify these values to ...
Yoffset = 20;    // change the popup position.
XdivSize = 216;  //size+border
YdivSize = 203;  //size+border
function popup(id) {
	var content="ola";
	document.getElementById("dekImage").style.backgroundImage = "url(getfile.php?table=c_portfolio&servicoid=" + id + "&size=213)";
	document.getElementById("dek").style.display="block";
	document.getElementById("dek").style.visibility="visible";
}

function get_mouse(e){
	if (document.getElementById("dek").style.visibility != "visible") {
		return ;
	}
	var x=(ns4||ns6)?e.pageX:event.x+document.body.scrollLeft;
	var y=(ns4||ns6)?e.pageY:event.y+document.body.scrollTop;
	if ((x + XdivSize + Xoffset) > windowSize()[0]) {
		x = windowSize()[0] - Xoffset - XdivSize;
	}
	if ((y + YdivSize + Yoffset) > windowSize()[1]) {
		y = windowSize()[1] - Yoffset - YdivSize;
	}
	document.getElementById("dek").style.left=x+Xoffset + "px";
	document.getElementById("dek").style.top=y+Yoffset + "px";
}

function kill(){
	document.getElementById("dek").style.visibility="hidden";
	document.getElementById("dek").style.display="none";
}

