jQuery(function(){
	var j = jQuery;
	//ABRIR PAGINA EM NOVA
	j('a[rel="external"]').click(function(){window.open(j(this).attr('href'));return false;});
	/* videos */
	j('.openVideoM').click(function(){
		var video = j(this).attr('rel');
		var posicao = j(this).offset();
		
		if(!j('.boxVidMult').is(':visible')){
			j('.boxVidMult div').html('<embed src="../../swf/player.swf" bgcolor="#D0D7D9" width="350" height="260" allowfullscreen="true" TYPE="application/x-shockwave-flash" FlashVars="file='+video+'&amp;backcolor=D0D7D9&amp;frontcolor=006633&amp;lightcolor=006969&amp;controlbar=bottom&amp;volume=80&amp;repeat=none&amp;stretching=fill&amp;bufferlength=1"></embed>');
			j('.boxVidMult').css({top:posicao.top,left:posicao.left+175});
			j('.boxVidMult').fadeIn();
		}
		else{
			j('.boxVidMult div').html('<embed src="../../swf/player.swf" bgcolor="#D0D7D9" width="350" height="260" allowfullscreen="true" TYPE="application/x-shockwave-flash" FlashVars="file='+video+'&amp;backcolor=D0D7D9&amp;frontcolor=006633&amp;lightcolor=006969&amp;controlbar=bottom&amp;volume=80&amp;repeat=none&amp;stretching=fill&amp;bufferlength=1"></embed>');
			j('.boxVidMult').hide();
			j('.boxVidMult').css({top:posicao.top,left:posicao.left+175});
			j('.boxVidMult').fadeIn();
			}
		return false;
	})
	
	j('body').click(function(){
		j('.boxVidMult').hide();
	});
	
	
	//MARCADOR DE MENU
	var idPag = jQuery("body").attr("id");
	if(idPag == ""){return false;}
	else{jQuery("a."+idPag).addClass("marcar");}
	jQuery("a."+idPag).click(function(){return false;});
	//MARCADOR DE MENU
	
	//SELECT
	jQuery("html").click(function(){
		jQuery(".select ul").fadeOut();
	});
	jQuery(".select input").focus(function(){
		var pic = jQuery(this);
		pic.removeAttr("width");
		var wOpt = pic.width()+21;
		var numOpt = jQuery(this).next().next().children("li").length;
		jQuery(".select ul").hide();
		jQuery(this).attr("readonly", "readonly");
		jQuery(this).attr("autocomplete", "off");
		if(numOpt > 7){
			jQuery(this).next().next("ul").attr({style: "width:"+wOpt+"px;height:"+160+"px;overflow:auto;display:block;"});
			return false;
		}else{
			jQuery(this).next().next("ul").attr({style: "width:"+wOpt+"px;display:block;"});
			return false;
		}
	});
	jQuery(".select input").click(function(){
		return false;
	});
	jQuery("div.select").click(function(){
		if((jQuery(this).children("ul").css('display') == 'none')){
			jQuery(this).children("input").focus();
			jQuery(this).children("ul").show();
		}else{
			jQuery(".select ul").fadeOut();
		}
		return false;
	});
	jQuery(".select ul li").click(function(){
		var value = jQuery(this).children('a').text();
		var codVl = jQuery(this).children('a').attr("rel");
		jQuery(this).parent().prev().prev().val(value);
		jQuery(this).parent().next().val(codVl);
	});
	/*jQuery(".select ul li a").click(function(){
		var value = jQuery(this).text();
		var codVl = jQuery(this).attr("rel");
		jQuery(this).parent().parent().prev().prev().val(value);
		jQuery(this).parent().parent().next().val(codVl);
	});*/
	jQuery(".select input").blur(function(){
		jQuery(".select ul").fadeOut();
	});
	//SELECT
	
	//ESTEIRA
	jQuery(".scLeft").click(function(){
		stepcarousel.stepBy('mygallery', -3);
	});
	jQuery(".scRight").click(function(){
		stepcarousel.stepBy('mygallery', 3)
	});
	//ESTEIRA
	
	//LISTA DE IMAGENS
	if(jQuery('.boxGal span.legImg02 span span').text() == ""){jQuery('.boxGal span.legImg02').css({opacity:0});}
	else {jQuery('.boxGal span.legImg02').css({opacity:1});}
//	var wImg = jQuery(".zoom img").width();
//	jQuery(".legImg02").animate({width: wImg-20});
//	jQuery(".boxGal").animate({width: wImg+16});
	jQuery(".belt li:first a img").css({opacity:0.5});
	
	jQuery(".panel a").click(function(){
		var imgZoom = jQuery(this).attr("href");
		var cod = jQuery(this).attr("rel");
		
		if( cod == ""){jQuery('.boxGal span.legImg02').css({opacity:0});}
		else {jQuery('.boxGal span.legImg02').css({opacity:1});}
		
		if(jQuery(".zoom img").attr("src") == imgZoom){return false}
		jQuery(".panel a").find("img").css({opacity:1});
		jQuery(this).find("img").css({opacity:0.5});
		jQuery(".zoom img").hide();
		loadImage(imgZoom);
		jQuery('.boxGal span span span').text(cod);
		jQuery('.areaAmpliada .cod span').text(cod).fadeIn();
		return false;
	});
	
	function loadImage(imgZoom){
		var img = new Image(); //cria o objeto imagem
		jQuery(img).error(function(){
			alert("Imagem não encontrada.");
			jQuery(".zoom img").fadeOut();
		});
		jQuery(img).load(function (){ //começa o load da imagem para dentro da variavel
			jQuery.ajax({
				success: function () {
					
					jQuery('.zoom').html(img); //atualiza o conteudo do elemento img_receive para a imagem
					jQuery('.zoom').find('img').hide();
					var wImg = jQuery(".zoom img").width();
					jQuery(".legImg02").animate({width: wImg-20}, 500);
					jQuery(".boxGal").animate({width: wImg+16}, 500);
					setTimeout(function(){ 
						jQuery('.zoom').find('img').fadeIn("fast"); //exibe a imagem
					}, 500 );
				}
			});
		}).attr('src', imgZoom);
	 }
	//LISTA DE IMAGENS
	
	//LIMPA INPUT
	jQuery(".linpaInput").focus(function(){
	if( this.value == this.defaultValue ) {
			this.value = "";
		}
		}).blur(function() {
	if( !this.value.length ) {
			this.value = this.defaultValue;
		}
	});
	//LIMPA INPUT
	
	jQuery("#maisdepend").click(function(){
		jQuery(".tabeladependente tbody tr:hidden:first").show();
		if(jQuery(".tabeladependente tr:last").css("display") != "none"){
			jQuery("#maisdepend").hide();
		}
	});
	
	jQuery('.termoComp span').click(function(){
		jQuery('.boxTermoTxt').fadeIn(500);
		return false;
	});
	jQuery('#termoCompromisso').attr('checked', '');
	jQuery('.termoComp').click(function(){
		jQuery(this).toggleClass('termoCompCheck');
		
		if(jQuery(this).hasClass('termoCompCheck')){ jQuery('#termoCompromisso').attr('checked', 'checked'); }
		else{jQuery('#termoCompromisso').attr('checked', ''); }
	});
	
	
	jQuery('#botao_regulamento').click(function(){
		jQuery(this).toggleClass('marcado');
		if($('#regulamento').is(':checked')){jQuery('#regulamento').attr('checked', '');}
		else{jQuery('#regulamento').attr('checked', 'checked');}
		jQuery('.balao_regulamento').hide();
		return false;
	});
	
	jQuery('.fechaTermo').click(function(){
		jQuery('.boxTermoTxt').fadeOut(500);
		return false;
	});
	
	jQuery('.infoSecao').click(function(){
		jQuery('.boxInfoSecao').fadeIn();
	});
	
	jQuery('.btnFechar a').click(function(){
		jQuery('.boxInfoSecao').fadeOut();
	});
	
	j(".moldBL").each(function(){
		//busca na lista um elemento com uma propriedade espacifica
		j(".moldBL").has("img").addClass("comFoto");
	});	
	
	j('.moldImg').each(function(){
		if(j(this).has('img')){
			var widImg = j(this).find('img').width()
			j(this).children('div').children('div').css({"width":widImg});
		}else alert("não tem imagem");
	});
	
	jQuery('.campoCheck').find('input').val("")
	jQuery('.campoCheck').click(function(){
		if(jQuery(this).hasClass("checado")){
			jQuery(this).removeClass("checado");
			jQuery(this).find('input').val("")
		}else{
			jQuery(this).addClass("checado");
			jQuery(this).find('input').val("true")
		}
	});
	
	jQuery('.openReservas').click(function(){
		if(jQuery(this).hasClass('checado')){
			jQuery(this).next().fadeIn().find('div.campoCheck:first').addClass("checado");
			jQuery(this).next().find('div.campoCheck:first input').val("true")
		}else{
			jQuery(this).next().fadeOut().find('div.campoCheck').removeClass("checado");
			jQuery(this).next().find('div.campoCheck input').val("")
		}
		
	})
	
	
	
	
});
