//alert('home');
var banner_height = 333;
var thumb_height = 115;
var i = 1;
var at_the_end = false;
var myTimer = 0;


jQuery(document).ready(function(){
						   
	var total_lis = jQuery('ul#home_banner_main li').size(); // method // function // 6
	
	//alert(total_lis);
	
	var contents_of_ul = jQuery('ul#home_banner_main').html();
	jQuery('ul#home_banner_main').append(contents_of_ul);

	var contents_of_thumb_ul = jQuery('ul#home_banner_thumbs').html();
	jQuery('ul#home_banner_thumbs').append(contents_of_thumb_ul);
	
	jQuery('ul#home_banner_thumbs li:first-child').remove();

	function myAnimation(){
	
		if(i >= total_lis) {
			
			at_the_end = true;
			
		}
		else {
			at_the_end = false;	
		}
	
		
	
		var animate_up        = (banner_height*i)*(-1); // 
		var animate_thumbs_up = (thumb_height*i)*(-1); // 
	
		jQuery('ul#home_banner_main').animate({ top: animate_up }, 1000, function(){  
					
					//alert(at_the_end);
					if(at_the_end == true){
						i = 1;
						//at_the_end = false;
						// abrupt to the top
						jQuery('ul#home_banner_main').css("top","0");
					}
																				  
		});
		
		
		
		jQuery('ul#home_banner_thumbs').animate({ top: animate_thumbs_up }, 1000, function(){
																						   
					if(at_the_end == true){
						//at_the_end = false;
						jQuery('ul#home_banner_thumbs').css("top","0");
					}
																						   
		});

		i++; // add one;

	}
	
	myTimer = setInterval(myAnimation, 3000);
	
	//
	
	jQuery('div#click_me').click(function(){
		
		clearInterval(myTimer); // throw timer in the trash;
		myAnimation();
		//alert('clicked');
		
	});
	
});