// JavaScript Document
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 toggle(a, show) {
	y = document.getElementById("contactos");
	x = document.getElementById("newsletter");
	z = document.getElementById("response");
	switch(a) {
	case 0:
		x.className = "hide";
		z.className = "hide";
		document.getElementById("menu").getElementsByTagName('div')[1].className = 'button';
		if (y.className == "hide" || show) {
			y.className = "show";
			document.getElementById("menu").getElementsByTagName('div')[a].className = 'button open';
		} else {
			y.className = "hide";
			document.getElementById("menu").getElementsByTagName('div')[a].className = 'button';
		}
	break;
	case 1:
		y.className = "hide";
		document.getElementById("menu").getElementsByTagName('div')[0].className = 'button';
		if (x.className == "hide" || show) {
			if (z.className == "hide") x.className = "show";
			if (z.className == "show" && !show) {
				z.className = "hide";
				document.getElementById("menu").getElementsByTagName('div')[a].className = 'button';
			}
			else document.getElementById("menu").getElementsByTagName('div')[a].className = 'button open';
		} else {
			x.className = "hide";
			z.className = "hide";
			document.getElementById("menu").getElementsByTagName('div')[a].className = 'button';
		}
	break;
	default:
		y.className = "hide";
		document.getElementById("menu").getElementsByTagName('div')[0].className = 'button';
		x.className = "hide";
		if (z.className == "hide")
		document.getElementById("menu").getElementsByTagName('div')[1].className = 'button';
	break;
	}
}

function closeResponse() {
	document.getElementById("response").className = "hide";
	document.getElementById("menu").getElementsByTagName('div')[1].className = 'button';
}



/* ALTERAR NUMERO TOTAL DE FOTOS (totalPhotos) DESEJADAS NO SLIDESHOW EM BAIXO */
var totalPhotos = 8;


var currentPhoto = 1 + Math.round((Math.random() * (totalPhotos - 1)));

function initSlideShow() {
	document.getElementById("slide").innerHTML = '<img src="pics/slideshow/'+currentPhoto+'.jpg" />';
	if (totalPhotos > 1) MM_preloadImages('pics/slideshow/'+(currentPhoto+1)+'.jpg');	
	var slideshowVar = setInterval(function() { 
		if (currentPhoto == totalPhotos) currentPhoto = 1;
		else currentPhoto++;
		elem = document.getElementById("slideAux");
		elem.innerHTML = '<img src="pics/slideshow/'+currentPhoto+'.jpg" />';
		if (currentPhoto+1 <= totalPhotos) MM_preloadImages('pics/slideshow/'+(currentPhoto+1)+'.jpg');
		move(elem,-200,0,50,50,0.1);
	},/*    PARA ALTERAR A DURAÇÃO DO SLIDESHOW É MUDAR ESTE VALOR (em milisegundos) -->   */ 12000);
}

function move(elem,startRight,endRight,steps,intervals,powr) { 
	if (elem.moveInt)
	window.clearInterval(elem.moveInt);
	var actStep = 0;
	elem.style.right = "-200px";
	elem.moveInt = window.setInterval(
		function() { 
		  elem.currentRight = easeInOut(startRight,endRight,steps,actStep,powr);
		  elem.currentAlpha = easeInOut(0,100,steps,actStep,2);
		  elem.style.right = elem.currentRight+"px"; 
		  elem.style.opacity = elem.currentAlpha/100;
		  elem.style.filter = "alpha(opacity = "+elem.currentAlpha+");";
		  actStep++;
		  if (actStep > steps) { 
		  	document.getElementById("slide").innerHTML = elem.innerHTML;
			elem.innerHTML = '';
			elem.style.opacity = 0;
			elem.style.filter = "alpha(opacity = 0);";
			elem.style.zIndex = 2;
		  	window.clearInterval(elem.moveInt);
		  }
		} 
	,intervals)
}



function easeInOut(minValue,maxValue,totalSteps,actualStep,powr) { 
//Generic Animation Step Value Generator By www.hesido.com
    totalSteps = Math.max(totalSteps,1)
    var delta = maxValue - minValue; 
    var stepp = minValue+(Math.pow(((1 / totalSteps) * actualStep), powr) * delta);  
    return Math.ceil(stepp) 
}



function subscribe(form) {
	if (form.name.value == '' || form.name.value == '') {
		alert("Por favor, preencha os campos obrigatórios.");
		return false;
	}
	var xmlHttp;
	try {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	} catch (e) {
	  // Internet Explorer
	  try {
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	  } catch (e) {
		try {
		  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {
		  alert("O seu browser não permite a subscrição da newsletter. Pedimos desculpa pelo incómodo.");
		  return false;
		}
	  }
	}
	xmlHttp.onreadystatechange=function() {
	   if(xmlHttp.readyState==4) {
		  /*document.getElementById('response').innerHTML=xmlHttp.responseText;
		  document.myform.message.value = '';*/
		  
		  document.getElementById("newsletter").className = "hide";
		  if (xmlHttp.responseText == 'true') {
		  	document.getElementById("response").innerHTML = '<div class="container"><span>A SUA INSCRIÇÃO FOI ENVIADA COM SUCESSO.<br/><br/><a href="javascript:closeResponse()">[X] FECHAR</a></span></div>';
		    form.reset();
		  } else
		  	document.getElementById("response").innerHTML = '<div class="container"><span>NÃO FOI POSSIVEL SUBMETER A SUA INSCRIÇÃO. POR FAVOR, TENTE MAIS TARDE.<br/><br/><a href="javascript:closeResponse()">[X] FECHAR</a></span></div>';
		  document.getElementById("response").className = "show";
		  //alert(xmlHttp.responseText);
	   }
	}
	var url="subscribe.php";
	url=url+"?name="+form.name.value; 
	url=url+"&email="+form.email.value;
	url=url+"&phone="+form.phone.value; 
	url=url+"&sid="+Math.random();
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

