jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
	return -c * ((t=t/d-1)*t*t*t - 1) + b;
};
jQuery(function( $ ){
	$('#buttons .prev img').hover(function(){ $(this).attr('src','images/bon.png'); } , function(){ $(this).attr('src','images/boff.png'); });
	$('#buttons .next img').hover(function(){ $(this).attr('src','images/fon.png'); } , function(){ $(this).attr('src','images/foff.png'); });

	if($.browser.msie && jQuery.browser.version - 7.0 <= 0) $(".star").css({"margin":"2px 0 0 2px"});


	$('.lateral').hover(doItem,undoItem);
	$('.lateral').click(function(){ 
		disableimg();
		$(this).css("backgroundColor",'#666');
		switch($(this).attr('id')){
			case 'carro':
				$("img",this).attr('src','images/carroON.jpg');
				mudarconteudo(1);
				break;
			case 'moto':
				$("img",this).attr('src','images/motoON.jpg');
				mudarconteudo(2);
				break;
			case 'utilitario':
				$("img",this).attr('src','images/utilitarioON.jpg');
				mudarconteudo(3);
				break;
		}
	});
	$('#slideshow').serialScroll({
		items:'li',
		prev:'#screen a.prev',
		next:'#screen a.next',
		offset:-230, //when scrolling to photo, stop 230 before reaching it (from the left)
		start:2, //as we are centering it, start at the 2nd
		duration:1200,
		force:true,
		stop:true,
		lock:false,
		cycle:false, //don't pull back once you reach the end
		easing:'easeOutQuart', //use this easing equation for a funny effect
		jump: false //click on the images to scroll to them
	});

	$('#fotos').click( function(){
		$('#ourovideo').slideUp('fast');
		$('#ouropreto').fadeIn('slow');
		$('#screen').fadeIn('slow');
	});
	$('#video').click( function(){
		$('#ouropreto').slideUp('fast');
		$('#screen').slideUp('fast');
		$('#ourovideo').fadeIn('slow');
	});
	$('#enviar').click( function(){
		if($('#email').val().search('@') < 0){ alert("por favor , coloque um email valido"); return 0 ;}	
		if(!$('#nome').val()){ alert("Por favor, insira um nome"); return 0 }
		if(!$('#email').val()){ alert("Por favor, insira um email"); return 0 }
		if(!$('#mensagem').val()){ alert("Por favor, insira uma mensagem"); return 0 }
		$('#enviar').val("Enviando");
		$('#enviar').attr("disabled","disabled");
	    	data = "contato=1&nome=" + $('#nome').val() + "&email=" + $('#email').val() + "&mensagem=" + $('#mensagem').val() + "&url=" + window.location;
		$.ajax({
   			url: 'index.php',
			data: data,
			type: 'POST',
			dataType: 'text',
			timeout: 10000,
 			error: function(){ 
						$('#enviar').val("Enviar");
						$('#enviar').attr("disabled","");
						alert('Algum erro ocorreu, tente mais tarde.'); 
			},
			success: function(x){
					 if(x == 1) { 
						alert("falha ao enviar a mensagem , tente mais tarde.");
						$('#enviar').val("Enviar");
						$('#enviar').attr("disabled","");
						
                    			 }
					 if(x == 2) {
						alert("Mensagem enviada com sucesso, em até 24horas um vendedor irá retornar em seu email. Agradecemos a mensagem.");
						$('#enviar').val("OK !!");
				 	}
			 }
		});
	});
});
function mudarconteudo(x){
	if(x == 1) { 
		$("#cabecalho").html("Procure na seção de automóveis"); 
		$("#tipo_veiculo").val('1');
	}
	else if(x == 2) { 
		$("#cabecalho").html("Procure na seção de motos"); 
		$("#tipo_veiculo").val('4');
	} 
	else if(x == 3) { 
		$("#cabecalho").html("Procure na seção de utilitários"); 
		$("#tipo_veiculo").val('11');
	}
	
}
function disableimg(){
	$(".lateral#carro img").attr("src","images/carroOFF.jpg"); $(".lateral#carro").css("backgroundColor",'#454545');
	$(".lateral#moto img").attr("src","images/motoOFF.jpg"); $(".lateral#moto").css("backgroundColor",'#454545');
	$(".lateral#utilitario img").attr("src","images/utilitarioOFF.jpg"); $(".lateral#utilitario").css("backgroundColor",'#454545');

}
function doItem(){ $(this).css("backgroundColor",'#666'); }
function undoItem(){ 
		if($("img",this).attr('src').search('ON') > 0) return 0;
		else $(this).css("backgroundColor",'#454545'); 
}

function flash(arqflash,largura,altura) {
document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="' + largura + '" height="' + altura + '">');
document.write('<param name="movie" value="' + arqflash + '" />');
document.write('<param name="quality" value="high" />');
document.write('<param name="menu" value="false" />');
document.write('<param name="wmode" value="transparent" />');
document.write('<embed src="' + arqflash + '" width="' + largura + '" height="' + altura + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" menu="false" wmode="transparent"></embed>');
document.write('</object>');
}

function AbreJanela(url) {
          window.open(url);
}
function changeOver(obj,color) { obj.style.backgroundColor=color; }

