(function($){  
	$.fn.skslideshow = function(){
		
		var context = this;
		var imgs = $(this).find('img');
		$(this).find('.left').hide();
		$(this).find('.right').hide();
		
		var hasCaptions = false;
		var current = 1;
		var total = 1;
		var offset = 0;
		
		if($(this).find('p.caption').length>0){
			hasCaptions = true;
		}
		
		var offset = $(context).attr('data-width');
		var i_width = $(context).attr('data-width');
		var i_height = $(context).attr('data-height');
		var total = $(context).find('div.slider ul li').length;
		var containerWidth = offset*total;
		
		if(hasCaptions==true){
			i_height = parseInt(i_height)+25;
			$(this).addClass('hasCaptions');
		}
		
		$(context).css({ width: i_width, height: i_height });
		$(context).find('ul').css({ width: containerWidth });
		$(context).find('li').css({ width: i_width, height: i_height });
		
		if(total==1){
			$(context).find('.right').hide();
		}
		else{
			$(context).find('.right').show();
		}
		
		$(context).find('.right').click(function(){
			
			$(context).find('.left').show();
			
	      	var next = current+1;
			
			left = (next-1) * (-1) * offset;
			
			$(context).find('div.slider ul').animate({
				marginLeft: left
			});
			
			current++;
			
			$(context).find('.left').show();
			
			if(current==total){
				$(context).find('.right').hide();
			}
			
			return false;
		});
		
		$(context).find('.left').click(function(){
			
			$(this).show();
			
	      	var next = current-1;
			
			left = (next-1) * (-1) * offset;
			
			$(context).find('div.slider ul').animate({
				marginLeft: left
			});
			
			current--;

			$(context).find('.right').show();
			
			if(current==1){
				$(context).find('.left').hide();
			}
			
			return false;
		});
		
	
		imgs[0].src = imgs[0].src;
	}	
})(jQuery);
