$(document).ready(function() {
	var l = $('#foto_topo img').width();
	$('#foto_topo').css({'width':l+'px','margin':'0 auto'});
	$('.thumb img').each(function(){
		var l = $(this).width();
		var a = $(this).height();
		if(l>131){
			$(this).css({'width':'131px'});
		}
		if(a>105){
			$(this).css({'height':'105px'});
		}
	});
	/*+url*/
	if(document.URL.indexOf('servidor3') != -1){
		base = 'http://servidor3/turismobento.com.br/www/';
		idioma = document.URL.split('/');
		idioma = idioma[5];
	}else if(document.URL.indexOf('alvoglobal.com.br/clientes') != -1){
		base = 'http://www.alvoglobal.com.br/clientes/turismobento/';
		idioma = document.URL.split('/');
		idioma = idioma[5];
	}else{
		base = 'http://www.turismobento.com.br/';
		//base = 'http://www.turismobento.com.br/novo_site/';
		idioma = document.URL.split('/');
		idioma = idioma[3];
	}
	/*-url*/
	$('#all').prepend('<img style="z-index:999;display:block;width:136px;height:135px;left:851px;top:75px;position:absolute;" src="'+base+'imagens/estrutura/melhor-site.png" alt="O Melhor Site Turístico do Brasil 2011" />');
	var nav = navigator.appVersion;
	$('html').css({'overflow-y':'scroll'});
	/*postais*/
	$('.radio_container').hover(function(){
		if($(this).children('.radio').length > 0){
			$(this).children('.radio').addClass('radio_destaque');
		}else{
			$(this).next('.radio').addClass('radio_destaque');
		}
	});
	$('.radio input[type="radio"]').hover(function(){
			$(this).parent('span').addClass('radio_destaque');
	});
	$('span.radio').hover(function(){
		$(this).addClass('radio_destaque');
	});
	$('.radio_container').mouseout(function(){
		if($(this).is('div')){
			$('.radio').removeClass('radio_destaque');
		}
			
	});
	/*postais*/
	/*tam fonte*/
	$('body').css({'color':'black !important'});
	$('a#ini').bind('click', function(e){
		e.preventDefault();
		$('#inner_mid p, #inner_mid a, #inner_mid h4, #inner_mid table td, #inner_mid li, span.data, .texto_mutavel').css({'font-size': 12});
		$('#inner_mid li h5').css({'font-size': 14});
		$('#inner_mid h6').css({'font-size': 11});
	});
	$('a#dim').bind('click', function(e){
		e.preventDefault();
		var tam = parseInt($('#inner_mid p').css('font-size'));
		tam -= 1;
		if(tam >= 11){
			$('#inner_mid p').css({'font-size': tam});
		}
		$('.texto_mutavel').each(function(){
			tam = parseInt($(this).css('font-size'));
			tam -= 1;
			if(tam >= 11){
				$(this).css({'font-size': tam});
			}
		});
		tam = parseInt($('#inner_mid a').css('font-size'));
		tam -= 1;
		if(tam >= 11){
			$('#inner_mid a').css({'font-size': tam});
		}
		tam = parseInt($('#inner_mid h4').css('font-size'));
		tam -= 1;
		if(tam >= 11){
			$('#inner_mid h4').css({'font-size': tam});
		}
		tam = parseInt($('#inner_mid li h5').css('font-size'));
		tam -= 1;
		if(tam >= 13){
			$('#inner_mid li h5').css({'font-size': tam});
		}
		tam = parseInt($('#inner_mid h6').css('font-size'));
		tam -= 1;
		if(tam >= 10){
			$('#inner_mid h6').css({'font-size': tam});
		}
		tam = parseInt($('#inner_mid table td').css('font-size'));
		tam -= 1;
		if(tam >= 11){
			$('#inner_mid table td').css({'font-size': tam});
		}
		tam = parseInt($('#inner_mid li').css('font-size'));
		tam -= 1;
		if(tam >= 11){
			$('#inner_mid li').css({'font-size': tam});
		}
		tam = parseInt($('span.data').css('font-size'));
		tam -= 1;
		if(tam >= 11){
			$('span.data').css({'font-size': tam});
		}
	});
	$('a#aum').bind('click', function(e){
		e.preventDefault();
		var tam = parseInt($('#inner_mid p').css('font-size'));
		tam += 1;
		if(tam <= 17){
			$('#inner_mid p').css({'font-size': tam});
		}
		$('.texto_mutavel').each(function(){
			tam = parseInt($(this).css('font-size'));
			tam += 1;
			if(tam <= 17){
				$(this).css({'font-size': tam});
			}
		});
		tam = parseInt($('#inner_mid a').css('font-size'));
		tam += 1;
		if(tam <= 17){
			$('#inner_mid a').css({'font-size': tam});
		}
		tam = parseInt($('#inner_mid h4').css('font-size'));
		tam += 1;
		if(tam <= 17){
			$('#inner_mid h4').css({'font-size': tam});
		}
		tam = parseInt($('#inner_mid li h5').css('font-size'));
		tam += 1;
		if(tam <= 19){
			$('#inner_mid li h5').css({'font-size': tam});
		}
		tam = parseInt($('#inner_mid h6').css('font-size'));
		tam += 1;
		if(tam <= 16){
			$('#inner_mid h6').css({'font-size': tam});
		}
		
		tam = parseInt($('#inner_mid table td').css('font-size'));
		tam += 1;
		if(tam <= 17){
			$('#inner_mid table td').css({'font-size': tam});
		}
		tam = parseInt($('#inner_mid li').css('font-size'));
		tam += 1;
		if(tam <= 17){
			$('#inner_mid li').css({'font-size': tam});
		}
		tam = parseInt($('span.data').css('font-size'));
		tam += 1;
		if(tam <= 17){
			$('span.data').css({'font-size': tam});
		}
	});
	/*tam fonte*/
	/*ajuste tam imagens*/
	/*
	$('.thumb img, .listagem_imagem_item img').each(function(){
		if($(this).height() < 105){
			$(this).css({'margin-top':((105 - $(this).height()) / 2) + 'px'});
		}
	});
	*//*
	$('#foto_topo img').each(function(){
		if($(this).height() < 302){
			$(this).css({'margin-top':((302 - $(this).height()) / 2) + 'px'});
		}
	});*/
	/*
	$('#ultimas_noticias_imagem img').each(function(){
		if($(this).height() < 174){
			$(this).css({'margin-top':((174 - $(this).height()) / 2) + 'px'});
		}
	});
	*/
	/*ajuste tam imagens*/
	/*+mapa site*/
	var altura = $('div#mapa_site').height();
	if($.browser.msie){
		altura = 700;
	}
	$('div#mapa_site').css({'opacity':0, 'height':'0'});
	$('div#mapa_site').hide(0);
	$('a#trigger_mapa_site').bind('click', function(e){
		e.preventDefault();
		if($('div#mapa_site').is(':visible')){
			if($.browser.msie){
				$('.objeto').css({'display':'block'});
				if(nav.indexOf('MSIE 7.0')!=-1){
					$('#banner_feiras_e_eventos').css({'display':'block'});
				}
			}
			$(this).removeClass('trigger_mapa_site');
			$('div#mapa_site').animate({
				'width': 162,
				'left': 360,
				'opacity': 0,
				'height': 0
				}, 500,
				'easeInSine', 
				function(){
					$('div#mapa_site').hide(0);
				});
		}else{	
			if($.browser.msie){
				$('.objeto').css({'display':'none'});
				if(nav.indexOf('MSIE 7.0')!=-1){
					$('#banner_feiras_e_eventos').css({'display':'none'});
				}
			}
				$(this).addClass('trigger_mapa_site');
				$('div#mapa_site').before('<div style="position:absolute;width:160px;left:361px;height:1px;background:#f4f5c2;z-index:9999;"></div>');
				$('div#mapa_site').show();
				$('div#mapa_site').css({'z-index': 9999});
				$('div#mapa_site').animate({
					'width': 728,
					'left': 0,
					'opacity': 1,
					'height': altura
				}, 500,
				'easeInSine', 
					function(){
				});
		}
	});
	/*-mapa site*/
	
	fancyBox();
	
	function fancyBox(){
		$('a.modal').fancybox({
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'titlePosition' 	: 'over',
			'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-over">Imagem ' + (currentIndex + 1) + ' de ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
			},
			'swf': {wmode: 'transparent'},
			'width': 700,
			'height': 264,
			onClosed: function(){
				$('.objeto').css({'display':'inline'});
			},
			onStart: function(){
				$('.objeto').css({'display':'none'});
			}
		});
	}
	
	var img = new Image();
	var src = base + 'imagens/estrutura/ajax-loader.gif';
	img.src = src;
	
	/*+swf*/
	swfobject.embedSWF(base + 'swf/destaques.swf?v=' + new Date().getTime(), 'destaques', '100%', '280', '9.0.0', 'expressInstall.swf', {embed: true}, {wmode:'transparent'} , {flashvar:'text'});
	/*-swf*/
	
	/*menu*/
	len = $('div#menu ul li.pnivel').length;
	$('div#menu ul li.pnivel').eq( len - 1 ).css({'background':'#350d3d'});
	$('div#menu ul li.pnivel').eq( len - 2 ).css({'background':'#350d3d', 'margin-bottom':20});
	$('a.item').each(function(){
		if(document.URL.toLowerCase().indexOf($(this).attr('rel'))==-1){ 
			$(this).next('ul.subitem').slideUp(0);
		}
	});
	$('ul#menu_principal li.pnivel a.pnivel').each(function(){
		if(document.URL.toLowerCase().indexOf($(this).attr('rel'))!=-1){ 
			$(this).css({'background': 'url(' + base + 'imagens/estrutura/marcador_branco.png) 7px center no-repeat #52205c'});
			$(this).next('ul.subitem').children('li').addClass('segundo_nivel');
		}
	});
	$('a.item').click(function(e){
		e.preventDefault();
		if($(this).next('ul.subitem').is(':visible')){
			$('ul.subitem').slideUp();
			$(this).next('ul.subitem').slideUp('5000', 'easeInSine', function(){});
		}else{
			$('ul.subitem').slideUp();
			$('li').removeClass('segundo_nivel');
			$(this).next('ul.subitem').slideDown('5000', 'easeInSine', function(){
				$(this).children('li').addClass('segundo_nivel');
			});
		}
	});
	
	/*menu*/
	
	/*+ATRATIVOS*/
	
	$('.titulo:last').css({'background':'#350D3D'});
	
	$('.atrativo a.atrativos_img').bind('mouseover', function (){
		$(this).prev('a').addClass('hover_atrativos');
	})
	$('.atrativo a.atrativos_img').bind('mouseout', function (){
		$(this).prev('a').removeClass('hover_atrativos');
	})
	
	$('a.titulo').bind('mouseover', function (){
		$(this).addClass('hover_atrativos');
	})
	$('a.titulo').bind('mouseout', function (){
		$(this).removeClass('hover_atrativos');
	})
	
	/*-ATRATIVOS*/
	
	/*ENQUETE*/
	$('#form_enquete_submit').click(function(event){
		id_opcao = $('input:radio[name=id_opcao]:checked').val();
		id_enquete = $('input[name=id_enquete]').val();
		$('#enquete').css({'padding-left':'159px'});
		$('#enquete').html('<img src="' + base + 'imagens/estrutura/ajax-loader.gif" alt="Carregando..." />');
		event.preventDefault();
		$.get(
				base + 'async/enquete.php', 
				{arg: 1, id_opcao: id_opcao, id_enquete: id_enquete}, 
				function(data){
					$('#enquete').css({'padding-left':'0'});
					$('#enquete').html(data);
		});
	});
	$('#form_enquete_resultados').click(function(event){
		$('#enquete').html('<img src="' + base + 'imagens/estrutura/ajax-loader.gif" alt="Carregando..." />');
		event.preventDefault();
		$.get(
				base + 'async/enquete.php?idioma=' + idioma, 
				function(data){
					$('#enquete').html(data);
		});
	});
	/*ENQUETE*/
	
	/*+noticias*/
	if($('.ultima_noticia').length > 1){
		var timer_noticias_id = playNoticias();
	}
	
	$('.ultima_noticia').bind('mouseover', function(){
		if(timer_noticias_id){
			clearInterval(timer_noticias_id);
		}
	});
	
	$('.ultima_noticia').bind('mouseout', function(){
		if($('.ultima_noticia').length > 1){
			timer_noticias_id = playNoticias();
		}
	});
	
	function playNoticias(){
		id = setInterval(function(){
			var obj = $('.ultimas_noticias li.foco');
			obj.removeClass('foco');
			if(obj.next('.ultimas_noticias li').length){
				trocaNoticia(obj.next('.ultimas_noticias li'));
			}else{
				trocaNoticia($('.ultimas_noticias li').eq(0));
			}
		}, 5000);
		return id;
	}
	
	function trocaNoticia(obj){
		if(!obj.is('.foco')){
			$('#img_ultima_noticia').css({'margin-top':70});
			$('#ultimas_noticias_imagem').css({'text-align':'center'});
			$('#img_ultima_noticia').attr('src', base+'imagens/estrutura/ajax-loader.gif');
			$('#img_ultima_noticia').attr('alt', 'Carregando...');
			$('.ultimas_noticias li').removeClass('foco');
			obj.addClass('foco');
			var prefixo = obj.attr('id').replace('noticia_','');
			var src = base + 'imagens/' + prefixo +'_1n.jpg';
			var img = new Image();
			img.src = src;
			var href = obj.children('a').attr('href');
			var title = obj.children('a').attr('title');
			if(img.complete){
				$('#img_ultima_noticia').parent('a').attr('href', href);
				$('#img_ultima_noticia').parent('a').attr('title', title);
				$('#img_ultima_noticia').css({'display':'none', 'margin-top':0});
				$('#img_ultima_noticia').attr('src', src);
				$('#img_ultima_noticia').fadeIn(350);
				$('#ultimas_noticias_imagem img').each(function(){
					if($(this).height() < 174){
						//$(this).css({'margin-top':((174 - $(this).height()) / 2) + 'px'});
					}
				});
			}else{
				img.onload = function(){ 
					$('#img_ultima_noticia').parent('a').attr('href', href);
					$('#img_ultima_noticia').parent('a').attr('title', title);
					$('#img_ultima_noticia').css({'display':'none', 'margin-top':0});
					$('#img_ultima_noticia').attr('src', src);
					$('#img_ultima_noticia').fadeIn(350);
				}
			}
			img = null;
		}
	}
	
	$('.ultimas_noticias li').bind('mouseover', function(){
		if(!$(this).is('.foco')){
			trocaNoticia($(this));
		}
	});
	/*-noticias*/
	
	/*BANNER EVENTOS*/
	$('#banner').jshowoff({
		animatePause: false,
		changeSpeed: 800,
		controls: false,
		links: false,
		speed: 3000
	});
	
	/*
	$('a.banner').hide(0);
	$('a.banner').eq(0).show(0).addClass('evento_active');
	id_banners = setInterval(function(){
			obj = $('#banner a.banner:visible');
			obj.fadeOut(350);
			if(obj.next('a.banner').length){
				trocaEvento(obj.next('a.banner'));
			}else{
				trocaEvento($('a.banner').eq(0));
			}
		}, 3000);
	
	function trocaEvento(obj){
		if(!obj.is(':visible')){
			$('a.banner').css({'display':'none'});
			//$('a.banner').hide(0);
			obj.fadeIn(350).addClass('evento_active');
		}
	}
	$('a.banner').hide(0);
	$('a.banner').eq(0).show(0);;
	$('a.banner').eq(0).addClass('evento_active');
	id_banners = setInterval(function(){
			obj = $('#banner a.evento_active');
			obj.fadeOut(350);
			if(obj.next('a.banner').length){
				trocaEvento(obj.next('a.banner'));
			}else{
				trocaEvento($('a.banner').eq(0));
			}
		}, 3000);
	
	function trocaEvento(obj){
		if(!obj.is('.evento_active')){
			$('a.banner').css({'display':'none'}).removeClass('evento_active');
			obj.fadeIn(350).addClass('evento_active');
		}
	}
	*/
	/*BANNER EVENTOS*/
	
	/*CALENDARIO*/
	
	$('a.eventos_ajax_trigger').click(function(e){
		e.preventDefault();
	});
		
	
	 var hideDelay = 500;
	 var hideTimer = null;
	 var container = $('<div id="eventos_ajax_container"><div id="eventos_ajax_content"></div></div>');

	 $('body').append(container);

	  $('.eventos_ajax_trigger').live('mouseover', function()
	  {
		  $('#eventos_ajax_container').html('<img src="' + base + 'imagens/estrutura/ajax-loader.gif" alt="Carregando..." />"');
	      $('#eventos_ajax_container').css({'background':'none', 'border':'none'});
	      if (hideTimer)
	          clearTimeout(hideTimer);
	      
	      var pos = $(this).offset();
	      var width = $(this).width();
	      container.css({
	          left: (pos.left + width + 5) + 'px',
	          top: pos.top - 30 + 'px'
	      });
	      	
	      data = $(this).attr('rel');
	      
	      $.ajax({
	          type: 'GET',
	          url: base + 'async/eventos.php',
	          data: 'data=' + data,
	          success: function(resultado)
	          {		  
	    	  	$('#eventos_ajax_container').css({'background':'#5d3d64', 'border':'1px solid #000', 'padding':'4px 14px 5px 6px'});
	            $('#eventos_ajax_container').html(resultado);
	          }
	      });
	      container.css('display', 'block');
	  });

	  $('.eventos_ajax_trigger').live('mouseout', function()
	  {	
	      if (hideTimer)
	          clearTimeout(hideTimer);
	      hideTimer = setTimeout(function()
	      {
	          container.css('display', 'none');
	      }, hideDelay);
	  });

	  $('#eventos_ajax_container').mouseover(function()
	  {
	      if (hideTimer)
	          clearTimeout(hideTimer);
	  });

	  $('#eventos_ajax_container').mouseout(function()
	  {
	      if (hideTimer)
	          clearTimeout(hideTimer);
	      hideTimer = setTimeout(function()
	      {
	          container.css('display', 'none');
	      }, hideDelay);
	  });
	  /*CALENDARIO*/
	  
	  /*NAVEGACAO CALENDARIO*/
		$('body').delegate('a.prev', 'click', function(event){
			if(nav.indexOf('MSIE 7.0')!=-1){
				data = $(this).attr('href');
				ultimo = ($(this).attr('href').lastIndexOf('/'));
				data = $(this).attr('href').substring(ultimo + 1, ultimo + 8);
				data = data.split('-');
			}else{
				data = $(this).attr('href').split('-');
			}
			event.preventDefault();
			$('#calendario').empty().html('<div class="loader"><img style="margin-left:85px;margin-top:50px;" src="' + base + 'imagens/estrutura/ajax-loader.gif" alt="Carregando..." /></div>');
			$.ajax({
				type: 'GET',
				url: base + 'async/calendario.php',
				cache: false,
				data: 'mes=' + data[0] + '&ano=' + data[1] + '&idioma=' + idioma,
				success: function(html){
					$("#calendario").html(html);
				}
			});
		});
		$('body').delegate('a.next', 'click', function(event){
			nav = navigator.appVersion;
			if(nav.indexOf('MSIE 7.0')!=-1){
				data = $(this).attr('href');
				ultimo = ($(this).attr('href').lastIndexOf('/'));
				data = $(this).attr('href').substring(ultimo+1,ultimo+8);
				data = data.split('-');
			}else{
				data = $(this).attr('href').split('-');
			}
			event.preventDefault();
			$('#calendario').empty().html('<div class="loader"><img style="margin-left:85px;margin-top:50px;" src="' + base + 'imagens/estrutura/ajax-loader.gif" alt="Carregando..." /></div>');
			$.ajax({
				type: 'GET',
				url: base + 'async/calendario.php',
				cache: false,
				data: 'mes=' + data[0] + '&ano=' + data[1] + '&idioma=' + idioma,
				success: function(html){
					$("#calendario").html(html);
				}
			});
		});
	  /*NAVEGACAO CALENDARIO*/
		
	/*VALIDA FORM*/
		$('#telefone').mask('(99)9999-9999');
		$('#form_fale_conosco').validate({
		rules: {
			nome: 'required',
			email: {
				required: true,
				email: true
			},
			telefone: {
				required: true
			},
			mensagem: 'required'
		},
		messages: {
			nome: null,
			email: {
				required: null,
				email: null
			},
			telefone: null,
			mensagem: null
		}
	});
		$('#form_postais').validate({
			rules: {
				from_email: {
					required: true,
					email: true
				},
				from_name: 'required',
				to_email: {
					required: true,
					email: true
				},
				to_name: 'required',
				subject: 'required',
				message: 'required'
			},
			messages: {
				from_email: {
					required:null,
					email:null
				},
				from_name: null,
				to_email: {
					required:null,
					email:null
				},
				to_name: null,
				subject: null,
				message: null
			}
		});
		$('#form_depoimentos').validate({
			rules: {
				nome: 'required'
			},
			messages: {
				nome: null
			}
		});
	/*VALIDA FORM*/
		
	/*
	var count = 0;
	$('tr').each(function(){
		++count;
		if( count % 2 == 0 ){
			$(this).css({'background':'#f5f5c3'});
		}else{
			$(this).css({'background':'white'});
		}
	});
	*/
	
	$('ul.partes h3.listagem_dinamica').bind('click', function(){
		//if(!$(this).next('ul').is('.partes_aberta')){
		if(!$(this).parent().children('ul').is('.partes_aberta')){
			$('ul.partes_aberta').slideUp('slow').removeClass('partes_aberta');
		//	$(this).next('ul').slideDown('slow').addClass('partes_aberta');
			$(this).parent().children('ul').slideDown('slow').addClass('partes_aberta');
		}else{ 
			$('ul.partes_aberta').slideUp('slow').removeClass('partes_aberta');
		}
	});
	/*form depoimentos*/
	$('button#adicionar_foto').click(function(e){
		e.preventDefault();
		var n = $('#count_f').val();
		if( n < 3 ){
			++n;
			$(this).after('<label for="legenda' + n + '" >Legenda</label><input size="74" name="legenda' + n + '" id="legenda' + n + '" type="text" class="inp" maxlength="255" /><input type="file" name="foto' + n + '" id="foto' + n + '" />');
			$('#count_f').val(n);
		}else{
			$(this).attr('disabled', 'disabled');
			$(this).css({'border':'1px solid #52205C', 'background':'#fff', 'color':'#1E0423'});
		}
	});
	/*form depoimentos*/
	/*depoimentos*/
	$('ul#paginacao li a').click(function(e){
		if(!$(this).is('.active')){
			$('ul#paginacao li a').removeClass('active');
			$(this).addClass('active');
			e.preventDefault();
			var n = $(this).text();
			$.get(
					base + 'async/depoimentos.php', 
					{pagina:n}, 
					function(depoimentos) {
						$('#depoimentos').fadeOut(0, function (){
							$('#depoimentos').fadeIn().html(depoimentos);
							fancyBox();
						});	
					}
				);
		}
	});
	/*depoimentos*/
	$('ul.interface').hide();
	$('.trigger_interface').click(function(e){
		e.preventDefault();
		var t = $('.trigger_interface').length;
		var i = 1;
		for( ; i <= t ; ++i ){
			if($(this).is('.trigger_interface_' + i)){
				if($('ul.interface_' + i).is('.visivel')){
					$('ul.interface_' + i).slideUp(1000).removeClass('visivel');
				}else{
					$('ul.interface').slideUp(1000).removeClass('visivel');
					$('ul.interface_' + i).slideDown(1000).addClass('visivel');
				}
			}
		}
			
	});
});

