﻿if (document.getElementById && document.getElementsByTagName) {
if (window.addEventListener) window.addEventListener('load', initAnims, false);
else if (window.attachEvent) window.attachEvent('onload', initAnims);
}

function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}

function showcontact() {
	estadoinicial_contacto = 0;
	estadofinal_contacto = 208;

	if(getInternetExplorerVersion() == 7)
	{
		document.getElementById("contactlabel").style.position = "static";
	}

	if (document.getElementById("contactlabel").style.height == "0px")
	{
		widthChange2();
	} else {
		widthRestore2();
	}
	
		function widthChange2() {
			if (!document.getElementById("contactlabel").currentWidth) document.getElementById("contactlabel").currentWidth = estadoinicial_contacto;
			doWidthChangeMem(document.getElementById("contactlabel"),document.getElementById("contactlabel").currentWidth,estadofinal_contacto,20,20,0.333);
			}

		function widthRestore2() {
			if (!document.getElementById("contactlabel").currentWidth) return;
			doWidthChangeMem(document.getElementById("contactlabel"),document.getElementById("contactlabel").currentWidth,estadoinicial_contacto,20,20,0.5);
			}

}

function initAnims() {
		estadoinicial = 100;
		estadofinal = 135;


		var animElements = document.getElementById("menutop").getElementsByTagName("p");
		for(var i=0; i<animElements.length; i++) {
			animElements[i].onmouseover = widthChange;
			animElements[i].onmouseout = widthRestore;
			}

		function widthChange() {
			if (!this.currentWidth) this.currentWidth = estadoinicial;
			doWidthChangeMem(this,this.currentWidth,estadofinal,10,10,0.333);
			}

		function widthRestore() {
			if (!this.currentWidth) return;
			doWidthChangeMem(this,this.currentWidth,estadoinicial,10,10,0.5);
			}

	}


function doWidthChangeMem(elem,startWidth,endWidth,steps,intervals,powr) {
	if (elem.widthChangeMemInt) window.clearInterval(elem.widthChangeMemInt);
	var actStep = 0;
	elem.widthChangeMemInt = window.setInterval(
		function() {
			elem.currentWidth = easeInOut(startWidth,endWidth,steps,actStep,powr);
			elem.style.height = elem.currentWidth+"px";			
			actStep++;
			if (actStep > steps) window.clearInterval(elem.widthChangeMemInt);
		}
		,intervals)

}

function easeInOut(minValue,maxValue,totalSteps,actualStep,powr) {
	var delta = maxValue - minValue;
	var stepp = minValue+(Math.pow(((1 / totalSteps)*actualStep),powr)*delta);
	return Math.ceil(stepp)
}
