// Gallery Plugin
(function($) {

  var nav, navItems, items, container, activeItem, options;
	
	var methods = {
		//
		activateItem: function(itemIndex) {
		  //
		  navItems.removeClass('active');
		  activeItem.removeClass('active').hide();
		  //
		  activeItem = items.eq(itemIndex);
		  //
      container.height(activeItem.height());
		  navItems.eq(itemIndex).addClass('active');
		  activeItem.addClass('active').fadeIn(options.fadeDuration);
		},
		//
		init: function(opt) {
			
			var defaults = { fadeDuration:200 }
			options = $.extend(defaults, opt);
			
			container = this;
			nav = $(options.nav);
			navItems = nav.find('li');
			items = this.children();
			activeItem = items.eq(0);
			
			navItems.find('a').click(function(e){
			  var item = $(this).closest('li');
			  methods.activateItem.call(container, item.index());
			  e.preventDefault();
			});
			
			activeItem.show();
			container.height(activeItem.height());
			
			return this;
		}
	}
	
	$.fn.toggler = function(method) {
		// Method calling logic
		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.slideShow' );
		}
	};
	
})(jQuery);
