$(document).ready(function()
{	
    /*Padding para garantir aparecer o box de noticias*/
    contentLeft                     = document.getElementById('left-sidebar');
    orcamentoResult                 = document.getElementById('orcamento');
    contentLeft.style.paddingTop    = parseInt(orcamentoResult.offsetHeight - 15) + 'px';    

    $('#orcamento-resultado').hide();
    $('#orcamento-erro').hide();
    $('#orcamento-loading').hide();
    
    $('#orcamento-erro a').click(function(){
        $('#orcamento-erro').fadeOut('normal');                 
    });
    
    
    $('#orcamento-resultado a#voltar').click(function(){
        $('#orcamento-inputs').show();
        $('#orcamento-resultado').hide();
             
        /*Padding para garantir aparecer o box de notícias*/
        contentLeft = document.getElementById('left-sidebar');
        orcamentoResult = document.getElementById('orcamento');
        contentLeft.style.paddingTop = parseInt(orcamentoResult.offsetHeight - 15)  + 'px';                                     
     });
	
	/* Slide de Notícias */		 
	headline_count = $("div.new-scroll").size();
	   $("div.new-scroll:eq(" + current_headline + ")").css('top', '0px');	   
		headline_interval = setInterval(headline_rotate,10000); 
		
	   $('#noticias-wrap').hover(function() {
		 clearInterval(headline_interval);
	   }, function() {
		 headline_interval = setInterval(headline_rotate,10000);
	   });
	    $('a#next-news').click(function() {
			if (inTween) return;
			headline_rotate();
			clearInterval(headline_interval);			
		});
		 $('a#prev-news').click(function() {
		 	if (inTween) return;
			prev_headline_rotate();
			clearInterval(headline_interval);			
		});
		$('a#prev-news').hide();
});

function update_buttons_rot()
{
   if (old_headline == headline_count-1) $('a#next-news').hide();
   else $('a#next-news').show();
   
   if (old_headline == 0) $('a#prev-news').hide();
   else $('a#prev-news').show();
}

function headline_rotate() { 
   current_headline = (old_headline + 1) % headline_count;
   inTween = true;
   
   $("div.new-scroll:eq(" + old_headline + ")").animate({top: -275},"slow", function() {
     $(this).css('top','-280px');
	 inTween = false;
   });
   
   if (parseFloat($("div.new-scroll:eq(" + current_headline + ")").css('top')) < 0) $("div.new-scroll:eq(" + current_headline + ")").css('top','280px');
   $("div.new-scroll:eq(" + current_headline + ")").show().animate({top: 0},"slow");  
   old_headline = current_headline;
   update_buttons_rot();   
}
 
function prev_headline_rotate() {	
   current_headline = (old_headline - 1) % headline_count; 
   inTween = true;
   
   $("div.new-scroll:eq(" + old_headline + ")").animate({top: 275},"slow", function() {
     $(this).css('top','280px');
	 inTween = false;
   });
   
   $("div.new-scroll:eq(" + current_headline + ")").show().animate({top: 0},"slow");  
   old_headline = current_headline;
	update_buttons_rot();   
}

swfobject.embedSWF("anim/mapa.swf", "mapa", "103", "103", "8.0.0", "expressInstall.swf");