/* Fisheye Menu v1.0 
   Written by Marc Grabanski (m@marcgrabanski.com)

   Copyright (c) 2007 Marc Grabanski (http://marcgrabanski.com/code/fisheye-menu)
   Dual licensed under the GPL (http://www.gnu.org/licenses/gpl-3.0.txt) and 
   CC (http://creativecommons.org/licenses/by/3.0/) licenses. "Share or Remix it but please Attribute the authors."
   Date: 10-05-2007  */

var indice = 0;

function getMaxIndice(tot) {
	indice = tot;
	fisheyemenu.init();
}

var fisheyemenu = {
	startSizeW : 37,
	startSizeH : 100,
	endSizeW : 48,
	endSizeH : 130,
	imgType : ".jpg",
	init : function () {
		for (var jkk=1; jkk<=indice; jkk++) {
			var animElements = $("fisheye_menu"+jkk+"").getElementsByTagName("img");
			for(var i=0; i<animElements.length; i++) {
				var y = animElements[i];
				y.style.width = fisheyemenu.startSizeW+'px';
				y.style.height = fisheyemenu.startSizeH+'px';
				fisheyemenu.imgSmall(y);
				animElements[i].onmouseover = changeSize;
				animElements[i].onmouseout = restoreSize;
			}
		}

		function changeSize() {
			fisheyemenu.imgLarge(this);
			if (!this.currentWidth) this.currentWidth = fisheyemenu.startSizeW;
			if (!this.currentHeight) this.currentHeight = fisheyemenu.startSizeH;
			fisheyemenu.resizeAnimation(this,this.currentWidth,fisheyemenu.endSizeW,this.currentHeight,fisheyemenu.endSizeH,15,10,0.333);
		}
		function restoreSize() {
			if (!this.currentWidth && !this.currentHeight) return;
			fisheyemenu.resizeAnimation(this,this.currentWidth,fisheyemenu.startSizeW,this.currentHeight,fisheyemenu.startSizeH,15,10,0.5);
			fisheyemenu.imgSmall(this);
		}
	},
	resizeAnimation : function (elem,startWidth,endWidth,startHeight,endHeight,steps,intervals,powr) {
		if (elem.widthChangeMemInt) window.clearInterval(elem.widthChangeMemInt);
		var actStep = 0;
		elem.widthChangeMemInt = window.setInterval(
			function() {
				elem.currentWidth = fisheyemenu.easeInOut(startWidth,endWidth,steps,actStep,powr);
				elem.currentHeight = fisheyemenu.easeInOut(startHeight,endHeight,steps,actStep,powr);
				elem.style.width = elem.currentWidth+"px";
				elem.style.height = elem.currentHeight+"px";
				actStep++;
				if (actStep > steps) window.clearInterval(elem.widthChangeMemInt);
			}
			,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 - 4));
		var imgNameSmall = imgName + "_small";
		obj.setAttribute("src", imgNameSmall + fisheyemenu.imgType);
	},
	imgLarge : function (obj) {
		imgSrc = obj.getAttribute("src");
		var typePos = imgSrc.indexOf(fisheyemenu.imgType, 0);
		var imgName = imgSrc.substr(0, (typePos - 6));
		var imgNameBig = imgName + "_big";
		obj.setAttribute("src", imgNameBig + fisheyemenu.imgType);
	}
}