	// JavaScript Document

(function($) {

	$.rotaryMenu = {
		defaults: {
			mWidth: 150,
			mHeight: 150,
			mClassName: "menuEntry",
			resizeFaktor: 0.75,
			mClassNameText: "headline",
			headlineHeight: 16,
			classNameMenuEntryLeft: "menuentryleft",
			classNameMenuEntryCenter: "menuentrycenter",
			classNameMenuEntryRight: "menuentryright",
			initEntry: 0
		}
	};  
	
	arrMenuEntriesWidth = new Array();
	var config = null;
	var containerId = null;
	
	$.fn.extend({   
		rotaryMenu:function(config) {   			   
			config = $.extend({}, $.rotaryMenu.defaults, config);   
			
			//alert(this.attr("id"));
			//alert(config.mClassName);
			containerId = this.attr("id");
			menuEntries = $("#" + this.attr("id") + " ." + config.mClassName);
			menuEntriesText = $("#" + this.attr("id") + " ." + config.mClassNameText);
			
			menuEntries.css("position","absolute").css("bottom", "0px").css("width", config.mWidth).css("height", config.mHeight).css("overflow", "hidden").show();
			
			menuEntriesText.css("position","relative").css("height", config.headlineHeight);
			
			menuEntriesCount = menuEntries.length;
			
			fullMenuEntriesWidth = 0;
			
			for (j = 0; j < 100; j++)
			{
				if (j == 0)
				{
					currWidth = config.mWidth;
					currHeight = config.mHeight;
					arrMenuEntriesWidth[j] = new Array(Math.round(currWidth), Math.round(currHeight));
				}
				else
				{
					currWidth = currWidth*config.resizeFaktor;
					currHeight = currHeight*config.resizeFaktor;
					arrMenuEntriesWidth[j] = new Array(Math.round(currWidth), Math.round(currHeight));
					arrMenuEntriesWidth[j*-1] = new Array(Math.round(currWidth), Math.round(currHeight));
				}
			}
			
			for (j = 0; j < menuEntriesCount; j++)
			{
				menuEntries[j].id = "jseusz_menuentry_" + j;
				$("#jseusz_menuentry_" + j + " a").attr("id", "_" + j);
				
				if (j == 0)
				{
					currWidth = config.mWidth;
				}
				else
				{
					currWidth = currWidth*config.resizeFaktor;
				}
				
				fullMenuEntriesWidth = fullMenuEntriesWidth + Math.round(currWidth);
				
				$("#jseusz_menuentry_" + j + " a").mouseenter(function(){
					menuentry_mouseover(parseInt(this.id.replace("_", "")), config);
				});
			}
			
			
			lastWidth = 0;
			
			fullMenuEntriesWidth = Math.round(fullMenuEntriesWidth);
			menuentry_mouseover(config.initEntry, config);
			/*
			menuEntriesOffsetLeft = Math.round( (this.width() - fullMenuEntriesWidth) / 2 );
			currPosLeft = menuEntriesOffsetLeft;		
			
			for (j = 0; j < menuEntriesCount; j++)
			{
				//currPosLeft = (new String(j*config.mWidth))+"px";

				if (j == 0)
				{
					currWidth = config.mWidth;
					currHeight = config.mHeight;
				}
				else
				{
					currWidth = currWidth*config.resizeFaktor;
					currHeight = currHeight*config.resizeFaktor;
					currPosLeft = currPosLeft + lastWidth;
				}
				
				currWidth = Math.round(currWidth);
				currHeight = Math.round(currHeight);
				
				lastWidth = currWidth;
								
				$("#jseusz_menuentry_" + j).css("left", currPosLeft).css("width", currWidth).css("height", currHeight);
				$("#jseusz_menuentry_" + j + " img").attr("width", currWidth).attr("height", currHeight);
				
			}
			*/
		}   
	});  
		  
	
	function menuentry_mouseover(currElement, cfg)
	{		
		fullMenuEntriesWidth = 0;
		
		currentPosition = 0;
		fullMenuEntriesWidth = 0;
		for (j = currElement*-1; j < (currElement*-1)+menuEntriesCount; j++)
		{
			fullMenuEntriesWidth = fullMenuEntriesWidth+arrMenuEntriesWidth[j][0];
		}
		fullMenuEntriesWidth = Math.round(fullMenuEntriesWidth);
		
		menuEntriesOffsetLeft = Math.round( ($("#"+containerId).width() - fullMenuEntriesWidth) / 2 );
		currPosLeft = menuEntriesOffsetLeft;
			
		lastWidth = 0;
		currentPosition = 0;
		for (j = currElement*-1; j < (currElement*-1)+menuEntriesCount; j++)
		{
			
			currWidth = arrMenuEntriesWidth[j][0];
			currHeight = arrMenuEntriesWidth[j][1];
			currPosLeft = currPosLeft + lastWidth;
			
			lastWidth = currWidth;
			
			currWidth = Math.round(currWidth);
			currHeight = Math.round(currHeight);
					
			$("#jseusz_menuentry_" + currentPosition).css("left", currPosLeft).css("width", currWidth).css("height", currHeight+cfg.headlineHeight);
			
			nOpacity = 0.7;
			if (currentPosition == currElement)
				nOpacity = 1;
			
			
			
			
			$("#jseusz_menuentry_" + currentPosition).css("bottom", (Math.round((cfg.mHeight-currHeight)/2)*0.36) ).css("opacity", nOpacity);
			
			$("#jseusz_menuentry_" + currentPosition + " img").attr("width", currWidth).attr("height", currHeight);
			
			nClassname = cfg.classNameMenuEntryLeft;
			
			if (currentPosition == currElement)
				nClassname = cfg.classNameMenuEntryCenter;
			if (j > 0)
				nClassname = cfg.classNameMenuEntryRight;
			
			$("#jseusz_menuentry_" + currentPosition + " ." + cfg.mClassNameText).removeClass(cfg.classNameMenuEntryLeft).removeClass(cfg.classNameMenuEntryCenter).removeClass(cfg.classNameMenuEntryRight);
			$("#jseusz_menuentry_" + currentPosition + " ." + cfg.mClassNameText).addClass(nClassname);
			
			currentPosition++;
			
		}
		
		
		
		//alert(arrMenuEntriesWidth[currElement][0]);
		//alert(currElement);		
	}
	
	
	
})(jQuery);
