/***	
 *			- Rotatey - 
 *				
 *	DEVELOPER:		David Cumberland
 *	EMAIL:			dcumberland@calmon.com.au
 *	VERSION: 		0.1
 *	DATE:			20 April 2011
 *	COMPANY:		Calmon Computing
 *	PH:				1300 768 568
 *	
 *	DESCRIPTION:
 *	Any element rotator, specify a parent and child elements
 *	and it will automatically rotate them from first to last
 *	element.
 *	
 *	@params		parennt	STRING
 *	@params		element	STRING
 *	@params		timer	INT
 *	
 */

(function( $ ){

$.fn.extend ({
	rotatey : function (options, callback)
	{
		var element = $(this);
		var defaults = {
			parent: "div.rotator",
			element: "div",
			timer: 5000
		}
		var o = $.extend(defaults, options);
		return this.each(function(){
			$(o.parent + ' ' + o.element).css({opacity: 0.0});
			$(o.parent + ' ' + o.element + ':first').css({opacity: 1.0});
			setInterval(
				function () {
					// Get the current item
					var current = ($(o.parent + ' ' + o.element + '.show')?  $(o.parent + ' ' + o.element + '.show') : $(o.parent + ' ' + o.element + ':first'));
					
					// is First?
				    if ( current.length == 0 ) 
				    	current = $(o.parent + ' ' + o.element + ':first');
				    
					var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $(o.parent + ' ' + o.element + ':first') :current.next()) : $(o.parent + ' ' + o.element + ':first'));
					next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 1000);
					current.animate({opacity: 0.0}, 1000).removeClass('show');
				}, o.timer);
		});	
	}
})
})(jQuery);
