// V 0.2.0 14/04/2010
function xmlElement(url){if(window.XMLHttpRequest){var Loader = new XMLHttpRequest();Loader.open("GET", url ,false);Loader.send(null);return Loader.responseXML;}else if(window.ActiveXObject){var Loader = new ActiveXObject("Msxml2.DOMDocument.3.0");Loader.async = false;Loader.load(url);return Loader;}}
function XMLHTTPRequest(){try{return new XMLHttpRequest();}catch(ee){try{return new ActiveXObject("Msxml2.XMLHTTP");}catch(e){try{return new ActiveXObject("Microsoft.XMLHTTP");}catch(E){return false;}}}}
function antiCacheRand(aurl){var dt = new Date();if(aurl.indexOf("?")>=0){return aurl + "&" + encodeURI(Math.random() + "_" + dt.getTime());}else{return aurl + "?" + encodeURI(Math.random() + "_" + dt.getTime());}}
function addLoadEvent(func){
  var oldonload = window.onload;
  if(typeof window.onload != 'function'){window.onload = func}else{window.onload = function(){oldonload();func();}}
}
function FormCSSweeg(){
	var form = document.getElementById('FormNET');
	for (var i=0; i<form.length; i++){
		if(form[i].type!='submit' && form[i].type!='button'){
			form[i].onfocus = function (){if(this.parentNode.getElementsByTagName("span")[0].innerHTML == "Valido"){this.parentNode.className="FormNET FormNETFocus";}};
			form[i].onblur = function (){if(this.parentNode.getElementsByTagName("span")[0].innerHTML == "Valido"){this.parentNode.className="FormNET";}};
		}
	}
}
function FormCSSweegForm(form){
	for (var i=0; i<form.length; i++){
		if(form[i].type!='submit' && form[i].type!='button'){
			form[i].onfocus = function (){if(this.parentNode.getElementsByTagName("span")[0].innerHTML == "Valido"){this.parentNode.className="FormNET FormNETFocus";}};
			form[i].onblur = function (){if(this.parentNode.getElementsByTagName("span")[0].innerHTML == "Valido"){this.parentNode.className="FormNET";}};
		}
	}
}
function desabilitar(campo){campo.parentNode.getElementsByTagName("span")[0].innerHTML='Valido';campo.parentNode.className="FormNET FormNETFocus";}
function Valida_Form(form){
	var passed = false; var ok = false;
	for(i = 0; i < form.length; i++){
		if(form[i].title != ""){
			if(form[i].type == "text" || form[i].type == "password" || form[i].type == "file" || form[i].type == "textarea" || form[i].type == "select-one" || form[i].type == "select-multiple") {
				if(form[i].value == ""){form[i].focus();form[i].parentNode.className="FormNET FormNETAlert";form[i].parentNode.getElementsByTagName("span")[0].innerHTML=form[i].title;return passed;stop;};
			}else if(form[i].type == "radio" || form[i].type == "checkbox") {
				for(x = 0; x < form[i].length; x++){ok = false;if (form[i][x].checked){ok = true;break;}};
				if(ok == false){form[i][0].focus();form[i][0].select();form[i].parentNode.className="FormNET FormNETAlert";form[i].parentNode.getElementsByTagName("span")[0].innerHTML=form[i][0].title;return passed;stop;};
			};
			var msg = false;
		}
		if(form[i].id == "DataBrasil"){msg = Valida_data(form[i].value,'Brasil');}
		if(form[i].id == "DataAmerica"){msg = Valida_data(form[i].value,'America');}
		if(form[i].id == "Email"){msg = Valida_email(form[i].value);}
		if(form[i].id == "Numero"){msg = Valida_numerico(form[i].value);}
		if(form[i].id == "Confirma"){msg = Valida_Confirma(form[i].value,form[i-1].value);}
		if(form[i].id == "Minimo"){msg = Valida_Minimo(form[i].value);}
		if(msg == true){form[i].focus();form[i].select();form[i].parentNode.className="FormNET FormNETAlert";form[i].parentNode.getElementsByTagName("span")[0].innerHTML=form[i].alt;return passed;stop;}
	};
	passed = true;return passed;
}
function Mascara(src, mask){
	var len = src.value.length; var saida = '#'; var texto = mask.substring(len);
	if(texto.substring(0,1) != saida){src.value += texto.substring(0,1)};
	if(len>=mask.length){src.value=src.value.substring(0,mask.length)};
}
function MascaraMoeda(objTextBox, e, tipo){
	if(tipo=='Real'){var SeparadorMilesimo='.';var SeparadorDecimal=',';};
	if(tipo=='Dolar'){var SeparadorMilesimo=',';var SeparadorDecimal='.';};
	var sep = 0;var key = '';var i = j = 0;var len = len2 = 0;var strCheck = '0123456789';var aux = aux2 = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if(whichCode == 13){return true;}
	if(whichCode == 8){return true;}
	if(whichCode == 0){return true;}
	key = String.fromCharCode(whichCode);
	if(strCheck.indexOf(key) == -1){return false;}
	len = objTextBox.value.length;
	for(i = 0; i < len; i++){
		if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal)) break;
	};
	aux = '';
	for(; i < len; i++){
		if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) aux += objTextBox.value.charAt(i);
	};
	aux += key;
	len = aux.length;
	if(len == 0){objTextBox.value = '';}
	if(len == 1){objTextBox.value = '0'+ SeparadorDecimal + '0' + aux;}
	if(len == 2){objTextBox.value = '0'+ SeparadorDecimal + aux;}
	if(len > 2 && len < 12){
		aux2 = '';
		for(j = 0, i = len - 3; i >= 0; i--){if(j == 3){aux2 += SeparadorMilesimo;j = 0;}aux2 += aux.charAt(i);j++;}
		objTextBox.value = '';
		len2 = aux2.length;
		for(i = len2 - 1; i >= 0; i--){
			objTextBox.value += aux2.charAt(i);
			objTextBox.value += SeparadorDecimal + aux.substr(len - 2, len);
		}
	};
	return false;
}
function Valida_numerico(String){var msg = false; if(isNaN(String)) msg = true;	return msg;}
function Valida_email(campo){var msg = false; if(campo.match(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/) == null){msg = true} return msg;}
function Valida_Confirma(Prim,Segu){var msg = false;if(Prim != Segu) msg = true;return msg;}
function Valida_Minimo(campo){var msg = false;if(campo.length < 6) msg = true;return msg;}
function Valida_data(data,tipo){ 
	var msg = false; var val = 0;
	if(parseInt(data.length)>0){
		if(tipo=='Brasil'){dia = (data.substring(0,2));mes = (data.substring(3,5));ano = (data.substring(6,10));}
		if(tipo=='America'){mes = (data.substring(0,2));dia = (data.substring(3,5));ano = (data.substring(6,10));}
		if(isNaN(dia)||isNaN(mes)||isNaN(ano)){msg = true;}
		if(parseInt(data.length)<10){val = 1}else{
			if((dia<01)||(dia<01||dia>30)&&(mes==04||mes==06||mes==09||mes==11)||dia>31){val = 1;}
			if(mes<01||mes>12){val = 1;}
			if(mes==2&&(dia<01||dia>29||(dia>28&&(parseInt(ano/4)!=ano/4)))){val = 1;}
		}
		if(val==1){msg = true;}
	}
	return msg;
}
$(document).ready(function(){
	$.smoothAnchors(500, "swing", false);

	//Login
	$("#LoginBtn").click(function(){
		var menuVarOpen = $("#menuOpen").attr('value');
		if(menuVarOpen==0){
			$("#menuOpen").attr('value','1');
			$(".Login").animate({top: "0px"},500);
			$("#LoginSpace").animate({height: "27px"},500);			
		}else if(menuVarOpen==1){
			$("#menuOpen").attr('value','0');
			$(".Login").animate({top: "-27px"},500);
			$("#LoginSpace").animate({height: "0"},500);
		}
	});
	
	//View Item portfolio
	$(".portClose").click(function(){
		$(".portClose").fadeOut(500);
		$('#portUnico').fadeOut(500, function(){
			$("#portTodos").fadeIn(500);
			$(".menuPortfolio2").fadeIn(500);
		});
		$('#sliderCorpo_'+$('#currentPort').attr('value')).fadeOut(500);
	});
	
	$(".imgPortfa").click(function(){
		var TitleImg=$(this).attr('title');
		var NumTitleImg=$(this).attr('name');
		$('#currentPort').attr('value',TitleImg);
		$(".menuPortfolio2").fadeOut(500);
		$('#portTodos').fadeOut(500, function() {
			$('#sliderCorpo_'+TitleImg).fadeIn(500);
			$('#slider_'+TitleImg).html(function(){
				var ImgStr=''; for(var n=1; n <= parseInt(NumTitleImg); n++){ImgStr=ImgStr+"<img src='images/"+TitleImg+n+".png' />";}; return ImgStr;
			});			
			$('#slider_'+TitleImg).SexySlider({auto:false, width:590, height:442, strips:10, delay:100, effect:'fountain', direction:'top', control:'#control_'+TitleImg});
			$("#portUnico").fadeIn(500);
			$(".portClose").fadeIn(500);
		});
	});

	//Portifolio
	$('.MenuPort').click(function(){
		$('.MenuPort').each(function(){$(this).removeClass('MenuPort_2');});
		$(this).addClass('MenuPort_2');
		var atrNamePort = $(this).attr('name');
		if(atrNamePort=='todos'){
			$('.imgPortfa').each(function(){$(this).animate({opacity: 1}, 500);});
		}else{
			$('.imgPortfa').each(function(){
				if ($(this).is('img:not([alt~='+atrNamePort+'])')){$(this).animate({opacity: 0.2}, 500);}
				else{$(this).animate({opacity: 1}, 500);}
			});
		};
	});
});

