function swap(target, fname) {
	document[target].src = "fotos/" + fname;
}
$(document).ready(function(){
	$(".simulador").hide();
	$(".simular_show").show();
		$('.simular_show').click(function(){
		$(".simulador").slideToggle();
    });
});
$(function(){
	$('#autoEnviar').click(function(){
		var autoTipo	= $("#autoTipo").val();
		var autoValor	= $("#autoValor").val();
		var autoAno		= $("#autoAno").val();
		var autoEntrada	= $("#autoEntrada").val();
	
		$.post("calculo.result.php",{autoTipo:autoTipo, autoValor:autoValor, autoAno:autoAno, autoEntrada:autoEntrada},
		  function(retorno){
	
			$('.resposta').html(retorno).fadeIn(4000);
		}) 
		return false;
	})
})
$(function(){
	$("#autoEntrada").maskMoney({symbol:"R$", decimal:",", thousands:"."});
	$("#autoValor").maskMoney({symbol:"R$", decimal:",", thousands:"."});
	$("#valor_por").maskMoney({symbol:"R$", decimal:",", thousands:"."});
})
jQuery(function($){
   $("#telefone").mask("(99) 9999-9999");
   $("#celular").mask("(99) 9999-9999");
});

// ---- acorddion ---- //
$(document).ready(function() {
	$('.accordionButton').click(function() {
		$('.accordionButton').removeClass('on');
	 	$('.accordionContent').slideUp('normal');

		if($(this).next().is(':hidden') == true) {
			$(this).addClass('on');
			$(this).next().slideDown('normal');
		 } 
	 });

	$('.accordionButton').mouseover(function() {
		$(this).addClass('over');
	}).mouseout(function() {
		$(this).removeClass('over');										
	});

	$('.accordionContent').hide();
	$("#open").trigger('click');
});
// ---- combo ---- //
$(document).ready(function(){
	$("select[name=marca]").change(function(){
		$("select[name=modelo]").html('<option value="0"><b style="color:#F00">Carregando, aguarde...</b></option>');
				
			$.post("processa.combo.php", {marca:$(this).val()}, function(valor){
			$("select[name=modelo]").html(valor);
			}
		)
	})
})
$(document).ready(function(){
	$("select[name=ano_de]").change(function(){
		$("select[name=ano_ate]").html('<option value="0"><b style="color:#F00">Carregando, aguarde...</b></option>');
				
			$.post("processa.combo.php", {ano_de:$(this).val()}, function(valor){
			$("select[name=ano_ate]").html(valor);
			}
		)
	})
})











/*
$(document).ready(function() {
    var speed = 5000;
    var run = setInterval('rotate()', speed);   
     
    var item_width = $('#slides li').outerWidth(); 
    var left_value = item_width * (0); 
         
    $('#slides li:first').before($('#slides li:last'));
    $('#slides ul').css({'left' : left_value});
 
    $('#prev').click(function() {
        var left_indent = parseInt($('#slides ul').css('left')) + item_width;
        $('#slides ul').animate({'left' : left_indent}, 200,function(){    
            $('#slides li:first').before($('#slides li:last'));           
            $('#slides ul').css({'left' : left_value});
        });
        return false;
    });
 
    $('#next').click(function() {
        var left_indent = parseInt($('#slides ul').css('left')) - item_width;
        $('#slides ul').animate({'left' : left_indent}, 200, function () {
            $('#slides li:last').after($('#slides li:first'));                  
            $('#slides ul').css({'left' : left_value});
        });
        return false;
    });        
     
    $('#slides').hover(
        function() {
            clearInterval(run);
        }, 
        function() {
            run = setInterval('rotate()', speed);   
        }
    ); 
         
});
 
function rotate() {
    $('#next').click();
}
*/

$.fn.infiniteCarousel = function () {

    function repeat(str, num) {
        return new Array( num + 1 ).join( str );
    }
  
    return this.each(function () {
        var $wrapper = $('> div', this).css('overflow', 'hidden'),
            $slider = $wrapper.find('> ul'),
            $items = $slider.find('> li'),
            $single = $items.filter(':first'),
            
            singleWidth = $single.outerWidth(), 
            visible = Math.ceil($wrapper.innerWidth() / singleWidth),
            currentPage = 1,
            pages = Math.ceil($items.length / visible);            


        // 1. Pad so that 'visible' number will always be seen, otherwise create empty items
        if (($items.length % visible) != 0) {
            $slider.append(repeat('<li class="empty" />', visible - ($items.length % visible)));
            $items = $slider.find('> li');
        }

        // 2. Top and tail the list with 'visible' number of items, top has the last section, and tail has the first
        $items.filter(':first').before($items.slice(- visible).clone().addClass('cloned'));
        $items.filter(':last').after($items.slice(0, visible).clone().addClass('cloned'));
        $items = $slider.find('> li'); // reselect
        
        // 3. Set the left position to the first 'real' item
        $wrapper.scrollLeft(singleWidth * visible);
        
        // 4. paging function
        function gotoPage(page) {
            var dir = page < currentPage ? -1 : 1,
                n = Math.abs(currentPage - page),
                left = singleWidth * dir * visible * n;
            
            $wrapper.filter(':not(:animated)').animate({
                scrollLeft : '+=' + left
            }, 500, function () {
                if (page == 0) {
                    $wrapper.scrollLeft(singleWidth * visible * pages);
                    page = pages;
                } else if (page > pages) {
                    $wrapper.scrollLeft(singleWidth * visible);
                    // reset back to start position
                    page = 1;
                } 

                currentPage = page;
            });                
            
            return false;
        }
        
        $wrapper.after('<a class="arrow back"><img src="images/prev.png" border="0" /></a><a class="arrow forward"><img src="images/next.png" border="0" /></a>');
        
        // 5. Bind to the forward and back buttons
        $('a.back', this).click(function () {
            return gotoPage(currentPage - 1);                
        });
        
        $('a.forward', this).click(function () {
            return gotoPage(currentPage + 1);
        });
        
        // create a public interface to move to a specific page
        $(this).bind('goto', function (event, page) {
            gotoPage(page);
        });
    });  
};

$(document).ready(function () {
  $('.carousel').infiniteCarousel();
});
