(function($){
	// namespace
	var ns = "contentSliderVertical";
	
	// =====================================================
	var contentSliderVertical = function(el, options){
		// ============================================
		// private variables
		var _settings = {
			width	: 500,
			height	: 200,
			speed	: 500,
			pause	: 5000
		};
		var _el; // root element
		var _cs; // content strip
		var _nav; // nav list
		var _itemCount = 0; // number of items in our strip
		var _pos = 0; // current position
		var _timer; // timer object
		var _callback; // callback function
		var self = this;
		
		// ============================================
		// constructor
		self.init = function(){
			_el = el;
			
			if(options) $.extend(_settings, options);
			
			// size our container
			_el.width(_settings.width)
				.height(_settings.height)
				.css("overflow", "hidden")
				.css("position", "relative");
			
			
			_callback = _settings.callback;
			
			// nav HTML
			var navHTML = ""; //"<ul class='contentSliderNav'>";
			
			// size and position our content nodes initial positions 
			$("> div", _el).each(function(i){
				// size and position
				$(this).width(_settings.width)
					.height(_settings.height)
					.css("position", "absolute")
					.css("top", i*_settings.height)
					.css("overflow", "hidden");
				// nav item
				//navHTML += "<li><a href='#' title='Move to slide " + (i+1) + "'>" + (i+1) + "<\/a><\/li>";
				// count
				_itemCount++;
			}).wrapAll("<div class='contentStrip'></div>");
			
			// close nav HTML
			//navHTML += "<\/ul>";
			
			// get our content strip and position it
			_cs = $(".contentStrip", _el).css("position", "absolute");
			
			// add our nav HTML into the mix
			_cs.before(navHTML);
			_nav = $(".contentSliderNav", _el)
						.css("position", "absolute")
						.css("z-index", "100");
			// nav click event
			$("li", _nav).click(function(e){
				var i = $(this).index();
				pub.move(i);
				e.preventDefault();
			});
			self.toggleNav();
			
			// build next/prev navigation
			self.buildNextPrev();
			
			// mouse events control our timer events
			_el.mouseleave(function(){
				self.setTimer();
				$(this).removeClass("mouseOver");
			});
			_el.mouseenter(function(){
				self.clearTimer();
				$(this).addClass("mouseOver");
			});
			self.setTimer();
		};
		
		// ============================================
		// private methods
		
		// ========================
		// TODO: if we need next/prev buttons, build them here...
		self.buildNextPrev = function(){
			
		};
		
		// toggles the status of our nav list to show the currently selected item
		self.toggleNav = function(){
			$("li", _nav).each(function(i){
				if(i == _pos){
					$(this).addClass("selected");
				}else{
					$(this).removeClass("selected");
				}
			});
		};
		
		
		self.setTimer = function(){
			self.clearTimer();
			_timer = setInterval(pub.next, _settings.pause);
		};
		
		self.clearTimer = function(){
			clearInterval(_timer);
		};
		
		// ============================================
		// public methods
		var pub = {
			// =============
			
			move: function(i){
				// check our bounds
				i = i-0; // force our incoming value to be a number
				if(i > _itemCount-1) i = 0;
				if(i < 0) i = _itemCount-1;
				_pos = i;
				self.toggleNav();
				self.clearTimer();
				// animate
				_cs.stop().animate({top: -i*_settings.height}, {duration: _settings.speed, complete: function(){
					//pos = i;
					//self.toggleNav();
					if(_callback){
						_callback.call(self, _pos);
					}
					if(!_el.hasClass("mouseOver")) self.setTimer();
					
				}});
			},
			
			next: function(){
				pub.move(_pos+1);
			},
			
			prev: function(){
				pub.move(_pos-1);
			},
			
			getPos: function(){
				return _pos;
			}
			
		};
		
		// call to initiate
		self.init();
		return pub;
	};
	// =====================================================
	
	
	
	// =======================================
	// plugin constructor
	$.fn[ns] = function(method) {
		//return this.each(function(i){
			var plugin = $(this).data(ns);

			if(!plugin){
				return $(this).data(ns, new contentSliderVertical($(this), method));
			}else{
				if(plugin[method]){
					return plugin[method](Array.prototype.slice.call(arguments, 1));
				}
			}
			
		//});
		
		/*
  		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.cubic." + ns);
		}*/
	};
})(jQuery);