//Menu
function menuK(Item){
	var menuVarOpen = document.getElementById('menuOpen').value;
	if(menuVarOpen==1){
		document.getElementById('spaceHome').className='space_2';
		document.getElementById('spaceServicos').className='space_2';
		document.getElementById('spacePortfolio').className='space_2';
		document.getElementById('spaceContato').className='space_2';
	}else if(menuVarOpen==0){
		document.getElementById('spaceHome').className='space';
		document.getElementById('spaceServicos').className='space';
		document.getElementById('spacePortfolio').className='space';
		document.getElementById('spaceContato').className='space';
	};
	menuK2(Item);
}
function menuK2(Item){
	document.getElementById('menuHome').className='menuHome';
	document.getElementById('menuServicos').className='menuServicos';
	document.getElementById('menuPortfolio').className='menuPortfolio';
	document.getElementById('menuContato').className='menuContato';
	document.getElementById('menu'+Item).className='menu'+Item+'_2';
}

var flashvars = {};
flashvars.xml = "config.xml";
flashvars.font = "font.swf";
var attributes = {};
attributes.wmode = "transparent";
attributes.id = "slider";
swfobject.embedSWF("cu3er.swf", "cu3er-container", "590", "300", "9", "expressInstall.swf", flashvars, attributes);

function initialize() {
  if (GBrowserIsCompatible()) {
	var map = new GMap2(document.getElementById("map_contato"));
	map.setCenter(new GLatLng(-23.572900,-46.698500), 15);
	
	// Add 10 markers to the map at random locations
	var latlng = new GLatLng(-23.572900,-46.698500);
	map.addOverlay(new GMarker(latlng));
  }
}