// ajax

function ajax(url,name){

	//carregador
	var alvo = $('#in');
	$('#loading').fadeIn(function(){

		alvo.load(url+' #page-loaded',function(){

			$('#loading').fadeOut('slow');
			jresize();

			//body class
			var bodyClass = $('body').removeAttr('class').addClass(name);

			if(name != 'inicio'){
				$('#rodape').animate({
					'bottom':'-50px'
				});
			}

			if(name == 'home'){
				$('#rodape').animate({
					'bottom':'0'
				},'slow');
				if($('html').height() <= 800){
					$('#banner').css({marginTop : '90px'});
				}
				if($('html').width() <= 1080){
					$('#banner').css({marginTop : '111px'});
				}
				//innerfade
				$('ul#rotativo').innerfade({
					speed: 1000,
					timeout: 5000,
					type: 'sequence',
					containerheight: '1000px'
				});
				//innerfade
			}

			if(name == 'Entregues'){
				$('.categorias-pct a[name=Entregues]').addClass('ativo');
			}

			if(name == 'Em-Obra'){
				$('.categorias-pct a[name=Em-Obra]').addClass('ativo');
			}

			if(name == 'Em obra'){
				$('.categorias-pct a[name=Em-Obra]').addClass('ativo');
			}

			if(name == 'Futuros-Empreendimentos'){
				$('.categorias-pct a[name=Futuros-Empreendimentos]').addClass('ativo');
			}

			if(name == 'Futuros empreendimentos'){
				$('.categorias-pct a[name=Futuros-Empreendimentos]').addClass('ativo');
			}

			if(name == 'Lançamentos'){
				$('.categorias-pct a[name=Lançamentos]').addClass('ativo');
			}

			//body class
			
			
			//empresa
			if(name == 'empresa'){
				if($('html').width() >= '1280')
				$('.jspPane').width('1280');
			}
			//empresa
			
			
			//contato
			$('.fone').mask("(99) 9999-9999");
			$('#form fieldset.botoes').append('<div><input class="radio" name="receber" type="checkbox" id="receber" /> <label for="receber">Desejo receber as novidades da Mendes Sibara</label></div>');
			if(name == 'contato'){
				$("#mapC").gMap({
					zoom:16,
					markers:[{
						latitude: '-26.91502906291461',
						longitude: '-48.65323305130005',
						icon:{
							image: "images/seta_google_map.png",
							shadow: false,
							iconsize: [64, 64],
							shadowsize: false,
							iconanchor: [22, 63],
							infowindowanchor: [2, 2]
						}
					}]
				});
			}
			//contato
			
			
			//videos
			$('.listar.videos a.left').hover(function(){
				$(this).find('img').fadeTo('slow',0.5);
				$(this).append('<span></span>');
				$(this).find('span').fadeIn('slow');
			},function(){
				$(this).find('img').fadeTo('slow',1);
				$(this).find('span').remove();
			});
			//videos
			
			if(name == 'ver-empreendimento'){
				//google mapa
				var  m1y = $('#cy_gmapsgeocode').val();
				var  m1x = $('#cx_gmapsgeocode').val();
				
				var  m2y = $('#cy_gmapsplantgeocode').val();
				var  m2x = $('#cx_gmapsplantgeocode').val();

				$("#map").gMap({
					zoom:16,
					markers:	[{latitude: m1y, longitude: m1x, html: ""}]
				});
				//google mapa
				
				//cronograma
				//crio as variaveis
				var lF = $('#cronograma span.left.f span');
				var lA = $('#cronograma span.left.a span');
				var lE = $('#cronograma span.left.e span');
				
				//pego os valores dos campos
				var rF = $('#cronograma span.right.f').html();
				var rA = $('#cronograma span.right.a').html();
				var rE = $('#cronograma span.right.e').html();
				
				//trato os valores
				/*var strF = rF.replace("%"," ");
				var strA = rA.replace("%"," ");
				var strE = rE.replace("%"," ");*/
				
				//calculo
				/*var cF = strF - 13;
				var cA = strA - 13;
				var cE = strE - 13;*/

				$('.menu-guia a').live('click',function(){
					if($(this).html() == 'Empreendimento'){
						lF.delay(500).animate({
							width:rF,
							opacity:1
						},2000);
						lA.delay(500).animate({
							width:rA,
							opacity:1
						},2000);
						lE.delay(500).animate({
							width:rE,
							opacity:1
						},2000);
					}
				});
				//cronograma
				
				//innerfade
				$('div#rotativo2').innerfade({
					speed: 1000,
					timeout: 5000,
					type: 'sequence',
					containerheight: '200px'
				});
				//innerfade
			}

			fotoResize();
			
			//prettyPhoto
			$("a[rel^='prettyPhoto']").prettyPhoto({
				animationSpeed:'slow',
				theme:'facebook',
				slideshow:3000,
				autoplay_slideshow: false
			});
			//prettyPhoto
			
			
			//guias
			$('.menu-guia a').live('click',function() {
				var name = $(this).attr('name');
				$('.menu-guia').find('a.a').addClass('d').removeClass('a');
				$(this).removeClass('d').addClass('a');
				$('.guias').find('div.guia').hide();
				$('.guias div#'+name).show();
				return false
			});
			
			$('.guias a[name=plantao]').live('click',function(){
				$(this).fadeOut('slow');
				$('#plantao-vendas').delay(100).fadeIn('slow');
				return false
			});
			//guias
	
	
			//ajustes lista ol e ul
			$('.lista ul li:last, .lista ol li:last, ul.lista li:last, ol.lista li:last, ol.links li:last, #ver-mapa article:last, #navL a:last').css({
				marginBottom:0
			});
			$('.listar li:last,#ver-empreendimento ul.listar.lista li:odd').css({
				marginRight:0
			});
			//ajustes lista ol e ul	
		});
	});
}


