/* 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 fisheyemenu = {
	startSize : 100,
	endSize : 160,
	imgType : ".jpg",
	init : function () {
		//var animElements = document.getElementById("fisheye_menu").getElementsByTagName("img");
		var animElements = document.getElementById("menuslider").getElementsByTagName("img");
		var titleElements = document.getElementById("menuslider").getElementsByTagName("span");
		for(var j=0; j<titleElements.length; j++) {
			titleElements[j].style.display = 'block';
			$(titleElements[j]).html("<pre>"+$(titleElements[j]).html()+"</pre>")
		}
		var flt = 0; var lt;
		for(var i=0; i<animElements.length; i++) {
			var y = animElements[i];
			//y.style.width = fisheyemenu.startSize+'px';
			y.style.height = fisheyemenu.startSize+'px';
			//alert($(y.parentNode).width())
			if (i==0) {
				$(y.parentNode).css({ top:"0", left:flt });
			}
			else {
				lt = $(animElements[i-1].parentNode).width()+11;
				flt += lt; 
				$(y.parentNode).css({ top:"0", left:flt });
			}
			/*else {var flt = lt; if (i==3) { var lt = lt+y.width+21; } else { var lt = lt+134+21; } }
			$(y.parentNode).css({ top:"0", left:lt });*/
			
			fisheyemenu.imgSmall(y);
			animElements[i].onmouseover = changeSize;
			animElements[i].onmouseout = restoreSize;
		}
		function changeSize() {
			//alert(this.lastChild)
			//var img = this.lastChild
			fisheyemenu.imgLarge(this);
			//var x = this.parentNode.getElementsByTagName("span");
			//alert(this.parentNode.firstChild.firstChild.nodeValue);
			$(this.parentNode).css("z-index","20");
			/*var x = this.parentNode.firstChild.firstChild;
			x.parentNode.style.fontSize = "18px";*/
			
			if (!this.currentWidth) this.currentWidth = fisheyemenu.startSize;
			/*if (text.nodeValue == "Бронювання") {
				fisheyemenu.resizeAnimation(this,this.currentWidth,fisheyemenu.endSize,15,10,0.333);
			}
			else {*/
				fisheyemenu.resizeAnimation(this,this.currentWidth,fisheyemenu.endSize,15,10,0.333);
			//}

            //alert(span.childNodes.length);
			//for(var i=0; i<span.childNodes.length; i++) {
			//alert(document.childNodes.item(0));
			//span.childNode[1].style.fontSize = "25px";
			//}
		}
		function restoreSize() {
			//var x = this.parentNode.getElementsByTagName("span");
			/*var x = this.parentNode.firstChild.firstChild;
			x.parentNode.style.fontSize = "18px";*/
			
			$(this.parentNode).css("z-index","15");
			
			if (!this.currentWidth) return;
			/*if (text.nodeValue == "Бронювання") {
				fisheyemenu.resizeAnimation(this,this.currentWidth,120,15,10,0.5);
			}
			else {*/
				fisheyemenu.resizeAnimation(this,this.currentWidth,fisheyemenu.startSize,15,10,0.5);
			//}
			fisheyemenu.imgSmall(this);
		}
	},
	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.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)
	},
	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);
	}
}

// Add event with wide browser support
if ( typeof window.addEventListener != "undefined" )
    window.addEventListener( "load", fisheyemenu.init, false );
else if ( typeof window.attachEvent != "undefined" )
    window.attachEvent( "onload", fisheyemenu.init );
else {
    if ( window.onload != null ) {
        var oldOnload = window.onload;
        window.onload = function ( e ) {
            oldOnload( e );
            fisheyemenu.init();
        };
    }
    else
        window.onload = fisheyemenu.init;
}
