// JavaScript

/*PRELOAD PARA ALGUMAS SECÇÕES DE IMAGENS*/

function prev_news(){

            if(jQuery('.news_visible').prev('.single_news_container').length){

                jQuery('.news_visible:not(:animated)').fadeOut(100, function(){
                    jQuery('.news_visible').removeClass('news_visible').prev('.single_news_container').addClass('news_visible').fadeIn(100);
                    var current = parseInt(jQuery('#current_news_num').text());
                    jQuery('#current_news_num').text(current - 1);
                });
            }
}

function next_news(){
            if(jQuery('.news_visible').next('.single_news_container').length){
                jQuery('.news_visible:not(:animated)').fadeOut(100, function(){
                    jQuery('.news_visible').removeClass('news_visible').next('.single_news_container').addClass('news_visible').fadeIn(100);
                    var current = parseInt(jQuery('#current_news_num').text());
                    jQuery('#current_news_num').text(current + 1);
                });
            }
}

//para carregar scripts no arranque da página
jQuery(window).load(function() {
	
	jQuery("#slidestopo").fadeIn(500);
	
	/*ANIMACAO NOTICIAS*/
	jQuery("ul#slidetopo").cycle({
	fx: 'fade',
	speed: 2500,
	cleartype: true, 
	cleartypeNoBg: true
	});
});

function animate_truck_lefttoright()
{
$('#truck').css('left', '-156px');
$('#truckb').css('left', '-156px');
$('#truckb').hide();
$('#truck').show();

$('#truck').animate({
left: '+='+($(window).width())
}, 20000, function() {
// Animation complete.
animate_truck_righttoleft()
});

}

function animate_truck_righttoleft()
{
$('#truck').hide();
$('#truckb').css('left', ($(window).width())-156);
$('#truckb').show();

$('#truckb').animate({
left: '-='+($(window).width())
}, 20000, function() {
// Animation complete.
animate_truck_lefttoright()
});

}

jQuery(document).ready(function(jQuery) {

	animate_truck_lefttoright();

	//jQuery("#atalhos").animate({top: '0px' }, {queue:false, duration:600, easing:'easeOutBounce'}); 
	jQuery("#frasetop").animate({left:"+=570px"},900);
	
	/*MENU PRINCIPAL*/
	/*jQuery("#menudropdown li.headlink").hover(
			function() { jQuery('ul', this).slideDown(400); },
			function() { jQuery('ul', this).slideUp(400); 
			});*/
	
	/*DESTAQUES*/
	//show the first singlde news container using fadeIn
        jQuery('.single_news_container:first').fadeIn(100);       
        jQuery('.single_news_container:first').addClass('news_visible');

        //DECLARE VARIABLES WE WILL NEED
        var news_No = jQuery('.single_news_container').length; //get number of single news containers
        var prev_html = '<img border=0 src="imgs/btmenos.png" style="vertical-align:middle">'; //the html inside <a>  for previous news
        var next_html = '<img border=0 src="imgs/btmais.png" style="vertical-align:middle">'; //the html inside <a>  for next news

        //fill the news_navigation container with the navigation html
        jQuery('#news_navigation').html('<a href="javascript:prev_news();">' + prev_html + '</a> <span id="current_news_num">1</span>/' + news_No +' <a href="javascript:next_news();">' + next_html + '</a>');	
	
	/*INIFINITE*/
	// THIS IS NEW CODE FOR THE AUTOMATIC INFINITE CAROUSEL
    var autoscrolling = true; //se for para automatico tem que estar true
    
    jQuery('.infiniteCarousel').infiniteCarousel().mouseover(function () {
        autoscrolling = false;
    }).mouseout(function () {
        autoscrolling = true; //se for para automatico tem que estar true
    });
    
    setInterval(function () {
        if (autoscrolling) {
            jQuery('.infiniteCarousel').trigger('next');
        }
    }, 4000);

  
});

