(function($){

$.fn.feature = function(options) {
	// Extend our default options with those provided.
	var opts = $.extend({}, $.fn.feature.defaults, options);

	// Local Variables
	var items			= $(this).find("div.entry");
	var timeoutID		= null;
	var current_index	= 0;
	// var controls 		= document.createElement("div");
	var parent 			= this;
	
	// Add the controls to the element.
	// controls.className = "controls";
	// this[0].appendChild(controls);

	this.show_item = function(index, func) {
		this.hide_item(current_index);
		
		if(index >= items.length) {
			index = 0;
		}
		
		if(index < 0) {
			index = items.length-1;
		} 
		
		// Set the current index to the new value.
		current_index = index;
		
		// $(items[index].shadow_box).hide();
		$(items[index]).animate({ 
			opacity: 'show'
		}, opts.animation_duration);
	}

	this.hide_item = function(index) {
		// Check if the index actually exists.
		if(!items[index]) {
			index = 0;
		} 
		
		$(items[index]).animate({ 
			opacity: 'hide'
		}, opts.animation_duration);
	}

	this.show_next = function() {
		this.show_item(current_index + 1);
	}

	this.show_previous = function() {
		this.show_item(current_index - 1);
	}

	this.rotate = function() {
		if(opts.pause == true) {
			return;
		}
		this.show_next();
		this.start_rotate();
	}

	this.start_rotate = function() {
		var self = this;
		timeoutID = window.setTimeout(function(){ self.rotate(); }, opts.rotate_delay);
	}

	this.stop_rotate = function() {
		window.clearTimeout(timeoutID);
	}


	this.start_rotate();

	return(this);
};

// override these globally if you like (they are all optional)
$.fn.feature.defaults = {
	rotate_delay:			5000,
	pause:				false,
	show_controls:			false,
	animation_duration:		1500,
	bullet_off:			"/media/images/white_bullet.gif",
	bullet_on:			"/media/images/yellow_bullet.gif"
};

})(jQuery);

$(document).ready(function(){

	$('.entry-master').feature();

});