//janela
/*function janela(){
	window.open('index.php','Mendes','toolbar=no,status=no,resizable=no,scrollbars=no,menubar=no,fullscreen=1');
}*/
function fotoResize(){
	//configurações gerais
	var w = $('html').width();
	var h = $('html').height();
	var listarEmp = $('ol.empreendimentos *,ol.empreendimentos.tam24 *');
	var fotos = $('.fotos img,.fotos a');
	var plantas = $('.plantas a, .plantas img');
	//form
	if(h >= 560 && h <= 700){
		$('fieldset.padrao input,fieldset.padrao select,fieldset.padrao textarea,fieldset.botoes .bt')
		.css({'font-size':'11px'});
		$('fieldset.padrao input,fieldset.padrao textarea,fieldset.padrao select').css({'padding':'0 1px'});
		
		if(h >= 560 && h <= 604){
			$('fieldset.padrao textarea').height(70);
			$('#form textarea').height(50);
		}
		if(h >= 605 && h <= 700){
			$('#form textarea').height(75);
		}
	}
	
	//font
	if(w >= 1000 && w <= 1150){
		listarEmp.css({'font-size':'11px'});
		$('#guia1').css({'font-size':'11px'});
	}
}

//resize de janela
function jresize(){
	var w = $('html').width();
	var h = $('html').height();
	var scrollPane = $('.scroll-pane-arrows');
	var newW = w - 50;
	var newH = h - 270;
	var newH2 = newH - 100;
	scrollPane.width(newW).height(newH).css({
		'padding-bottom':'100px'
	});
	$('#mapC').height(newH2);
	//jScrollPane
	$('.scroll-pane-arrows').jScrollPane({
		showArrows: true,
		horizontalGutter: 30
	});
	//jScrollPane	
}


//jquery
$(function(){
	
	var re = new RegExp(/pagina\/([a-z-]+)($|\/)/);
	var m = re.exec(window.location);
	//alert(m[1]);
	/*if(m != 'undefined'){
		ajax(window.location,m[1]);
	}*/
	$('#galeriaMuda').live('change',function(){

		var id = $(this).val();

		$.ajax({
			url : "mudaGaleria.php",
			data : 'id='+id,
			success : function(data, textStatus, jqXHR){
				fotoResize();
				$('#alvoGaleria').html(data);
				$("a[rel^='prettyPhoto']").prettyPhoto({
					animationSpeed:'slow',
					theme:'facebook',
					slideshow:3000,
					autoplay_slideshow: false
				});
			}
		});
	});


	//ajax
	$('a[rel=ajax]').live('click',function(){
		var url = $(this).attr('href');
		var name = $(this).attr('name');
		ajax(url,name);
		$(this).parent().parent().find('a.ativo').removeClass('ativo');
		$(this).addClass('ativo');
		return false;
	});
	//ajax
	

	//innerfade
	$('ul#rotativo').innerfade({
		speed: 1000,
		timeout: 5000,
		type: 'sequence',
		containerheight: '970px'
	});
	$('div#rotativo2').innerfade({
		speed: 1000,
		timeout: 5000,
		type: 'sequence',
		containerheight: '200px'
	});
	//innerfade
	
	
	//banner
	if($('html').height() <= 800){
		$('#banner').css({marginTop:'90px'});
	}
	if($('html').width() <= 1080){
		$('#banner').css({marginTop:'111px'});
	}
	if($('html').height() >= 930 && $('html').height() <= 950){
		$('#banner').css({marginTop:'97px'});
		$('#rodape').css({height:'118px'});
		$('#rodape h1').css({bottom:'28px'});
		$('#arroba').css({bottom:'30px'});
	}
	//banner
	
	
	//rodape.delay(3000).animate
	$('#rodape').delay(3000).animate({
		bottom:'0'
	},2000,function(){
		$(this).find('h1').fadeIn(1200);
	});
	//rodape

	$(window).resize(function(){
		jresize()
	}).trigger('resize');

	$('#navH.j2 a').hover(function(){
			$(this).find('span.bg').stop().fadeTo('slow',1);
		},function(){
			$(this).find('span.bg').stop().fadeTo('slow',0);
	});

});
