// JavaScript Document
var playSlideshow;
var homeimg_list = new Array();
var current_img = 0;
var slide_width = 563;
var img_width = 563;
var is_moving = true;

jQuery(document).ready(function() {
	
	//Get all image in to array include the first image
	jQuery('ul.additional li','#slide-offers').each(function(index){
		homeimg_list.push(jQuery(this).html());
	});
	
	if(homeimg_list.length > 1){
	
		//Remove all image
		jQuery('#slide-offers ul.current').remove();	
		jQuery('#slide-offers ul.additional').remove();	
		
		//Create new div
		jQuery('.slide-wrapper').append(jQuery(document.createElement('ul')).attr('id','home_slideshow').css('left','0px').css('width',String((homeimg_list.length+1)*563)+'px'));
		
		//Insert first image in to div
		jQuery.each(homeimg_list, function(index, value){
			jQuery('#home_slideshow').append(jQuery(document.createElement('li')).attr('id','home_img_'+index).html(value));
		});
		
		jQuery('#home_slideshow').append(jQuery(document.createElement('li')).attr('id','home_img_'+homeimg_list.length).html(homeimg_list[0]));						
		
		jQuery('.slide-wrapper','#slide-offers').mouseenter(
			 function(){
				is_moving = false;		
			 }).mouseleave(
			 function () {
				is_moving = true;			
			
			 }
		);
		
		playSlideshow = setTimeout('slideshow_move()', 2000);
	}
	

	
});


function slideshow_move(){
	clearTimeout(playSlideshow);
	var next_img = current_img + 1;		
	var new_left = -next_img*img_width;	
	if(is_moving == true)
	{		
		jQuery('#home_slideshow').animate({'left':new_left}, 2000, function(){
			current_img = next_img;
			if(current_img >= homeimg_list.length)
			{
				current_img = 0;
				jQuery('#home_slideshow').css('left','0px');
			}
			playSlideshow = setTimeout('slideshow_move()', 2000);
		 });
	}
	else
	{
		playSlideshow = setTimeout('slideshow_move()', 2000);
	}
}

// playSlideshow = setInterval(function()},4000);//Interval
