/**
 * @version 1.0
 * @author Mauricio Dottavio
 */
(function () {

	// default configuration properties
	var settings = {
		prevId: 		'prevBtn',
		nextId: 		'nextBtn',
		speed: 			800,
		auto:			true,
		pause:			6000,
		continuous:		true
	};
	var mygalleryindex = 0;
	var $this = '';
	
	var methods = {
    init : function( options ) {
			$this = $(this);
			if ( options ) {
        $.extend( settings, options );
      }

			return this.each(function() {
				$(this).find('li').hide();
				$("#"+options.nextId).click(function(){
					methods[ 'moverNext' ].apply( this, Array.prototype.slice.call( arguments, 1 ));
				});
				$("#"+options.prevId).click(function(){
					methods[ 'moverPrev' ].apply( this, Array.prototype.slice.call( arguments, 1 ));
				});
				methods[ 'moveIndex' ].apply( this, Array.prototype.slice.call( arguments, 1 ));
			});

    },
    moverNext : function() {
			if(mygalleryindex >= ($($this).find('li').length - 1)){
				mygalleryindex = 0;
			}else{
				mygalleryindex++;
			}
	  	methods[ 'moveIndex' ].apply( this, Array.prototype.slice.call( arguments, 1 ));
		},
    moverPrev : function() {
			if(mygalleryindex <= 0){
				mygalleryindex = $($this).find('li').length- 1;
			}else{
				mygalleryindex--;
			}
	  	methods[ 'moveIndex' ].apply( this, Array.prototype.slice.call( arguments, 1 ));
    },
    moveIndex : function(){
			$($this).find('li').hide();
			$($this).find('li:eq('+mygalleryindex+')').show();
    }
  };


	$.fn.myGallery = function( method ){

    if ( methods[method] ) {
      return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
    } else if ( typeof method === 'object' || ! method ) {
      return methods.init.apply( this, arguments );
    } else {
      $.error( 'Method ' +  method + ' does not exist on jQuery.tooltip' );
    }

	};

}());

