// JavaScript Document

chama_video('villamaranhao');

function chama_video(nome_video){
	
flashvars_video= {
	file:'http://www.construtoravillamarin.com.br/videos/'+nome_video+'.flv',
	autostart:'false'
}

params_video={
	wmode: 'transparent',
	allowFullScreen: 'true'
}
		
swfobject.embedSWF("swf/player.swf", "video", "330", "253", "9.0.0","expressInstall.swf", flashvars_video, params_video, null);

}

function centraliza_img(class_id,id_produto,alt,larg){		
		altura_img = (alt-$(class_id+' img[id="'+id_produto+'"]').height())/2;
		largura_img = (larg-$(class_id+' img[id="'+id_produto+'"]').width())/2;
		
		if(altura_img >=85){
			altura_img = 0;
		}
		if(largura_img >=85){
			largura_img = 0;
		}

		$(class_id+' img[id="'+id_produto+'"]').css('margin-top' , ''+ Math.round(altura_img) +'px');
		$(class_id+' img[id="'+id_produto+'"]').css('margin-left' , ''+ Math.round(largura_img) +'px');
		
}



function adj(){
	


	empreendimentos('lancamentos')
	
	$(window).load( function() {
		$("#slider, #logo_maranhao").show();
		$("#vitrine_swf #alerta").remove();
		$("#slider").easySlider({
			auto: true, 
			continuous: true,
			numeric: true,
			speed:800,
			pause:6000
		});
	})
}

	function empreendimentos(q_empe){

		$("#recebe_fotos").empty();
		
		//alert(q_empe);
		if (q_empe=="pronto_para_morar" || q_empe=="em_obras"){
		//if (q_empre != "pre_lancamento"){
			//alert(q_empre);
			
			$('#recebe_fotos').html('<div id="alerta">Carregando Imagens...</div><ul class="fotos_destaque"> </ul>');
	
				$.ajax({
				type: "GET",
				url: "xml/itens_categorias.xml",
				dataType: "xml",
				success: function(xml) {
						
						$('#recebe_fotos #alerta').remove();
	
						$(xml).find('categoria[id="'+q_empe+'"]').find('item').each(function(){
							
							var arquivo = $(this).attr('id');
							var nome = $(this).find('nome').text();
							var titulo = $(this).find('titulo').text();
							var info1 = $(this).find('info1').text();
							var info2 = $(this).find('info2').text();
							var info3 = $(this).find('info3').text();
							var info4 = $(this).find('info4').text();
							var descricao =$(this).find('descricao').text();
							
							
							var html = '<li><a href="#empre='+q_empe+'&item='+arquivo+'" name="'+arquivo+'"><div class="div_foto"><img id="foto_'+arquivo+'" src="images/empreendimentos/'+q_empe+'/'+arquivo+'/p/'+arquivo+'_0.jpg" /></div></a><h3>'+nome+'</h3><ul class="subItem_empre"><li>'+titulo+'</li><li>'+info1+'</li><li>'+info2+'</li><li>'+info3+'</li><li>'+info4+'</li><li>'+descricao+'</li></ul></li>';
							
							$(html)
							.appendTo('.fotos_destaque');
	
							$('#foto_'+arquivo).load(function(){
								centraliza_img('.div_foto',$(this).attr('id'),127,171);
							})
			
						});//close each(
				
				$('.fotos_destaque li a').click(function(){	
					abre_detalhes(q_empe, $(this).attr('name'))
				});
				
			}//success
			}) //close $.ajax(
		}
		
		else{
			if ( q_empe=="lancamentos"){

			$('#recebe_fotos').html('<div id="alerta">Carregando Imagens...</div><ul class="fotos_destaque"> </ul>');
			
			$.ajax({
			type: "GET",
			url: "xml/itens_categorias.xml",
			dataType: "xml",
			success: function(xml) {
			
			$('#recebe_fotos #alerta').remove();							
	
			$(xml).find('categoria[id='+q_empe+']').find('item').each(function(){
				
				var arquivo = $(this).attr('id');
				var nome = $(this).find('nome').text();
				var titulo = $(this).find('titulo').text();
				var info1 = $(this).find('info1').text();
				var info2 = $(this).find('info2').text();
				var info3 = $(this).find('info3').text();
				var info4 = $(this).find('info4').text();
				var descricao =$(this).find('descricao').text();
				
				if (arquivo == null){
					arquivo = "../../foto_indisponivel.jpg"
				}
				$('<li><a rel="group" href="images/empreendimentos/'+q_empe+'/'+arquivo+'/g/'+arquivo+'_0.jpg"><div class="div_foto"><img id="foto_'+arquivo+'" src="images/empreendimentos/'+q_empe+'/'+arquivo+'/p/'+arquivo+'_0.jpg" /></div></a><h3>'+titulo+'</h3><ul class="subItem_empre"><li>'+nome+'</li><li>'+info1+'</li><li>'+info2+'</li><li>'+info3+'</li><li>'+info4+'</li><li>'+descricao+'</li></ul></li>')
					.appendTo('.fotos_destaque');
					
					$('#foto_'+arquivo).load(function(){
						centraliza_img('.div_foto',$(this).attr('id'),127,171);
					})
					
				});//close each(
			
				 $(".fotos_destaque li a[rel=group]").fancybox({
					'transitionIn' : 'none',
					'transitionOut' : 'none'
				})

			}//success
			}) //close $.ajax(
				
			}else{
				$('<img src="images/empreendimentos/pre_lancamento/1.jpg"/>').appendTo('#recebe_fotos');
			}
		}

}//function empre
