(function($){
	$.fn.createrotatemenu = function(options) {
		
		var defaults = {
			offset: 18,
			fadeInSpeed: "normal",
			element: "dt",
			elementThumbNail: "dd",
			timeOutInterval: 10 /* In seconds right now, may change */
		};
		var options = $.extend(defaults, options);

		return this.each(function() {
			/**
			* Instantiate our object
			* What's being passed into this function is the id of the definition list
			**/
			var menuObj = $(this);
			
			var tPos = 0;
			/**
			* Assign our core classes to each definition term 
			**/
			var topPos = 10;
			var elementCount = 0;
			menuObj.find(options.element).each(function(){
				/**
				* Create and clone our large images for the thumbnails 
				**/
				
				var lrgImageTemp = $(this).next(options.elementThumbNail);
				
				var lrgImage = lrgImageTemp.clone();
				var smlImage = lrgImageTemp.before(lrgImage);
				
				var smlImageObject = smlImage.find("img");
			
				var thmHeight = smlImageObject.height() * .17;
				smlImageObject.height(thmHeight);
				smlImage.height(thmHeight);
				
				if (elementCount > 0)
					topPos = topPos + thmHeight + options.offset;
				else 
					smlImage.addClass("current");
				
				smlImage.css("top", topPos);
				
				var thmWidth = smlImageObject.width() * .17;
				smlImageObject.width(thmWidth);
				smlImage.width(thmWidth);
				
				/**
				* Actually add our core classes 
				**/
				$(this).addClass("core-headline");
				lrgImage.addClass("core-lrgImg");
				smlImage.addClass("core-smlImg");
				
				/**
				* Show the thumbnail image 
				**/
				smlImage.show();
				elementCount++;
				/**
				* Attach a click function to each thumbnail element 
				**/
				smlImage.mouseover(function(){
					/**
					* Check if we are already on the element 
					**/
					if ($(this).prev().prev(".core-headline").is(":visible"))
						return;
								
					if ($(this).prev().prev(".core-lrgImg").is(":animated"))
						return;
						
					if ($(this).prev().prev(".core-headline").is(":animated"))
						return;
					/**
					* Call fadeFunction
					**/
					fnFadeOut($(this), menuObj);
				});
				
				
			});
			/**
			* Time to hide stuff!
			**/
			menuObj.find("dt").hide();
			menuObj.find(".core-lrgImg").hide();
			
			/**
			* Show only the first group while this is initialized
			**/
			menuObj.find("dt").eq(0).show();
			menuObj.find("dd").eq(0).show();
			
			//fnAnimate(menuObj);
		});

			
		function fnAnimate(menuObj) {
			/**
			* Iterate through all main elements, then animate them
			**/
			menuObj.find(".core-smlImg:gt(0)").each(function(){
				
				//alert("Inside Loop");
				var fadeObject = $(this);
				
				setTimeout(function() { fnFadeOut(fadeObject, menuObj); },10000);
				//alert("Leaving Loop");
			});
			//alert("outside of loop");
		}
		function fnFadeOut(fadeObject, menuObj){
			//alert("fnFadeOut Start");
			
			/**
			* Time to hide stuff!
			**/
			menuObj.find(".core-smlImg").removeClass("current");	
			menuObj.find(".core-headline:visible").fadeOut(options.fadeInSpeed);
			menuObj.find(".core-lrgImg:visible").fadeOut(options.fadeInSpeed);

			/**
			* Now then let's do some magic! 
			**/
			fadeObject.addClass("current");
			fadeObject.prev(".core-lrgImg").fadeIn(options.fadeInSpeed);
			fadeObject.prev(".core-lrgImg").prev(".core-headline").fadeIn(options.fadeInSpeed);
			
			//alert("fnFadeOut End");
		}
	};
	
})(jQuery);