$(".icon_enlarge").ready(function() {
	$(".icon_enlarge").each(function(i) {
		var HOVER_SCALE = 2.0
		var PROXIMITY = 200.0

		//private variables
		var dock = $(this);
		var dock_icons = dock.find("li a");
		var initHeight = dock_icons.css("height");
		var initWidth = dock_icons.css("width");
		
		dock_icons.css("height",initHeight);
		dock_icons.css("width",initWidth);

		var newHeight = parseInt(initHeight) * HOVER_SCALE;
		var newWidth = parseInt(initWidth) * HOVER_SCALE;
		
		var halfNewHeight = newHeight/2.0;
		var halfNewWidth = newWidth/2.0;
		
		//event handlers
		dock_icons.bind("click",function() {
			// $(this).parent().after("<li><a href=\"#\">" + $(this).html() + "</a></li>");
			dock_icons = dock.find("li a");
		});
		
		dock.bind("mouseleave",function(event) {
			dock_icons.animate({"height": initHeight, "width": initWidth},"fast");
		});
		
		dock.bind("mousemove", function(event) {
			dock_icons.each(function(i) {
				var newSize = calculateDockIconSize($(this), event.pageX);
				
				$(this).stop();
				$(this).css("width", newSize[0]);
				$(this).css("height", newSize[1]);
			});
		});
		
		//methods
		function calculateDockIconSize(icon, mousePosX) {
			xProximity = Math.abs(mousePosX - icon.offset().left - halfNewWidth);
			
			if (xProximity<PROXIMITY) {
				newRatio = ((PROXIMITY-xProximity)/PROXIMITY);
				return [(parseInt(initWidth) + (newRatio * (newWidth-parseInt(initWidth)))), parseInt(initHeight) + (newRatio * (newHeight-parseInt(initHeight)))];
			} else {
				return [parseInt(initWidth), parseInt(initHeight)];
			}
		}
	});
});
