// JavaScript Document




var timer = 0;
function interVal(iconNext){
	timer = setInterval(function(){
		iconNext.trigger('click');
	},5000);
}
function initGallery(){ 
	var iconNext = $('#banner').find('.next:first');
	var iconPrev = $('#banner').find('.prev:first');
	var slideshows = $('#slideshows');
	var currentIndex = 0;
	var lengthEl = slideshows.children().length;
	var leftAnimate = -436 * currentIndex;
	
	iconNext.click(function(){
		clearInterval(timer);
		currentIndex = currentIndex + 1;
		leftAnimate = -436 * currentIndex;
		if(currentIndex == lengthEl)
		{
			leftAnimate = 0;
			currentIndex = 0;
		}
		slideshows.children().animate({
			'left':leftAnimate
		},
		300);
		interVal(iconNext);
		return false;
	});
	
	iconPrev.click(function(){
		clearInterval(timer);
		currentIndex = currentIndex - 1;
		leftAnimate = -436 * currentIndex;
		if(currentIndex < 0)
		{
			leftAnimate = -436 * (lengthEl - 1);
			currentIndex = lengthEl - 1;
		}
		slideshows.children().animate({
			'left':leftAnimate
		},300);
		interVal(iconNext);
		return false;
	});
	interVal(iconNext);
}



