var start_width = 500;
var start_height = 500;
var end_width = 250;
var end_height = 250;
var cur_img = -1;
var prev_img = 0;
var img_len = 0;
var animation_speed = 1200;
var animation_timeout = 2000;

jQuery(window).load(function(){
	//set image length
	img_len = jQuery("#thumbnails_new img").length;
	
	//start slideshow
	fadeIn(1);
});

function fadeIn(dir){
	//setup previous img
	prev_img = cur_img;
	
	//get the next img
	if(cur_img+dir >= img_len){
		cur_img = 0;
	} else if(cur_img+dir < 0){
		cur_img = img_len - 1;
	} else {
		cur_img += dir;
	}
	
	//setup current image
	jQuery("#thumbnails_new img").eq(cur_img).css({ 'width':start_width, 'height':start_height, 'zIndex':'9999', 'left':(((start_width-end_width) / 2)*-1)+'px', 'top':(((start_height-end_height) / 2)*-1)+'px' }).show();
	
	//fade in current image
	jQuery("#thumbnails_new img").eq(cur_img).animate({ 'width':end_width, 'height':end_height, 'left':'0px', 'top':'0px' },animation_speed,//'easeOutBounce',
	function(){	
		//reset the z index
		if(cur_img == img_len -1){
			jQuery('#thumbnails_new img').css({'zIndex':'1000'});
		}
		
		//start the next animation
		setTimeout('fadeIn(1)',animation_timeout);
	});
}

