$(document).ready(function(){

	// LINKS EXTERNOS
	$("a[rel=externo]").attr('target','_blank');
	$("input[type=submit]").css("cursor","pointer");
	$("input[type=button]").css("cursor","pointer");

	// TRANSPARENCIA
	$(".opac").css("opacity","0.5");

	// AREAS DE ATIVACAO DO LIGHTBOX
	$('a[rel*=lightbox]').lightBox({
		overlayBgColor: '#000',
		overlayOpacity: 0.6,
		imageLoading: 	'img/loading.gif',
		imageBtnClose: 	'img/close.gif',
		imageBtnPrev: 	'img/prev.gif',
		imageBtnNext: 	'img/next.gif',
		containerResizeSpeed: 300,
		txtImage: 'Imagem',
		txtOf: 'de'
	});

	// BT BACK 
	$(".bt-back, .bt-back-topo").click(function(){
		history.back();
	});

	// BT TOPO
	$(".bt-topo").click(function(){
		$(document).scrollTo( {top:'0px',left:'0px'}, 200 );
	});

	$(".holder").cycle({
	    fx: "scrollHorz", 
	    prev: ".bt-left", 
	    next: ".bt-right",
		speed: 300,
	    timeout: 0 
	});
	
	$(".holder-ambientes").cycle({
	    fx: "scrollHorz", 
	    prev: ".bt-left", 
	    next: ".bt-right",
		speed: 300,
	    timeout: 0 
	});

	$("#holder-ranking").cycle({
	    fx: "scrollVert", 
	    prev: ".bt-top", 
	    next: ".bt-bottom",
		speed: 600,
	    timeout: 0 
	});

	//FLASH HOME
	$('#flash-home').flash({
	    src: 'swf/header.swf',
	    width: '100%',
	    height: 272,
		wmode: 'transparent',
		expressInstall: true
	});

	//FLASH HOME
	$('#flash-internas').flash({
	    src: 'swf/header-interna.swf',
	    width: '100%',
	    height: 133,
		wmode: 'transparent',
		expressInstall: true
	});

	// Marcaras
	$('#dia').mask('99/99/9999');
	$('#fone').mask('(99) 9999-9999');

	// TABS AMBIENTES
	$('.tabs-nav li').eq(0).addClass('tabs-selected');

	$('#lista-ambientes li').click(function(){

		$('#lista-ambientes li').removeClass('tabs-selected');
		$(this).addClass('tabs-selected');

		// monta URL e DATA
		var titulo = $(this).find('a').attr('title');
		var boliche = $(this).find('a').attr('rel');

		$.ajax( {
			type: "POST",
			url: 'incs/lista-ambiente.php',
			data: 'boliche=' + boliche + '&titulo=' + titulo,
			beforeSend: function() {
				// enquanto a função esta sendo processada...
//				$('#local-galeria').html('<img src="img/loader.gif" alt="Carregando" />');
//				$('#' + titulo).html('<img src="img/loader.gif" alt="Carregando" />');
			},
			success: function(txt) {
				// troca o conteúdo
//				$('#local-galeria').html(txt);
//				$('#' + titulo).html(txt);
				var arrTxt = txt.split('<!-- SEPARADOR -->');
				$('#imagem-grande').html(arrTxt[0])
				$('#holder').html(arrTxt[1])
			},		
			error: function(txt) {
				// em caso de erro pode dar um alert('erro');
				alert('Erro: '+txt);
			}
		});

		return false;

	});

	$('#itens-cardapio a').click(function(){

		$('#itens-cardapio a').removeClass('active');
		$(this).addClass('active');

		// monta URL e DATA
		var id = $(this).attr('title');
		var id = $(this).attr('rel');

		$.ajax( {
			type: "POST",
			url: 'incs/itens-cardapio.php',
			data: 'id='+id,
			beforeSend: function() {
				// enquanto a função esta sendo processada...
				$('#alvo-ajax').html('<img src="img/loader.gif" alt="Carregando" />');
			},
			success: function(txt) {
				// troca o conteúdo
				$('#alvo-ajax').html(txt);
			},		
			error: function(txt) {
				// em caso de erro pode dar um alert('erro');
				alert('Erro: '+txt);
			}
		});

		return false;

	});

});

function trocaFoto (foto, legenda) {
	$("#imagem-grande .foto-g").attr('src', foto);
	$("#imagem-grande .legenda").html(legenda);
}

/**
  * Função Validar Formulário COM ERRO NA VALIDAÇÃO W3C POIS PEGA O "REL"
  * @param 
  * @return Boolean
  **/
function validaForm(form) {
    for (var i = 0; i < document.getElementById(form).elements.length; i++) {

        var nomeObj = document.getElementById(form).elements[i].name;
        var idObj 	= document.getElementById(form).elements[i].id;
		var relObj 	= document.getElementById(form).elements[i].getAttribute('rel');

		if ((relObj == "email")) {
			expressao = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/i;
			if(!expressao.test(document.getElementById(form).elements[i].value)){
				alert(document.getElementById(form).elements[i].title);
				document.getElementById(form).elements[i].value = "";
				document.getElementById(form).elements[i].style.color = "#000";
				document.getElementById(form).elements[i].focus();
				return false;
			}
		}else if (relObj == "required") {
			if((document.getElementById(form).elements[i].value == null) || (document.getElementById(form).elements[i].value == "")){
				alert(document.getElementById(form).elements[i].title);
				document.getElementById(form).elements[i].style.color = "#000";
				document.getElementById(form).elements[i].focus();
				return false;
			}
		}
    }
    return true;
}
