var P8S_slideshow = (function(){
	var container, images, imgs, curPic;
	
	function showPic(n){
		var pic = imgs[n];
		curPic = n;
		images.animate({
			left: -pic.offsetLeft+'px'
		}, 500, "easeout");
	}
	
	function showPrevPic(e){
		var prev = 0,
			lastImg = imgs.length-1;
		
		if((curPic-1) < 0){
			prev = lastImg;
		}else{
			prev = curPic - 1;
		}
		showPic(prev);
		return false;
	}
	
	function showNextPic(e){
		var next = 0,
			lastImg = imgs.length-1;
		if((curPic+1) > lastImg){
			next = 0;
		}else{
			next = curPic + 1;
		}
		showPic(next);
		return false;
	}
	
	function initSlideshow(con){
		container = con;
		var inner = $('.inner',con);
	 	images = $('.images',inner);
		imgs = $('img',inner);
		var totalWidth = 0;
		imgs.each(function(n,img){
			totalWidth+=$(img).width();
			//totalWidth+=img.offsetWidth;
		});
		images.attr('style','width: '+parseInt(totalWidth+1000,10)+'px;');
		/*
		var prevLink = $("<a><span>&lt;</span></a>").attr('href','#');
		prevLink.attr('class','prevLink');
		prevLink.click(showPrevPic);
		
		var nextLink = $("<a><span>&gt;</span></a>").attr('href','#');
		nextLink.attr('class','nextLink');
		nextLink.click(showNextPic);
		inner.before(prevLink);
		inner.after(nextLink);
		*/
		curPic = 0;
		
	}
	
	return {
		init: function(ss){
			initSlideshow($('#'+ss));
		},
		
		showNext: function(e){
			showNextPic(e);
		},
		
		showPrev: function(e){
			showPrevPic(e);
		},
		
		showImage: function(x){
			showPic(x);
		},
		
		isFirstPic: function(){
			return (curPic == 0);
		},
		
		isLastPic: function(){
			return (curPic == (imgs.length - 1));
		}
	};
	
})();
