function toggleMenuPort(layer_sb) {
	var sub_menus = $('menu_portfolio').getElementsByTagName("div");
	for (i=0; i<sub_menus.length; i++) {
		if(sub_menus[i].id != layer_sb)
		{
			eval("$('l_" + sub_menus[i].id + "').className='mais'");
			Element.hide(sub_menus[i]);
		}
	}
	/*if (window.opera)
		Element.toggle(layer_sb);
	else
		Effect.toggle(layer_sb);*/
	if (eval("$('l_" + layer_sb + "').className") == "menos") {
		if (window.opera)
			Element.hide(layer_sb);
		else
			Effect.Fade(layer_sb, { duration:0.2 });
		eval("$('l_" + layer_sb + "').className='mais'");
	}
	else {
		if (window.opera)
			Element.show(layer_sb);
		else
			Effect.Appear(layer_sb, { duration:0.2 });
		eval("$('l_" + layer_sb + "').className='menos'");
	}
}

function marcaMenuPort(id) {
	var sub_menus = $("menu_portfolio").getElementsByTagName("ul");

    for(var i=0;i<sub_menus.length;i++)
    {
    	var links = sub_menus[i].getElementsByTagName("a");
    	for(var j=0;j<links.length;j++)
	    {
			links[j].className="";
		}
	}
	Element.addClassName('mp_id_' + id,'ativo');
}

function trocaImgPort(id, n_img) {
	Effect.Fade('img_peca',{ duration:0.3});
	$('cont_imagem').innerHTML = "<img src=\"imagens/portfolio/" + id + "/" + n_img + ".jpg\" alt=\"\" id=\"img_peca\" style=\"display:none;\" />";
	
	confereCarregada();

	var url = "inc/ajax_nav_img.php"
	var params = "id=" + id + "&n_img=" + n_img;
	var ajax = new Ajax.Request(url, {method: 'get', parameters:params, asynchronous:true, onSuccess:function(t) { adicionaConteudo(t.responseText, 'nav_img_port'); }});
}
function trocaPecaPort(id) {
	$('detalhes_peca').innerHTML = "<p class=\"carregando\">Carregando...</p>";
	marcaMenuPort(id);
	var url = "inc/ajax_pega_peca_port.php"
	var params = "id=" + id;
	var ajax = new Ajax.Request(url, {method: 'get', parameters:params, asynchronous:true,
					onSuccess:function(t) {
						adicionaConteudo(t.responseText, 'detalhes_peca');
						if ($('cont_video_flash')) {
							var FO = { movie:"swf/video.swf?urlVideo=../imagens/portfolio/" + id + "/video.flv", width:"320", height:"280", majorversion:"6", build:"0"};
							UFO.create(FO, "cont_video_flash");
							//alert("flash - swf/video.swf?urlVideo=imagens/portfolio/" + id + "/video.flv");
							//alert($('cont_video_flash').innerHTML);
						}
					}});
}

function mostraAmpliada() {
	Effect.Appear('img_peca',{ duration:0.3});
}
function adicionaConteudo(cont, id_layer) {
	cont=cont.replace(/\+/g," ");
	cont=unescape(cont);
	$(id_layer).innerHTML = cont;
	if (id_layer == 'detalhes_peca' && $('img_peca'))
		confereCarregada();
}
function confereCarregada() {
	if (window.opera)
		mostraAmpliada();
	else
		Event.observe('img_peca', 'load', mostraAmpliada, false);
}

/****** FUNÇÃO PARA POSICIONAMENTO DO SITE ******/
function getPageSize(){
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function posicionaSite() {
	var tamanho = getPageSize();
	//arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	
	if (tamanho[3] < 510) {
		$('mestre').style.top = "0px";
		$('mestre').style.marginTop = "0px";
	}
	else {
		if (!arguments[0]) {
			$('mestre').style.top = "50%";
			$('mestre').style.marginTop = "-252px";
		}
	}
	
	if (tamanho[2] < 960) {
		$('mestre').style.left = "0px";
		$('mestre').style.marginLeft = "0px";
	}
	else {
		if (!arguments[0]) {
			$('mestre').style.left = "50%";
			$('mestre').style.marginLeft = "-477px";
		}
	}
	//alert("PW: " + tamanho[0] + "\nPH: " + tamanho[1] + "\nWW: " + tamanho[2] + "\nWH: " + tamanho[3]);
}
/****** FIM FUNÇÃO PARA POSICIONAMENTO DO SITE ******/

/********************************/
/*** FUNCIONAMENTO NEWSLETTER ***/
/********************************/
function cadastraMailing(email) {
	layer = 'status_mailing';
	$(layer).innerHTML = "Carregando...";
	var url = "ac_mailing.php";
	var params = "email=" + email + "&ajax=true";
	var ajax = new Ajax.Request(url, {method: 'get', parameters:params, asynchronous:true, 
					onSuccess:function(t) {
							$(layer).innerHTML = t.responseText; 
							Element.show(layer);
							if (t.responseText.search(/acao_completa/i) != -1) {
								$('id_email').value = "";
							}
						}});
}
function apagarInput(id_input, valor_input){
	if($(id_input).value == valor_input)
		$(id_input).value = "";
	return false;
}

function reescreverInput(id_input, valor_input){
	if($(id_input).value == "")
		$(id_input).value = valor_input;
	return;
}
/********************************/
/*** FUNCIONAMENTO NEWSLETTER ***/
/********************************/

window.onload = function() {
	posicionaSite();
	window.onresize = function() { posicionaSite(); }
}