var timer;
var slide_time = 5000;
var trans_time = 2000;
var current_slide = 1;

$(document).ready(function(){

	if ($("#flash_header li").size() > 0) {
		
		//style the ul
		$("#flash_header ul").css({ 'position':'absolute', 'left':'0', 'top':'0' });
		
		ul_width = 0;
		$("#flash_header li").each(function(index) {
											
			$(this).css({ 'float':'left' });
			ul_width += $(this).width();
			
		});
		
		//set ul width
		$("#flash_header ul").css({ 'width':ul_width+'px' });
		
		//set loop timer
		timer = setTimeout(loopSlides, slide_time);
		
	}
						   
});

function loopSlides() {
	
	$current_slide = $("#flash_header li."+current_slide); 
	current_width = $current_slide.width();
	
	$("#flash_header ul").animate({
    	left: '-='+current_width
	}, trans_time, 'linear', function() {
    
		// Animation complete.
  		//set loop timer
		timer = setTimeout(loopSlides, slide_time);
		
		//move the slide
		$("#flash_header ul").append($current_slide);
		
		//reset the ul
		$("#flash_header ul").css({ 'left':'0' });

		//change the current slide
		if (current_slide == $("#flash_header li").size())
			current_slide = 1;
		else
			current_slide++;
  	
	});
	
}
