//google font
WebFontConfig = {
    google: { families: [ 'Lato:100:latin' ] }
  };
  (function() {
    var wf = document.createElement('script');
    wf.src = ('https:' == document.location.protocol ? 'https' : 'http') +
      '://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
    wf.type = 'text/javascript';
    wf.async = 'true';
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(wf, s);
  })();

//nav
$(".nav_sub_contents div:last-child").prev().addClass("last");
 $(".feature #meta_nav li:last-child, #content .col_highlight_two li:last-child, #content .sublinks li:last-child, #content .trio_list ul li:last-child, .product_index_alt #content .highlights .highlight:last-child, .table_comparison thead th:last-child, .solution_index #content .solution_list li:last-child, #content .rac_sublinks li:last-child, #industry_experts p:last-child, header ul#nav li.highlight:last-child").addClass("last-child");
 $("header ul#nav > li:not(.highlight)").hover(function(){
	if($(this).children("div").length > 0){
		$(this).addClass("active");
	}
},
function(){
	$(this).removeClass();
});
 
 
  function bannerFadeIn(index){
	$("#banners .wrap > div:eq("+index+")").fadeIn();
	$("#banner_nav a").click(function(){
		bannerClick($(this).index());
		return false;
	});
}

var bannerArray = [];
function bannerClick(pos){
	$("#banner_nav a").unbind("click");
	banner_timer = 0;
	var index = parseInt($("#banner_nav a:eq("+pos+")").index());
	
	var params = $("#banners .wrap > div:eq("+pos+") a").attr("href").split("?");
	for(var i = 0; i < params.length; i++) {
		var param = params[i].split("=");
		if(param[0] == "s_gaevent") {
			var gaevent = param[1];
		}
	}
    
	$("#banner_nav .active").removeClass("active");
	$("#banner_nav a:eq("+pos+")").addClass("active");
	
	if($("#banners .wrap > div:visible:not(#banner_nav)").length > 0){ //there are visible banners
		$("#banners .wrap > div:visible:not(#banner_nav)").fadeOut(function(){
			bannerFadeIn(index);
		});
	}
	else{
		bannerFadeIn(index);
	}
	
	return false;
}

//banners
if($("#banners .banner").length > 1){
	
	$("#banners .banner:last").after('<div id="banner_nav"></div>');
	var banner_counter = 0;
	$(".banner").each(function(){
		$("#banner_nav").append('<a href="#"></a>');
		banner_counter++;
	});
	$("#banner_nav a:first").addClass("active");

	$("#banner_nav a").click(function(){
		bannerClick($(this).index());
		return false;
	});
	
	//auto-rotacao
	setInterval(function(){ 
		if(banner_timer == 10){ //segundos
			var index = parseInt($("#banner_nav a.active").index()) + 1;
			if(index < $("#banner_nav a").length)
				$("#banner_nav a:eq("+index+")").click();
			else
				$("#banner_nav a:first").click();
			banner_timer = 0;
		}
		banner_timer++;
	}, 1000);
	
	bannerClick(0); //inicia	
}
else{
	$("#banners .banner:first").show()
}

//colorbox
$(document).ready(function(){
    /*$(".link_social").colorbox({width:"95%", inline:true, href:".social"});
    $(".link_institucional").colorbox({width:"95%", inline:true, href:".institucional"});*/
    $(".link_institucional").click(function(){
        $(".trial_content_sub").removeClass('trial_content_sub').addClass('trial_content_sub_ext');
        $(".init").fadeOut(500);
        $(".social").fadeOut(500);
        $(".ouvidoria").fadeOut(500);
        $(".institucional").fadeIn(500);
    });
    
    $(".link_social").click(function(){
        $(".trial_content_sub").removeClass('trial_content_sub').addClass('trial_content_sub_ext');
        $(".init").fadeOut(500);
        $(".institucional").fadeOut(500);
        $(".ouvidoria").fadeOut(500);
        $(".social").fadeIn(500);
    });
    
    $(".link_ouvidoria").click(function(){
        $(".trial_content_sub").removeClass('trial_content_sub').addClass('trial_content_sub_ext');
        $(".init").fadeOut(500);
        $(".social").fadeOut(500);
        $(".institucional").fadeOut(500);
        $(".ouvidoria").fadeIn(500);
    });
});

//qtip
$(document).ready(function(){
    $('#success_one').qtip({content: 'G Laffitte'});
    $('#success_two').qtip({content: 'Supermercados Schmit'});
    $('#success_thr').qtip({content: 'Speed Motors'});
    $('#success_fou').qtip({content: 'Marambaia Ve&iacute;culos'});
});
