/* initialize the Ajax handler */
$().ready(function(){
	RotatingNews.init();							
});




RotatingNews={	
	currentPage:1,		
	pagesCount:0,
	sortBy:null,
	newsCollection:null,
	currentNews:-1,
	rotatorHandler:null,
	
	init:function(){										
			// defining the news rotator behaviours			
			RotatingNews.newsCollection=$(".newsRotator .news");
			$("#startRotationBtn").hide();			
			$("#stopRotationBtn").click(function(){
		 		clearInterval(RotatingNews.rotatorHandler);
				$(this).hide(0);
				$("#startRotationBtn").show(0);
				return false;
			});
			
			$("#startRotationBtn").click(function(){												 		
		        $(this).hide(0);
		        $("#stopRotationBtn").show(0);
		        newsAnimation();
		        startNews();
		        return false;
	        });			
													
			$("#previousRotationImage").click(function(){
			    clearInterval(RotatingNews.rotatorHandler);
			    $("#startRotationBtn").show(0);
			    $("#stopRotationBtn").hide(0);
			    newsAnimationPrevious();
				return false;
			});
			
			$("#nextRotationImage").click(function(){
			    clearInterval(RotatingNews.rotatorHandler);
			    $("#startRotationBtn").show(0);
			    $("#stopRotationBtn").hide(0);
			    newsAnimation();
				return false;
			});												
													
			$(".newsRotator").mouseover(function(){
                clearInterval(RotatingNews.rotatorHandler);
            });
	                                            
	        $(".newsRotator").mouseout(function(){
                startNews();
            });
			
			
			newsAnimation();
			startNews();			
		}
}
	
function startNews(){
	newsDuration=7000;
	
	if (RotatingNews.newsCollection.length>0){
		RotatingNews.rotatorHandler=setInterval(newsAnimation,newsDuration)
	}		
}

function newsAnimation(){
	
	if(RotatingNews.currentNews>-1){
		$(RotatingNews.newsCollection[RotatingNews.currentNews]).animate({																						 
																opacity:0,
																fontSize:"0em",
																height:"0px",
																paddingBottom:"0px"
															 },1000,"swing",function(){this.style.display="none"})
	}
	
	RotatingNews.currentNews++;
	if (RotatingNews.currentNews>RotatingNews.newsCollection.length-1) RotatingNews.currentNews=0;
	
	if (RotatingNews.newsCollection[RotatingNews.currentNews]){ 
		$(RotatingNews.newsCollection[RotatingNews.currentNews]).css({
																opacity:0,
																fontSize:"0em",
																height:"0px",
																paddingBottom:"0px"																					 
														 })									
		
		RotatingNews.newsCollection[RotatingNews.currentNews].style.display="block";
		$(RotatingNews.newsCollection[RotatingNews.currentNews]).animate({																						 
																opacity:1,
																fontSize:"1em",
																height:"150px",
																paddingBottom:"10px"
															 },1000,"swing",function(){this.style.filter=""})			
		}
	}	
	
	
	function newsAnimationPrevious(){
	
	    if(RotatingNews.currentNews>-1){
		    $(RotatingNews.newsCollection[RotatingNews.currentNews]).animate({																						 
																    opacity:0,
																    fontSize:"0em",
																    height:"0px",
																    paddingBottom:"0px"
															     },1000,"swing",function(){this.style.display="none"})
	    }
    	
	    RotatingNews.currentNews--;
	    if (RotatingNews.currentNews<0) RotatingNews.currentNews=RotatingNews.newsCollection.length-1;
    	
	    if (RotatingNews.newsCollection[RotatingNews.currentNews]){ 
		    $(RotatingNews.newsCollection[RotatingNews.currentNews]).css({
																    opacity:0,
																    fontSize:"0em",
																    height:"0px",
																    paddingBottom:"0px"																					 
														     })									
    		
		    RotatingNews.newsCollection[RotatingNews.currentNews].style.display="block";
		    $(RotatingNews.newsCollection[RotatingNews.currentNews]).animate({																						 
																    opacity:1,
																    fontSize:"1em",
																    height:"150px",
																    paddingBottom:"10px"
															     },1000,"swing",function(){this.style.filter=""})			
		    }
	}	