// JavaScript Document
params = {
	wmode: 'transparent'
}

swfobject.embedSWF("swf/banner.swf", "banner", "931", "94", "9.0.0","swf/expressInstall.swf", null, params, null);


function pega_xml(aux_xml)
{
	$('.link_manipulacao').empty();
	$('.jcarousel-skin-tango').empty();
	$.ajax({
	type: "GET",
	url: "xml/" + aux_xml + ".xml",
	dataType: "xml",
	success: function(xml){
		$('.link_' + aux_xml).empty();
		$(xml).find('item').each(function(){
			var linha_unica = '';
			
			if($(this).find('link').text().length <= 9){
				linha_unica = ' class="uma_linha"';
			}
			
			$('<li><a class="'+aux_xml+ $(this).attr('id') + '"  href="#desc_' + aux_xml + '_0' + $(this).attr('id') + '" title="' + $(this).find('link').text() + '">' + $(this).find('link').text() + '</a></li>').appendTo($('.link_' + aux_xml));
		})//close each(
		
		$('.link_' + aux_xml + ' li a').each(function(){
			if($(this).text().length<=9){
				$(this).addClass('uma_linha')
			}
		})
		
		$('.link_' + aux_xml + ' li a').click(function(){
			
			$('.link_' + aux_xml + ' li a').animate({backgroundPosition:"(0 0)", paddingTop:'10px',height:'49px'}, {duration:500});
			
			$(this).stop().delay(100).animate({backgroundPosition:"(0 -64px)", paddingTop:'10px',height:'49px'}, {duration:500});

			var id = $(this).attr('href').substring(19);
			
			var href = $(this).attr('href');
			
			id = href.substring(href.length-1);
			
			
			var texto = $(xml).find('item[id="' + id + '"]').find('texto').text();
			
			$('.texto .esquerda_rolagem').html(texto);
			
			$('.texto .direita').empty();
			
			$(xml).find('item[id="' + id + '"]').find('imagem').each(function(){
				if( $(this).text() == "anima_banner.swf" ){
					$('.texto .direita').html('<img title="' + $(this).attr('titulo') +' src="#" id="anima_banner" />');
					swfobject.embedSWF("swf/anima_banner.swf", "anima_banner", "425", "340", "9.0.0","swf/expressInstall.swf", null, null, null)					
				}
				else{
					$(//'<h3>' + $(this).attr('titulo') + '</h3>' +
					'<img title="' + $(this).attr('titulo') + '" ' +
					'src="images/' + aux_xml + '/' + $(this).text() + '.jpg">'
					).appendTo($('.texto .direita'));
				}
			});

			
		});
	
	},//success
	
	complete:function(){
		var url = window.location+"";
		url= url.split('#');
		
		if(url[1] != "" && typeof url[1] != "undefined"){
			url[1]  = url[1].replace("desc_" + aux_xml + "_0","")
		
			$("."+aux_xml+url[1]).trigger('click');
		}
	}
	
	}) //close $.ajax(
}

function trigger_fancy(seletor){
	$(seletor).trigger('click');
}

function chama_video(nome_video,autoplay){
	if (autoplay == "true"){

		flashvars_video= {
			file:'http://192.168.0.155/espacovital/public_html/novo/' + nome_video,
			autostart:'true',
			image: 'images/video.jpg'
		}

	}else{
		flashvars_video= {
			file:'http://192.168.0.155/espacovital/public_html/novo/'+ nome_video,
			autostart:'false',
			image: 'images/video.jpg'
		}
	}

	params_video={
		wmode: 'transparent',
		allowFullScreen: 'true'
	}

	swfobject.embedSWF("swf/player.swf", "video", "380", "215", "9.0.0","swf/expressInstall.swf", flashvars_video, params_video, null);
}



