// JavaScript Document// JavaScript Document
var slideshowCurrent = null;
(function($) {
	$.fn.slideshow = function(options) {
		var opts = $.extend({}, $.fn.slideshow.defaults, options);
		return this.each(function() {
			var $this 						= $(this);
			$this.opts 						= $.extend({}, opts);
			$this.opts.currentslide			= 0;
			$this.opts.slides				= $this.find(' > ul > li');
			
			$fullwidth = ($this.opts.slides.length * 642) + 'px';
			$this.find(' > ul').css('width',$fullwidth);
			
			$('.album-navigation a.prev').bind('click', function(){
				$.fn.slideshow.left($this);
			})
			$('.album-navigation a.next').bind('click', function(){
				$.fn.slideshow.right($this);
			})
			slideshowCurrent = $this;
			$this.find('li.picture').swipe( {
				swipeLeft:function(){
					$.fn.slideshow.right($this);
				},
				swipeRight:function(){
					$.fn.slideshow.left($this);
				},
				threshold:0
			} );
			$("body").keydown(function(e) {
			  if(e.keyCode == 37) { 
				$.fn.slideshow.left($this);
			  }
			  else if(e.keyCode == 39) {
				$.fn.slideshow.right($this);
			  }
			});
						
		});
	};		
	$.fn.slideshow.left = function($this){
		$this.opts.currentslide--;
		$.fn.slideshow.slide($this);
	}
	$.fn.slideshow.right = function($this){
		$this.opts.currentslide++;
		$.fn.slideshow.slide($this);
	}
	
	$.fn.slideshow.slide = function($this){
		if($this.opts.currentslide < 0){
			$this.opts.currentslide = 0;
		}else if($this.opts.currentslide >= $this.opts.slides.length){
			$this.opts.currentslide = $this.opts.slides.length-1;
		}else{
			$position = -$this.opts.currentslide * 632;
			$this.find(' > ul').stop().animate({'left': $position + 'px'}, 500)
		}
	}
	
	$.fn.slideshow.defaults = {
	};
	
})(jQuery);
