function CheckMail(str){ var testresults; var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i; if (filter.test(str)) {testresults=false} else {testresults=true} return (testresults)}
function cChange(div,clas) { var a = div.split(','); for(x=0;x<=a.length-1;x++) { document.getElementById(a[x]).className = clas; } }

function popWin(URL,NAME,WIDTH,HEIGHT,RESIZE,SCROLL) {
   winId = window.open(URL,NAME,'width='+WIDTH+',height='+HEIGHT+',resizable='+RESIZE+',scrollbars='+SCROLL+',menubar=no,toolbar=no,location=no,directories=no,status=no');
	var clientWidth = screen.availWidth;
	var clientHeight = screen.availHeight;
	var xPos = (clientWidth - WIDTH)/2;
	var yPos = (clientHeight - HEIGHT)/2;
	winId.moveTo(xPos,yPos);
}

function montaFlash(swf, width, height, id, wmode, cache) {
	noCache = cache || cache == undefined ? "" : "?" + new Date();
	monta_swf = "";
	monta_swf += "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0\" id=\""+ id +"\" width=\""+ width +"\" height=\""+ height +"\" title=\"\">";
	monta_swf += "<param name=\"movie\" value=\""+ swf + noCache +"\" />";
	monta_swf += "<param name=\"wmode\" value=\""+ wmode +"\" />";
	monta_swf += "<param name=\"quality\" value=\"high\" />";
	monta_swf += "<param name=\"menu\" value=\"false\" />";
	monta_swf += "<param name=\"volume\" value=\"1\" />";
	monta_swf += "<embed src=\""+ swf + noCache +"\" quality=\"high\" wmode=\""+ wmode +"\" volume=\"100\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" menu=\"false\" id=\""+ id +"\" width=\""+ width +"\" height=\""+ height +"\"></embed>";
	monta_swf += "</object>";
	document.write(monta_swf);
}

function checkContato() {
	$("#msgE").html('Aguarde enviando...');								 
	cChange('nome,cidade,uf,telefone,email,mensagem','fldContato')
	var e = new Array();
	var c = 0;
	if($('#nome').val()=='') { e[c++] = 'Preencha seu <b>Nome</b>'; cChange('nome','fldContatoE'); }
	if($('#cidade').val()=='') { e[c++] = 'Preencha sua <b>Cidade</b>'; cChange('cidade','fldContatoE'); }
	if($('#uf').val()=='') { e[c++] = 'Selecione seu <b>Estado (UF)</b>'; cChange('uf','fldContatoE'); }
	if($('#telefone').val()=='') { e[c++] = 'Preencha seu <b>Telefone (Fixo ou Celular)</b>'; cChange('telefone','fldContatoE'); }
	if($('#email').val()=='') { e[c++] = 'Preencha seu <b>E-mail</b>'; cChange('email','fldContatoE'); }
	else if(CheckMail($("#email").val())) { e[c++] = 'Preencha seu <b>E-mail, corretamente</b>'; cChange('email','fldContatoE'); }
	if($('#mensagem').val()=='') { e[c++] = 'Preencha a <b>Mensagem</b>'; cChange('mensagem','fldContatoE'); }
	if(e.length>1) {
		$("#msgE").html('Preencha os campos em <b>Vermelho</b>');
	} else if(e.length==1) {
		$("#msgE").html(e.toString());
	} else if(e.length<=0) {
		$("#fContato").ajaxSubmit({ resetForm:false, success:function(r) { trataretorno('fContato',r); } }); 
		return false;
	}
	return false;
}

function trataretorno(f,s) { var a = s.split("|"); if(a[0]==0) { $("#msgE").html(a[1]); } else if(a[0]==1) { $("#msgE").html(a[1]); $("#"+f).resetForm(); }}

var abriu = 0;


$(document).ready(function() {
	$(".inpOver").hover(function(){ $(this).css("background-position","bottom"); }, function(){ $(this).css("background-position","top"); });
	$(".imgOver, .bBorda").hover(function(){ $(this).children().css("background-position","bottom"); }, function(){ $(this).children().css("background-position","top"); });
	$("#tbThumb tr td a").hover(function(e){ $(this).children().css("background-position","bottom"); }, function(){ $(this).children().css("background-position","top"); });
	$("#areaTextBg").fadeTo('slow', 0.7);
	$("#slider").stop().scrollTo('li:eq(0)',800);


	$('#menu li').hover(
		function(){
			
			$(this).find('img:eq(0)').css("background-position","bottom");
			
			var sub = $(this).find('.dd:eq(0)');
			if( sub.length == 0 ) return false;
			
			sub.show();
			var t = (parseInt(sub.css('top').replace('px', '')) - 5);
			sub.hide();
			var new_t = t + 5;
			
			sub
				.css({ 'top' : t+'px' })
				.animate({ 'top' : new_t + 'px', opacity : 'show' }, 200, function(){
					$(this).css({ 'top' : new_t + 'px' });
				 });
		},
		function(){
			var sub = $(this).find('.dd:eq(0)');			
			sub.hide();
			$(this).find('img:eq(0)').css("background-position","top");
		}
	);
	
});

function paginaDep(pag) {
	$.get(pag, function(r){ $("#tdDep").html(r); });
}

var slideatual = 0;
var timeouti = 0;

function passaTempo(t) { timeouti = setTimeout("slide('+')",t*1000); }
function slide(d) {
	clearTimeout(timeouti);
	var s = $("li", $('#slider')).length-1;
	
	$("#markBal"+slideatual).css("background-position","right");
	if(d=='+' || d=='-') { slideatual = parseInt((d=='+' ? (slideatual<s?slideatual+1:0) : (slideatual>0 && slideatual<=s ? slideatual-1 : s))); } else { slideatual = parseInt(d); }
	$("#slider").stop().scrollTo('li:eq('+slideatual+')',800);
	mostraResenha(slideatual+1);
	$("#markBal"+slideatual).css("background-position","left");
	passaTempo(temposCham[slideatual]);
}
function mostraResenha(i) {
	$.get('pegaResenha.php?id='+idsCham[i], function(r){ 
		var a = r.split("#^#");
		$("#areaTexto h1").html(a[0]);
		$("#areaTexto span").html(a[1]);
	});
}

Shadowbox.init({counterType:'skip', continuous:true, animSequence:'sync', handleOversize: "drag" });
