/*!
 * Fisheye Menu
 * Copyright 2007-2009 Marc Grabanski (m@marcgrabanski.com) http://marcgrabanski.com
 * Project Page: http://marcgrabanski.com/pages/code/fisheye-menu
 * Under the MIT License */

var fisheyemenu = {
	startSize : 95,
	endSize : 115,
	imgType : ".jpg",
	init : function (el_id) {
		var animElements = document.getElementById(el_id).getElementsByTagName("img");
		for(var i=0; i<animElements.length; i++) {
			var y = animElements[i];
			//y.style.width = fisheyemenu.startSize+'px';
			//y.style.height = fisheyemenu.startSize+'px';
			//fisheyemenu.imgSmall(y);
			animElements[i].onmouseover = changeSize;
			animElements[i].onmouseout = restoreSize;
		}
		function changeSize() {
			//fisheyemenu.imgLarge(this);
			if (!this.currentHeight) {
				this.currentHeight = fisheyemenu.startSize;
				this.ratio = this.width / this.height; 
			}
			fisheyemenu.resizeAnimation(this,this.currentHeight,fisheyemenu.endSize,this.ratio,15,10,0.333);
		}
		function restoreSize() {
			if (!this.currentHeight) return;
			fisheyemenu.resizeAnimation(this,this.currentHeight,fisheyemenu.startSize,this.ratio,15,10,0.5);
			//fisheyemenu.imgSmall(this);
		}
	},
	resizeAnimation : function (elem,startHeight,endHeight,ratio,steps,intervals,powr) {
		if (elem.changeMemInt) window.clearInterval(elem.changeMemInt);
		var actStep = 0;
		elem.changeMemInt = window.setInterval(
			function() {
				elem.currentHeight = fisheyemenu.easeInOut(startHeight,endHeight,steps,actStep,powr);
				elem.style.width = Math.floor(elem.currentHeight * ratio)+"px";
				elem.style.height = elem.currentHeight+"px";
				actStep++;
				if (actStep > steps) window.clearInterval(elem.changeMemInt);
			}
			,intervals);
	},
	easeInOut : function (minValue,maxValue,totalSteps,actualStep,powr) {
	//Generic Animation Step Value Generator By www.hesido.com
		var delta = maxValue - minValue;
		var stepp = minValue+(Math.pow(((1 / totalSteps)*actualStep),powr)*delta);
		return Math.ceil(stepp);
	},
	imgSmall : function (obj) {
		imgSrc = obj.getAttribute("src");
		var typePos = imgSrc.indexOf(fisheyemenu.imgType, 0);
		var imgName = imgSrc.substr(0, typePos);
		obj.setAttribute("src", imgName+"_small"+fisheyemenu.imgType);
	},
	imgLarge : function (obj) {
		imgSrc = obj.getAttribute("src");
		var typePos = imgSrc.indexOf("_small", 0);
		var imgName = imgSrc.substr(0, typePos);
		obj.setAttribute("src", imgName+fisheyemenu.imgType);
	}
};

