﻿var menuElement="menu"
var minSize = 104;
var maxSize = 168;
var speed = 1       //don't change this
var growrate = 4    //both minsize and max size must be a multiple of this number - increasing this will make the animation faster

var menu=document.getElementById(menuElement).childNodes[0];
var icons=menu.getElementsByTagName("img");
var timer=null;
if(menu.attributes.getNamedItem("class").value == "animated"){  
  for(var i=0;i<icons.length;i++){      
    icons[i].style.height=minSize+"px";    
  }
}

function resizeIcon(currentIcon, grow){
 if(timer!=null)window.clearTimeout(timer);  
  if(currentIcon!=null){
    if(grow==true){
      var update = false;
      for(var i=0;i<icons.length;i++){  
        var size=parseInt(icons[i].style.height.replace("px",""));   
        if(i==currentIcon){ 
          size=size+growrate;
          if(size<=maxSize){
            icons[i].style.height=size+"px"; 
            if(icons[i].src.lastIndexOf("big.png") == -1) icons[i].src=icons[i].src.replace(".png","big.png");   
            update=true         
          }
        }else{
          size=size-growrate;  
          if(size>minSize){
            icons[i].style.height=size+"px";             
            update=true;
          }else if(size==minSize){
            icons[i].style.height=size+"px";             
            icons[i].src=icons[i].src.replace("big.png",".png");
            update=true;
          }             
        }        
      }      
      if(update==true){        
        timer=window.setTimeout("resizeIcon("+currentIcon+",true)",speed); 
      }else{
        timer=null;
      } 
    }else{
      var x=0;
      for(var i = 0;i<icons.length;i++){  
        var size=parseInt(icons[i].style.height.replace("px",""));    
        size=size-growrate;
        if(size>minSize){
          icons[i].style.height=size+"px";           
        }else if(size==minSize){
          icons[i].style.height=minSize+"px";           
          icons[i].src=icons[i].src.replace("big.png",".png");
        }
        if(size>x){
          x=size;          
        }
      }      
      if(x>minSize){        
        timer=window.setTimeout("resizeIcon("+currentIcon+",false)",speed); 
      }else{
        timer=null;
      }
    }
  }        
}
