(function($) {
	
function TauiFeature(target, settings) {
	
	var self = this;
	self.settings = settings;
	self.container = $(target);
	self.pos = 0;
	
	//container.attr("id", "svwp"+j);
	
	self.slideWidth = (self.settings.width != null) ? self.settings.width : self.container.find("li").width();
	var slideHeight = (self.settings.height != null) ? self.settings.height : self.container.find("li").height();
	
	self.numberOfSlides = self.container.find("li").size();
	
	var totalWidth = self.slideWidth * self.numberOfSlides;
	
	
	
	self.container.css({"width": self.slideWidth, "height": slideHeight, "position" : "relative", "overflow": "hidden"});
	self.container.find("ul").css({"width": totalWidth, "height": slideHeight, "list-style": "none", "padding": "0", "position": "absolute", "top": 0, "left" : -self.slideWidth * self.pos});
	self.container.find("li").each(function(i) {
		$(this).css({"width": self.slideWidth, "height": slideHeight, "float" : "left", "overflow": "hidden"});
	});
	
	self.container.append('<div id="'+id("left")+'" class="feature-button feature-button-left"><a href="#"><span>&larr;</span></a></div>');
	self.container.append('<div id="'+id("right")+'" class="feature-button feature-button-right"><a href="#"><span>&rarr;</span></a></div>');

	self.l = $("#" + id("left"));
	self.r = $("#" + id("right"));
	self.l.css({"position": "absolute"});
	self.r.css({"position": "absolute"});
	
	$.extend(self, {
		
		setNavigation: function() {
			self.l.show();
			self.r.show();
			if (self.pos == 0) {
				self.l.hide();
			}
			if (self.pos == self.numberOfSlides - 1) {
				self.r.hide();
			}
		},
		
		goTo: function(_pos) {
			self.pos = _pos;
			var ul = $(self.container.find("ul:not(:animated)"));
			ul.animate({ left: -self.slideWidth * self.pos}, 500, self.settings.easing, function(){self.setNavigation();});
		}
	});
	
	self.setNavigation();
	
	self.l.bind("click", function() {
		var ul = $(self.container.find("ul:not(:animated)"));
		if (ul.size() > 0) {
			self.pos--;
			ul.animate({ left: -self.slideWidth * self.pos}, 500, self.settings.easing, function(){self.setNavigation();});
		}
		return false;
	});
	
	self.r.bind("click", function() {
		var ul = $(self.container.find("ul:not(:animated)"));
		if (ul.size() > 0) {
			self.pos++;
			ul.animate({ left: -self.slideWidth * self.pos}, 500, self.settings.easing, function(){self.setNavigation();});
		}
		return false;
	});
	
	self.container.find(".loading").hide();
	self.container.find("ul").fadeIn();
	
	return self;
}

function init(settings, id) {
	var tf = new TauiFeature($(this), settings, id);
	$(this).data('tauiFeature', tf);
}

var j = 0;
function id(id) {
	return "taui-feature-" + id + "-" + j;
}

jQuery.fn.tauiFeature = function(options, data) {
	var command = String(options).toLowerCase();

	if(typeof options === 'string') {
		$(this).each(function() {
			var api = $(this).data('tauiFeature');
			if(!api){ return true; }
			
			if (command === 'go') { api.goTo(data) }
			else if (command === 'nocommand') { }
			
		});
		
	} else if(typeof options === 'object') {
		var settings = $.extend(true, {}, $.fn.tauiFeature.defaults, options);
		return this.each(function() {
			var obj = init.call($(this), settings);
			if(obj === false) { return true; }
			return obj;
		});
	}
}

$.fn.tauiFeature.defaults = {
	easeTime: 750,
	easeing: "easeInOutExpo",
	width: null,
	height: null
};

}(jQuery));

// from the jquery.easing plugin
jQuery.extend( jQuery.easing, {
	easeInOutExpo: function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	}
});