$(document).ready(function(){
		$('#newsletter #enviar').click(function(){
			$('#newsletter').validationEngine({
				ajaxSubmit: false,
				success : function(){
					$('#newsletter #email').val('');
					$('#newsletter .alerta').html('Cadastro efetuado com sucesso para receber as novidades da Espa&ccedil;o Vital!');
				}
			})
		})
		
		$('#logo').click(function(){
			window.location = 'home.html';			
		})
						   
		$('.conteudo_princpal ul li a').click(function(){
			chama_video($(this).attr("name"),"true");
		})
		
		chama_video('videos/breve.flv',"false");
			
					
		$('#menu_inf li a').css( {backgroundPosition: "0 24px"} )
		.mouseover(function(){
			//$(this).stop().animate({backgroundPosition:"(0 -58px)",color:"#fff", paddingBottom:"8px", marginTop:"0px"}, {duration:500})
			$(this).stop().animate({backgroundPosition:"(0 -42px)",paddingBottom:"8px", paddingTop:"7px" ,marginTop:"-8px",color:"#fff"}, {duration:500});			
		})
		.mouseout(function(){
			//$(this).stop().animate({backgroundPosition:"(0 0)",color:"#fff", paddingBottom:"0px", marginTop:"7px"}, {duration:500});
			$(this).stop().animate({backgroundPosition:"(0 24px)", paddingTop:"7px" ,paddingBottom:"0px" ,marginTop:"0px",color:"#9f007a"}, {duration:500})

		})
		
		$('.links').fancybox({
			'transitionIn'		: 'elastic',
			'transitionOut'		: 'elastic',
			'speedIn' 			: 300,
			'speedOut' 			: 100,
			'overlayOpacity'    : 0.60,
			'overlayColor'		: '#ddd',
			'titleShow'			: false,
			'autoDimensions'	: true,
			'width'				: 500,
			'height'			: 550,
			'outerColor'		:'#fff'
		});
		
		$("#orcamento,.info_orcamento").fancybox({
			'transitionIn'		: 'elastic',
			'transitionOut'		: 'elastic',
			'speedIn' 			: 300,
			'speedOut' 			: 100,
			'overlayOpacity'    : 0.60,
			'overlayColor'		: '#ddd',
			'type'				: "iframe",
			'titleShow'			: false,
			'frameWidth'		: 500,
			'frameHeight'		: 550,
			'autoDimensions'	: true,
			'width'				: 500,
			'height'			: 550,
			'outerColor'		:'#fff'
		});
		
		$("#onde_estamos").fancybox({
			'transitionIn'		: 'elastic',
			'transitionOut'		: 'elastic',
			'speedIn' 			: 300,
			'speedOut' 			: 100,
			'overlayOpacity'    : 0.60,
			'overlayColor'		: '#ddd',
			'type'				: "iframe",
			'titleShow'			: false,
			'frameWidth'		: 600,
			'frameHeight'		: 600,
			'autoDimensions'	: true,
			'width'				: 600,
			'height'			: 600
		});
		
	$(".vitrine_dicas").easySlider({
		auto: true, 
		continuous: true,
		numeric: true,
		controlsFade:true,
		speed:400,
		pause:8000
	});
	
	jQuery.easing['BounceEaseOut'] = function(p, t, b, c, d){
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t) + b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		}
	};
	
	function pega_produtos(){
		$.ajax({
			type:"get",
			url:"xml/parceiros.xml",
			datatype:"xml",
			success:function(xml){
				
				$('.jcarousel-skin-tango').empty();
				
				/*$(xml).find("parceiros").find('parceiro').each(function(){				
					$('<li><h5>'+$(this).find('nome').text()+'</h5><a href="#"><img src="'+$(this).find('caminho').text()+'.jpg" /></a></li>').appendTo('.jcarousel-skin-tango');				
				});*/
				$(xml).find("parceiros").find('parceiro').each(function(){				
					$('<li><a href="#"><img src="'+$(this).find('caminho').text()+'.jpg" /></a></li>').appendTo('.jcarousel-skin-tango');				
				});
			},
			complete:function(){
				
				function carousel(direcao){
					jQuery('#lista_produto ul').jcarousel({
						animation: 1000,
						auto:2,
						rtl:direcao,
						wrap: 'circular'
    				});
				}
				carousel(false);				
			}
		})
	}

	$('.lista_quadrado li').animate({
	    opacity: 0.50
	})

	$('.lista_quadrado li').mouseover(function(){
		$(this).stop().animate({
	    	opacity: 1
		})
	})
	
	$('.lista_quadrado li').mouseout(function(){
		$(this).stop().animate({
	    	opacity: 0.50
		})
	})
	
	pega_produtos();
	
	
	if ( typeof adj != "undefined" ){
		adj();
	}
})
