// AJAX

var BAjax = {
	varsget: '',
	loader: 'Load do ajax.',
	msgerror: 'Erro: A solicitacao AJAX falhou!',
	elementresponse: '',
	elementload: '',
	timewait: 3000,
	request: new Array(),
	replaceText: function (el, text) {
		if (el != null) {
			clearText(el);
			el.innerHTML = text;	
		}
	},
	clearText: function (el) {
		if (el != null) {
	    	if (el.childNodes) {
	      		for (var i = 0; i < el.childNodes.length; i++) {
	        		var childNode = el.childNodes[i];
	        		el.removeChild(childNode);
	      		}
	    	}
	  	}
	}, 
	getText: function (el){
		var text = "";
		if (el != null) {
			if (el.childNodes) {
				for (var i = 0; i < el.childNodes.length; i++) {
		        	var childNode = el.childNodes[i];
		        	if (childNode.nodeValue != null) {
		          		text = text + childNode.nodeValue;
		        	}
		      	}
		    }
		}
		return text;
	}, 
	createRequest: function (){
		try {
			tmpRequest = new XMLHttpRequest();
			BAjax.request.push(tmpRequest);
		} catch (trymicrosoft) {
			try {
				tmpRequest = new ActiveXObject("Msxm12.XMLHTTP");
				BAjax.request.push(tmpRequest);
			} catch (othermicrosoft) {
				try {
					tmpRequest = new ActiveXObject("Microsoft.XMLHTTP");
					BAjax.request.push(tmpRequest);
				} catch (failed) {
					alert("Erro ao criar o objeto!");
				}
			}
		}
		if (BAjax.request.length==0) {
			alert("Erro ao criar o objeto!");
		}
	},
	load: function (){
		BAjax.createRequest();
		tmprequest = BAjax.request[(BAjax.request.length-1)];
		url = 'ajax.php?'+BAjax.varsget;
		tmprequest.open("GET",url,true);
		tmprequest.onreadystatechange = BAjax.updatePage;
		tmprequest.send(null);
		
	}, 
	updatePage: function (){
		tmpload = document.getElementById(BAjax.elementload);
		if(tmprequest.readyState < 4) {
		   	tmpload.innerHTML = BAjax.loader;
		} else {
			if(tmprequest.status == 200){
					c=window.setTimeout(
						function (){ 
								document.getElementById(BAjax.elementresponse).innerHTML  = tmprequest.responseText;
								showLightbox();
						}, BAjax.timewait
					);
			} else {
					alert(BAjax.msgerror);
			}
		}
	}
}

//GLOBAL

var GLOBAL_expEmail = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
var GLOBAL_fontSize = 0;
var GLOBAL_height = -178;
var GLOBAL_imgLoad = new Image();
GLOBAL_imgLoad.src='img/load.gif';

//LITEBOX

function verDetalhePortifolio(varsget){
	BAjax.loader='<div align=\"center\" style=\"background:#7da758; width: 42px; border:5px solid #FFF; height: 38px; padding: 5px 0 0 0; margin: 170px auto 0 auto;\"><img src="img/load.gif" /></div>';
	BAjax.elementresponse = 'detalheportifolio';
	BAjax.elementload = 'detalheportifolio';
	BAjax.varsget=varsget;
	BAjax.load();
}

function verDetalhePortifolioSend(varsget){
	BAjax.loader='<div align=\"center\" style=\"background:#7da758; width: 60px; color:#FFF; font-size:11px; text-align:center; border:5px solid #FFF; height: 55px; padding: 5px 0 0 0; margin: 170px auto 0 auto;\"><img src="img/load.gif" /><br>Enviando...</div>';
	BAjax.elementresponse = 'detalheportifolio';
	BAjax.elementload = 'detalheportifolio';
	BAjax.varsget=varsget;
	BAjax.load();
}

function verPortifolio(portifolio){
	setZoomDetalhe();
	verDetalhePortifolio('case='+portifolio);
}

function sendEmail(nome, email, assunto, msg){
	setZoomDetalhe();
	verDetalhePortifolioSend('case=send&nome='+nome+'&email='+email+'&assunto='+assunto+'&msg='+msg);
}

function setZoomDetalhe(){
	var zoomdetalhe = document.getElementById('zoomdetalhe');
	var detalheportifolio = document.getElementById('detalheportifolio');
	zoomdetalhe.style.MozOpacity='0.5'; 
	zoomdetalhe.style.opacity='.50'; 
	zoomdetalhe.style.filter='alpha(opacity=50)';
	zoomdetalhe.style.display='block';
	detalheportifolio.style.display='block';
}
function apagatudo(){
	var zoomdetalhe = document.getElementById('zoomdetalhe');
	var detalheportifolio = document.getElementById('detalheportifolio');
	zoomdetalhe.style.display='none';
	detalheportifolio.style.display='none';
	detalheportifolio.innerHTML='';	
}
function fechar(){
	hideLightbox();
	setTimeout('apagatudo()', 500);
}

function validaform(){
	d = document.getElementById('form');
	if (d.nome.value == ""){
			alert("Digite seu nome");
			d.nome.focus();
			return false;
			}
			
	if (d.email.value == ""){
			alert("Digite seu e-mail.");
			d.email.focus();
			return false;
			}
	if (d.assunto.value == ""){
			alert("Digite o assunto.");
			d.assunto.focus();
			return false;
			}
			
	if (d.msg.value == ""){
			alert("Digite sua message.");
			d.msg.focus();
			return false;
			}
	sendEmail(d.nome.value, d.email.value, d.assunto.value, d.msg.value);
	}
	
function legendaPortifolio(imagem){
	return overlib('<div>'+imagem+'</div>', BGCOLOR, '#000');
}

function verMapa(){
	setZoomDetalhe();
	BAjax.loader='<div align=\"center\" style=\"background:#fff; width: 60px; height: 55px; padding: 5px 0 0 0; margin: 170px auto 0 auto;\"><img src="img/load.gif" /></div>';
	BAjax.elementresponse = 'detalheportifolio';
	BAjax.elementload = 'detalheportifolio';
	BAjax.varsget='pg=2';
	BAjax.load();
}


    document.onkeydown = this.keyboardAction; 

	function keyboardAction(e) {
		if (e == null) { // ie
			keycode = event.keyCode;
			escapeKey = 27;
		} else { // mozilla
			keycode = e.keyCode;
			escapeKey = e.DOM_VK_ESCAPE;
		}

		key = String.fromCharCode(keycode).toLowerCase();
		
		if(keycode == escapeKey){	// close lightbox
			fechar();
		}
	}