


/*function accordion(){
	$('.accordion dt').click(function() {
        if ($(this).next('dd').css('display') == 'none') {
            $('.accordion dt').removeClass('active');
            $(this).addClass('active');
            $('.accordion dd').slideUp();
            $(this).next('dd').slideDown();
        } else {
            $('.accordion dt').removeClass('active');
            $(this).next('dd').slideUp();
        }
    });
}*/

function init(){
	var qtd = $('.accordion dd').size();
	var dd = Array(qtd);
	var indice = $('.accordion dt.active').prevAll('dt').size();	
	for(a = 0; a < qtd; a ++){
		dd['item' + a] = $('.accordion dd:eq('+a+')').height();
		$('.accordion dt.active').next('dd').nextAll('dd').height(0);
		$('.accordion dt.active').next('dd').nextAll('dd').css('border', 'none');
		$('.accordion dt.active').next('dd').nextAll('dd').css('padding', '0 3%');
		
		$('.accordion dt:eq('+a+')').click(function(){
			if($(this).next('dd').height() > 0){
				$('.accordion dt').removeClass('active');
				$(this).next('dd').animate({
					height: 0 + 'px',
					paddingTop: 0 + 'px',
					paddingBottom: 0 + 'px'
				}, 500, function(){
					$(this).animate({
						border: 0					   
					}, 100);
				});
			}else{
				$('.accordion dt').removeClass('active');
				$(this).addClass('active');
				
				$(this).next('dd').prevAll('dd').animate({
					height: 0 + 'px',
					paddingTop: 0 + 'px',
					paddingBottom: 0 + 'px'
				}, 500, function(){
					$(this).animate({
						border: 0					   
					}, 100, function(){
					
					});
				});
				$(this).next('dd').nextAll('dd').animate({
					height: 0 + 'px',
					paddingTop: 0 + 'px',
					paddingBottom: 0 + 'px'
				}, 500, function(){
					$(this).animate({
						border: 0					   
					}, 100, function(){
					
					});
				});
				
				$(this).next('dd').height(0);
				$(this).next('dd').css('border', '1px solid #565757');
				$(this).next('dd').css('padding', '0 3%');
				$(this).next('dd').animate({
					height: dd['item' + indice] + 'px',
					paddingTop: 20 + 'px',
					paddingBottom: 20 + 'px'
				}, 500);
			}
		});
	}
}


var ano;
function historia(){
	var datas = new Array();
	var qtdAno = $('.menu-historia li').size();
	var anos = '';
	for(a = 0; a < qtdAno; a ++){
		datas[a] = $('.menu-historia li:eq('+ a +') a').text();
		anos += '<li>'+ datas[a] +'</li>';
		$('.nav-historia .mask ul').html(anos);
		if(a == qtdAno - 1){
			$('.menu-historia').remove();
		}
		
	}
	
	ano = 0;
	paginaHistoria();
	ConteudoAno(datas[0]);
	
	$('.nav-historia > a').click(function(){
		if($(this).hasClass('sobe')){
			ano -= 1;
			$('.linha-tempo .historia .conteudo').animate({
				top: 300 + 'px',
				opacity: 0
			}, 800, function(){
				$(this).css('top', -20 + 'px');
				ConteudoAno(datas[parseInt(ano)]);
				$('.linha-tempo .historia .conteudo').animate({
					opacity: 1,
					top: 0
				}, 1000);
				$('.nav-historia').height($('.linha-tempo .historia').height() + 60)
			});
		}else{
			ano += 1;
			$('.linha-tempo .historia .conteudo').animate({
				top: -300 + 'px',
				opacity: 0
			}, 800, function(){
				$(this).css('top', 20 + 'px');
				//console.log(datas);
				ConteudoAno(datas[parseInt(ano)]);
				$('.linha-tempo .historia .conteudo').animate({
					opacity: 1,
					top: 0
				}, 1000);
				$('.nav-historia').height($('.linha-tempo .historia').height() + 60)
			});
		}
		paginaHistoria();
		
		$('.nav-historia ul').animate({
			top: ano * -56 + 'px'				  
		}, {duration:1000, easing:'easeOutBack'});
		$('#loading, #spinner').show();

	});
	var barra = setInterval("$('.nav-historia').height($('.linha-tempo .historia').height() + 60);", 500);
}

function paginaHistoria(){
	if(ano == 0){
		$('.nav-historia > .desce').css('visibility', 'visible');
		$('.nav-historia > .sobe').css('visibility', 'hidden');
	}else if(ano == $('.nav-historia ul li').size() - 1){
		$('.nav-historia > .desce').css('visibility', 'hidden');
		$('.nav-historia > .sobe').css('visibility', 'visible');
	}else{
		$('.nav-historia > .setas').css('visibility', 'visible');
	}
}
function ConteudoAno(data){
	$('.linha-tempo .historia .conteudo').load($('base').attr('href') + data + ' form', function(response, status, xhr) {
		if (status == "error") {
			alert('Erro durante o carregamento. Tente novamente.');
		}else{
			$('.linha-tempo .historia .conteudo').ajaxComplete(function(){
				$('#loading, #spinner').hide();	
				$('.nav-historia').height($('.linha-tempo .historia').height() + 40);
			});
			
		}
	});
	
}

