// JavaScript Document

function ajax(url){
	alvo = $('#in');
	alvo.load(url+' #page-loaded',function(){
		
		//mycarousel
		$('#mycarousel-fotos').jcarousel({
			scroll:2,
			animation:'slow',
			auto: 0,
			wrap: 'circular'
		});
		
		//fotos
		$('#mycarousel-fotos a').live('click',function(){
			
			var img = $(this).attr('href');
			var legenda = $(this).find('img').attr('alt');
			
			$('#loading').fadeIn();
			$('#ver-foto-produto').find('img').fadeOut(1000,function(){
				$(this).remove();
			});
			
			$('#ver-foto-produto').append('<img />');
			$('#ver-foto-produto img').hide().attr('src', img).fadeIn(1000).load(function(){
				$('#loading').fadeOut();
			});
			
			$('#legenda-produto span').fadeOut('fast',function(){
				$(this).remove();
			});
			$('#legenda-produto').append('<span></span>').fadeIn('fast').text(legenda);
			
			return false;
		});
		
		//prettyPhoto
		$("a[rel^='prettyPhoto']").prettyPhoto({
			animationSpeed:'slow',
			theme:'dark_square',
			slideshow:2000,
			autoplay_slideshow: false
		});
	});
}

$(function(){
	//$(window).load(function(){
	
	//banner
	$('#rotativo').after('<div id="nav-banner"></div>').cycle({
		fx: 'fade',
		easingIn:'easeInCubic',
		easingOut:'easeOutCubic',
		speed: 1500,
		timeout: 5000,
		pager:'#nav-banner'
	});
	$('#rotativo2').cycle({
		fx: 'fade',
		easingIn:'easeInCubic',
		speed: 1500,
		timeout: 6000
	});
	//});
	//banner
	
	
	//mycarousel
	$('#mycarousel').jcarousel({
		scroll:2,
		animation:'slow',
		auto: 0,
		wrap: 'circular'
	});
	$('#mycarousel a').hover(function(){
		$(this).find("span").animate({opacity: .9, top: "0"}, "slow");
	}, function() {
		$(this).find("span").animate({opacity: 0, top: "-85px"}, "slow");
	});
	
	$('#mycarousel a[rel=ajax]').live('click',function(){
		var url = $(this).attr('href');
		ajax(url);
		return false;
	});
	
	$('#mycarousel-fotos').jcarousel({
		scroll:2,
		animation:'slow',
		auto: 0,
		wrap: 'circular'
	});

	//fotos
	$('#mycarousel-fotos a').live('click',function(){

		var img = $(this).attr('href');
		var legenda = $(this).find('img').attr('alt');

		$('#loading').fadeIn();
		$('#ver-foto-produto').find('img').fadeOut(1000,function(){
			$(this).remove();
		});

		$('#ver-foto-produto').append('<img />');
		$('#ver-foto-produto img').hide().attr('src', img).fadeIn(1000).load(function(){
			$('#loading').fadeOut();
		});

		$('#legenda-produto span').fadeOut('fast',function(){
			$(this).remove();
		});
		$('#legenda-produto').append('<span></span>').fadeIn('fast').text(legenda);

		return false;
	});

	//prettyPhoto
	$("a[rel^='prettyPhoto']").prettyPhoto({
		animationSpeed:'slow',
		theme:'dark_square',
		slideshow:2000,
		autoplay_slideshow: false
	});
	//mycarousel
	
	
	//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').css({
		marginRight:0
	});
	//ajustes lista ol e ul
	
	
	//opera
	if($.browser.opera){
		$('.tam25.coluna').css({
			width:'25%'
		});

		$('ol.produtos li').css({
			marginLeft:'1%'
		});
		
		$('#newsletter .bt').css({
			bottom:'1px',
			right:'-45px' 
		});
	}
	//opera
	
	
	//webkit
	if($.browser.webkit){
		$('.tam25.coluna').css({
			marginLeft:'1.3%',
			width:'24.7%'
		});
		$('#newsletter button').css({
			'margin-top':'5px'
			
		});
	}
	//webkit
	
	
	//contato
	$('.fone').mask("(99) 9999-9999");
	$('.cpf').mask("999.999.999-99");
	$('.cnpj').mask("99.999.999/9999-99");
	$('.data').mask("99/99/9999");
	
	
	//faq
	$('.accordion dt').live('click',function() {
		$(this).parent().parent().find('dt').removeClass('ativo');
		$(this).addClass('ativo');
		if($(this).next().is(':visible')){
			$(this).next().slideUp('slow');
			$(this).removeClass('ativo');
		} else {
			$('.accordion dd').slideUp('slow');
			$(this).next().slideToggle('slow');
		}
	}).next().hide();
	$('.accordion dt.ativo').show(function(){
		$(this).next().show();
	});
	//faq
	

	//myPopup
	/*$("a.myPopup").open({
		width: 400,
		height: 300,
		scrollbars: false
	});*/
	//myPopup


	//newsletter
	$('#newsletter').submit(function(){
		var form = $(this).serialize();
		$.ajax({
			url : url_site+'newsletter.php',
			dataType : 'html',
			data : form,
			type : 'POST',
			success : function(data){
				if(data == 'Email Inválido'){
					$('#newsletter .r').addClass('aviso negativo').html(data).fadeIn().delay(1000).fadeOut(function(){
						$(this).removeClass('aviso negativo');
					});
				}else{
					$('#newsletter').find('input').val('');
					$('#newsletter .r').addClass('aviso positivo').html(data).fadeIn().delay(1000).fadeOut(function(){
						$(this).removeClass('aviso positivo');
					});
				}
			}
		});
		return false;
	});
	//newsletter


	//login
	/*$('#flogin').val('login');
	$('#flogin').focusin(function(){
		val = $(this).val();
		if(val != ''){
			val;
		}
		if(val == 'login'){
			$(this).val('');
		}
	});
	$('#flogin').focusout(function(){
		val = $(this).val();
		if(val == '' || val == 'login' ){
			$(this).val('login');
		}
	});

	$('#fsenha').val('senha');
	$('#fsenha').focusin(function(){
		val = $(this).val();
		if(val != ''){
			val;
		}
		if(val == 'senha'){
			$(this).val('');
		}
	});
	$('#fsenha').focusout(function(){
		val = $(this).val();
		if(val == '' || val == 'senha' ){
			$(this).val('senha');
		}
	});*/
	
	//painel login
	/*$('#slide').click(function(){
		$("#painel").slideToggle("slow");
		$("#painel input,#painel button").fadeToggle("slow");
		$(this).toggleClass("ativo");
		return false;
	});
	
	$('#painel').submit(function(){
		var form = $(this).serialize();
		$.ajax({
			url : url_site+'envia.php',
			dataType : 'html',
			data : form,
			type : 'POST',
			success : function(data){
				if(data == 'Email Inválido'){
					$('#painel .r').addClass('aviso negativo').html(data).fadeIn().delay(1000).fadeOut(function(){
						$(this).removeClass('negativo');
					});
				}else{
					$('#painel .r').addClass('aviso positivo').html(data).fadeIn().delay(1000).fadeOut(function(){
						$(this).removeClass('positivo');
					});
				}
				}
			});
	return false;
	});*/
	//login
	
	
	//cotação
	/*$.get('puxa_cotacao.php', function(data) {
		
		$('#cotacao').html(data);
		$('#cotacao tr:odd').css({
			backgroundColor:'#fafafa'
		});
		$('#cotacao td:odd').css({
			textAlign:'right'
		});
	});*/
	//cotação
	
	
	//mapa
	/*$('#map a.hover').fadeTo('slow',0.4);
	$('#map a.hover').hover(function(){
		$(this).fadeTo('slow',1);
	},function(){
		$(this).fadeTo('slow',0.4);
	});
	//pelo link
	$('#map a.hover').click(function(){
		$(this).parent().parent().find('a.ativo').removeClass('ativo');
		$(this).addClass('ativo');
		title = $(this).attr('title');
		$.ajax({
			url:url_site+'listar-unidades.php',
			dataType:'html',
			data:{uf:title},
			type:'GET',
			success:function(data){
				$('#ver-mapa').html(data);
			}
		});
		return false;
	});*/
	//pelo select
	/*$('#festados').change(function(){
		uf = $(this).find('option:selected').val();
		$.ajax({
			url:url_site+'listar-unidades.php',
			dataType:'html',
			data:{uf:uf},
			type:'GET',
			success:function(data){
				$('#ver-mapa').html(data);
			}
		});
	});*/
	//mapa
	
	
	//alpha
	$('.alpha').hover(function(){
		$(this).find('img').fadeTo(300,0.8);
	},function(){
		$(this).find('img').fadeTo(300,1);
	});
	$('.alpha2').hover(function(){
		$(this).fadeTo(300,0.7);
	},function(){
		$(this).fadeTo(300,1);
	});
	//alpha
	
	
	//prettyPhoto
	$("a[rel^='prettyPhoto']").prettyPhoto({
		animationSpeed:'slow',
		theme:'dark_square',
		slideshow:2000,
		autoplay_slideshow: false
	});
	//prettyPhoto
	
});
