/* 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  */
   
function onLoad()
{
    var menu = new FisheyeMenu();
}

FisheyeMenu.prototype.startSize = 80;
FisheyeMenu.prototype.endSize = 128;
FisheyeMenu.prototype.imgType = ".jpg";

function FisheyeMenu()
{
    this.Initialise = function()
    {
        if (document.getElementById("fisheye_menu")) 
        {
		    var animElements = document.getElementById("fisheye_menu").getElementsByTagName("img");
		    var titleElements = document.getElementById("fisheye_menu").getElementsByTagName("span");
		    
		    for(var j=0; j<titleElements.length; j++) 
		    {
			    titleElements[j].style.display = 'none';
		    }
		    
		    for(var i=0; i<animElements.length; i++) 
		    {
			    var y = animElements[i];
			    y.style.width = FisheyeMenu.prototype.startSize+'px';
			    y.style.height = FisheyeMenu.prototype.startSize+'px';
			    FisheyeMenu.prototype.imgSmall(y);
			    animElements[i].onmouseover = FisheyeMenu.prototype.changeSize;
			    animElements[i].onmouseout = FisheyeMenu.prototype.restoreSize;
		    }
		}
    }
    
    this.Initialised = this.Initialise();
}

FisheyeMenu.prototype.imgSmall = function(obj)
{
	imgSrc = obj.getAttribute("src");
	var typePos = imgSrc.indexOf(this.imgType, 0);
	var imgName = imgSrc.substr(0, typePos);
	obj.setAttribute("src", imgName+"_small"+FisheyeMenu.prototype.imgType);
}

FisheyeMenu.prototype.imgLarge = function(obj)
{
	imgSrc = obj.getAttribute("src");
	var typePos = imgSrc.indexOf("_small", 0);
	var imgName = imgSrc.substr(0, typePos);
	obj.setAttribute("src", imgName+FisheyeMenu.prototype.imgType);
}

FisheyeMenu.prototype.changeSize = function()
{
    FisheyeMenu.prototype.imgLarge(this);
    var x = this.parentNode.getElementsByTagName("span");
    x[0].style.display = 'block';
    if (!this.currentWidth) this.currentWidth = FisheyeMenu.prototype.startSize;
    FisheyeMenu.prototype.resizeAnimation(this,this.currentWidth,FisheyeMenu.prototype.endSize,15,10,0.333);
}

FisheyeMenu.prototype.restoreSize = function()
{
    var x = this.parentNode.getElementsByTagName("span");
    x[0].style.display = 'none';
    if (!this.currentWidth) return;
    FisheyeMenu.prototype.resizeAnimation(this,this.currentWidth,FisheyeMenu.prototype.startSize,15,10,0.5);
    FisheyeMenu.prototype.imgSmall(this);
}

FisheyeMenu.prototype.resizeAnimation = function (elem,startWidth,endWidth,steps,intervals,powr) 
{
	if (elem.widthChangeMemInt) window.clearInterval(elem.widthChangeMemInt);
	var actStep = 0;
	elem.widthChangeMemInt = window.setInterval(
		function() 
		{
			elem.currentWidth = FisheyeMenu.prototype.easeInOut(startWidth,endWidth,steps,actStep,powr);
			elem.style.width = elem.currentWidth+"px";
			elem.style.height = elem.currentWidth+"px";
			actStep++;
			if (actStep > steps) window.clearInterval(elem.widthChangeMemInt);
		}
		,intervals)
}

FisheyeMenu.prototype.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)
}
	
// Add event with wide browser support
if ( typeof window.addEventListener != "undefined" )
        window.addEventListener( "load", onLoad, false );
else if ( typeof window.attachEvent != "undefined" )
    window.attachEvent( "onload", onLoad );
else {
    if ( window.onload != null ) {
        var oldOnload = window.onload;
        window.onload = function ( e ) {
            oldOnload( e );
            onLoad();
        };
    }
    else
        window.onload = onLoad;
}