/*
 * WordShow - interactive words rotator
 * Examples and documentation at: http://
 * Version: 1.0.0 (27/06/2010)
 * Copyright (c) 2010 MaxSmith
 * Licensed under the MIT License: http://en.wikipedia.org/wiki/MIT_License
 * Requires: jQuery v1.3+
*/
;(function($) {
	
/*	$.fn.wordShow = function(options) {
		var place	= $(this);
		var conte	= $(options.conte);
		new jQuery.wordShow(place, conte, options);
		return this;	
	};
	*/

	$.wordShow = function(place, conte, options) {

		function twist( nItem ){
			if (typeof nItem == "undefined") {
				nItem = visibleItem;
				nItem = nItem >= totalItems ? 0 : nItem;
			}
			
			if($.browser.msie)
			{
				place.stop(true, true).filter(":visible").hide(0,function(){
					$(this).html( conte.filter(":eq(" + nItem + ")" ).html()).show(0,function(){
						visibleItem = nItem + 1;
					})
				});
			}
			else
			{
				place.stop(true, true).filter(":visible").fadeOut(function(){
					$(this).html( conte.filter(":eq(" + nItem + ")" ).html()).fadeIn(function(){
						visibleItem = nItem + 1;
					})
				});
			}

		}

		var options		= options || {}; 
		var totalItems	= conte.length;
		var visibleItem	= options.startItem || 0;
		//var f			= typeof f == "function" ? f : function(){};

		options.pause	= options.pause		|| true;
		options.interval= options.interval	|| 5000;
		
		twist();

		if(options.interval > 0) {
			
			var timer = setInterval(function(){
				twist();
			}, options.interval);

			if(options.pause)
			{
				place.mouseenter(function(){
					clearInterval( timer );
				}).mouseleave(function(){
					clearInterval( timer );
					timer = setInterval(function(){
						twist();
					}, options.interval);
				});
			}
		}
	};
})(jQuery);
