var noticiaOver = false;
var mudar = false;
var x = 0; 
var not = 3;
var prox = null;

window.onload = function(){
				document.getElementById('noticia4').innerHTML = noticia[0];
				document.getElementById('noticia3').innerHTML = noticia[1];
				document.getElementById('noticia2').innerHTML = noticia[2];
				document.getElementById('noticia1').innerHTML = noticia[3];
			}

		function over(){
			noticiaOver = true;
		}
		function out(){
			noticiaOver = false;
		}
		
		$(document).ready(function() {
		
			function mudaNoticia(moveNext){	
			
					mudar = true;
					
					if(moveNext){
						if(!prox)
						{
							prox = true;
							not+=2;
						}
					}else{
						if(prox)
						{						
							not-=2;
							prox=false;
						}
					}
					
					if(not==5){not=1;}
					
					if(not<1){not=4;}
					
					for(i=1;i<5;i++)
					{
						if(i!=not)
						{
							$("#noticia"+i).animate({
								opacity: 'hide'
							}, 'slow');
							//alert("esconde: "+i);
						}else
						{
							$("#noticia"+not).animate({
								opacity: 'show'
							}, 'slow');
						}
					}
					
					if(moveNext){
						not++;
					}else{
						not--;
					}
					
					x=0;
				}
			
			
			$("#icoProximo").click(					
				function(){
					mudaNoticia(true);
				});
			
			$("#icoAnterior").click(			
				function() {					
					mudaNoticia(false);
				});
		
			setInterval(
						function(){
							if(x==0){
								mudaNoticia(true);
							}
						}
						, 500);
	
			setInterval(
						function() {
							if(mudar && !noticiaOver){
								if (x < 600){
									barraMais('barraLoad');
								}else{
									x = 0;
									mudar = false;
								}
							}
							
						}, 100);

			function barraMais(id) {
				x+=10;
				document.getElementById(id).style.width = (x/5.3)+"px";
			}
		
		});