// JavaScript Document
$(document).ready(function(){
	$("#slider .tweetbox ul li > a").each(function(){
   		  var el = jQuery(this);
   		 el.html( el.text().replace("riotracing:", ""));
	 })
	$("#slider .tweetbox span.date").each(function(){
   		  var el = jQuery(this);
   		 el.html( el.text().replace("+0000", ""));
	 })
});

// -------- Slide ----------------
$(document).ready(function() {
 
    //rotation speed and timer
    var speed = 5000;
    var run = setInterval('rotate()', speed);  
     
    //grab the width and calculate left value
    var item_width = $('#slides li').outerWidth();
    var left_value = item_width * (-1);
         
    //move the last item before first item, just in case user click prev button
    //$('#slides li:first').before($('#slides li:last'));
     
    //set the default item to the correct position
    $('#slides ul').css({'left' : left_value});
	

    $('#prev').click(function() {    //if user clicked on prev button
 
		
        var left_indent = parseInt($('#slides ul').css('left')) + item_width;     //get the right position    
        $('#slides ul').animate({left : left_indent, opacity : 0}, 200,function(){           //slide the item  
            $('#slides li:first').before($('#slides li:last'));                      //move the last item and put it as first item       
            $('#slides ul').css({'left' : left_value});            //set the default item to correct position
			$('#slides ul').animate({opacity : 1}, 1000);
		});
		
         
        return false; //cancel the link behavior   
		         
    });
	$('#prev').hover(function() {  
		clearInterval(run);
	}, function() {
		 run = setInterval('rotate()', speed);  
	});

    $('#next').click(function() {    //if user clicked on next button

		 
        var left_indent = parseInt($('#slides ul').css('left')) - item_width;        //get the right position
        $('#slides ul').animate({left : left_indent, opacity : 0}, 200, function () {        //slide the item
            $('#slides li:last').after($('#slides li:first'));                             //move the first item and put it as last item
            $('#slides ul').css({'left' : left_value});            //set the default item to correct position
			$('#slides ul').animate({opacity : 1}, 1000);
        });
		
		
        return false;        //cancel the link behavior
    });    
	$('#next').hover(function() {  
		clearInterval(run);
	}, function() {
		 run = setInterval('rotate()', speed);  
	});   
   
    $('#slides').hover( //if mouse hover, pause the auto rotation, otherwise rotate it
         
        function() {
            clearInterval(run);
        },
        function() {
            run = setInterval('rotate()', speed);  
        }
    );
	
         
});
 
//a simple function to click next link
//a timer will call this function, and the rotation will begin :) 
function rotate() {
    $('#next').click();
}