function texto(quem){
	$('.como-funciona > div > strong').text(quem.children('img').attr('alt'));
}
function como_funciona(){
	$('.como-funciona ol li').mouseover(function(){
		texto($(this));
		$('.como-funciona ol li:first-child').removeClass('active');
	});
	$('.como-funciona ol li').mouseout(function(){
		texto($('.como-funciona ol li:first-child'));
		$('.como-funciona ol li:first-child').addClass('active');
	});
}

function banners(){
	var params = {
		menu: "false",
		scale: "noScale",
		allowFullscreen: "true",
		allowScriptAccess: "always",
		bgcolor: "#FFFFFF",
		wmode: "transparent"
    };
 
	for (var i = 0; i < arrBanners.banner.length; i++) {
	    var flashvars = {
	        link: arrBanners.banner[i].link ,
	        linkTarget: arrBanners.banner[i].linkTarget   
		};
	    var attributes = {
	        id: "Banner" + (i + 1)
	    };
	    swfobject.embedSWF(arrBanners.banner[i].arquivo, "banner" + (i + 1), "100%", "100%", "7.0.0", "expressInstall.swf", flashvars, params, attributes);
	}
//	var attributes = {
//		id:"Banner2"
//	};
//	swfobject.embedSWF("swf/bannerRacing.swf", "banner2", "100%", "100%", "10.0.0", "expressInstall.swf", flashvars, params, attributes);
//	var attributes = {
//		id:"Banner3"
//	};
//	swfobject.embedSWF("swf/bannerPro.swf", "banner3", "100%", "100%", "10.0.0", "expressInstall.swf", flashvars, params, attributes);
//	var attributes = {
//		id:"Banner4"
//	};
//	swfobject.embedSWF("swf/bannerPowerSports.swf", "banner4", "100%", "100%", "10.0.0", "expressInstall.swf", flashvars, params, attributes);
//	var attributes = {
//		id:"Banner5"
//	};
//	swfobject.embedSWF("swf/bannerExtreme.swf", "banner5", "100%", "100%", "10.0.0", "expressInstall.swf", flashvars, params, attributes);
//	var attributes = {
//		id:"Banner6"
//	};
//	swfobject.embedSWF("swf/bannerFrota.swf", "banner6", "100%", "100%", "10.0.0", "expressInstall.swf", flashvars, params, attributes);
}
function Ativo(){
	$('.item').removeClass('atual');
	$(this).addClass('atual');
	$('#nav-banner li').removeClass('active');
	var banner = $('.item.atual').prevAll().size();	
	$('#' + banner + '').addClass('active');
	$('#' + banner + '').parent().parent().addClass('active');
	
	if($.browser.msie == true){
		$('.atual').html('<div id="banner'+ (banner + 1) +'"></div>')
		banners();
	}
}
function controlador() {
    banners();
    
	if($.browser.msie == true){
		$('#content-banner').cycle({
			fx: 'none',
			timeout: 8000,
			speed:50,
			after: Ativo
		});
	}else{
		$('#content-banner').cycle({
			fx: 'fade',
			timeout: 8000,
			speed: 'fast',
			after: Ativo
		});
	}
	
	$('#nav-banner ul li ul li, #nav-banner ul li.unit').click(function(){
		$('#nav-banner li').removeClass('active');
		$(this).addClass('active');
		$(this).parent().parent().addClass('active');
		$('#content-banner').cycle(parseInt($(this).attr('id')));
	});
}

$(document).ready(function() {
    init();
    como_funciona();
    //$('#nav-banner > ul > li:first-child, #nav-banner ul li:first-child ul li:first-child').addClass('active');

    $('#nav > ul > li').hover(function() {
        $(this).children('.subBox').css('opacity', 0);
        $(this).children('.subBox').css('margin-top', 0);
        $(this).children('.subBox').animate({
            opacity: 1,
            marginTop: 5 + 'px'
        }, 200);
    });

    //historia();
    $('.sidebar #nav-banner li.active').parent().parent().addClass('active');


    $('#btnBusca').click(function() {
        if ($('#txBusca').val()) {
            location.href = $('base').attr('href') + 'busca/?t=' + $('#txBusca').val();
        }
        return false;
    });

    $('#btnBuscaResult').click(function() {
        if ($('#txBuscaResult').val()) {
            location.href = $('base').attr('href') + 'busca/?t=' + $('#txBuscaResult').val();
        }
        return false;
    });

	
	if ($('.content.left ul').hasClass() == false){
		$(this).addClass('list4');
	}
});
				
				
