jQuery(function($){
	
	$.fn.extend({
		
		myGall: function() {
			
			var $this = $(this);
			
			return this.each(function(){
				var i = 1;
				var next = "<a href='#' class='next'>Next</a>";
				var prev = "<a href='#' class='prev'>Prev</a>";
				var count = $('img',$this).size();
				
				$this.append(prev+next);
				
				function get_image(type){
					if(type == 'next'){
						if(i <= count-1){
							i++
							$('img',$this).hide();
							$('img:eq('+i+')').show();
						} else {
							i = 1;
							$('img',$this).hide();
							$('img:eq('+i+')').show();						
						}
					}
					else if(type == 'prev'){
						if(i > 1){
							i--
							$('img',$this).hide();
							$('img:eq('+i+')').show();
						} else{
							i = count;
							$('img',$this).hide();
							$('img:eq('+i+')').show();
						}
					}
				}
				
				$('.next').click(function(){
					get_image('next');
				});
				
				$('.prev').click(function(){
					get_image('prev');
				});
				
				$('.prev,.next').hide();
				
				$this.hover(function(){
					$('.prev,.next').fadeIn(500);
				},function(){
					$('.prev,.next').fadeOut(500);
				});
			
			});
			
		}//end myGall
		
	});//end $.fn.extend
	
});//end plugin

