//animatie v2.
var animation=new Array();
var timerAnimation;
var animationPlaying=0;
function ani(pasi,interval,tip,mod,id,pro,start,end,onrun,onend){
 t=new Object();
 t.pasi     = Math.ceil(pasi/3);
 t.index    = 0;
 t.id       =id;
 t.interval = interval*3;
 t.tip      = tip;
 t.mod      = mod;
 t.pro      = pro;
 t.start    = start;
 t.end      = end;
 t.nr       = animation.length;
 t.timer    = null;
 t.val      = start;
 t.onend    = onend?onend:function(){};
 t.onrun    = onrun?onrun:function(){};
 t.timp     =0;
 t.tstart   =0;
 t.splaying =0;
 t.waiting  =null;
 t.play     = function(){
               this.tstart=new Date().getTime(); 
               this.splaying=1;   
               if (animationPlaying==0) 
                {
                 timerAnimation=window.setInterval("AnimationRun()",2);           
                 animationPlaying=1;
                }
             }
 t.stop     = function(){
               this.splaying=0;			   
             } 
 t.reload   =function(_end){
               this.stop();              
               this.start=this.val;
               this.end=_end;
               this.index=0;
               this.timp=0;
               this.tstart=0;
               this.play();
             }     
 t.reinit   =function(_start,_end){
               this.stop();              
               this.start=_start;
               this.end=_end;
               this.index=0;
               this.timp=0;
               this.tstart=0;
               this.play();
             }                             
 animation.push(t);
 return t;                     
}

function fixTimp(that){
   var msec=new Date().getTime();
   that.timp+=(msec-that.tstart);
   that.tstart=msec;
}

function runIt(that){
  
  fixTimp(that);
  var t=Math.floor(that.timp/that.interval);
  that.index=Math.abs(that.index-t)>1?t:that.index;
  
  if (that.index<that.pasi){       
      var temp=doTheJob[that.tip](that.pasi,that.index,that.pro,that.start,that.end,that.id,that.mod);      
      that.onrun(temp);
      that.val=temp;
      that.index++;
     }
  else { var temp=doTheJob[that.tip](that.pasi,that.pasi,that.pro,that.start,that.end,that.id,that.mod);               
         that.val=temp;
         that.stop();
         that.onend();
        } 
}

doTheJob = {
           px : function(pasi,index,pro,start,end,id,mod){
                var temp=new Array();
                for (var q=0;q<id.length;q++){
                  temp[q]=ease[mod](start[q],end[q],pasi,index);
                  document.getElementById(id[q]).style[pro[q]]=temp[q]+"px";               
                  }
                return temp;   
                },
           rgb: function(pasi,index,pro,start,end,id,mod){
                var temp=new Array();
                for (var q=0;q<id.length;q++){
                  temp[q]=new Array();
                  temp[q][0]=ease[mod](start[q][0],end[q][0],pasi,index);
                  temp[q][1]=ease[mod](start[q][1],end[q][1],pasi,index);
                  temp[q][2]=ease[mod](start[q][2],end[q][2],pasi,index);
                  document.getElementById(id[q]).style[pro[q]]="rgb("+temp[q][0]+","+temp[q][1]+","+temp[q][2]+")";               
                  }
                return temp;   
                },     
           opa: function(pasi,index,pro,start,end,id,mod){
                var temp=new Array();
                for (var q=0;q<id.length;q++){
                  temp[q]=ease[mod](start[q],end[q],pasi,index);
                  setOpacity(document.getElementById(id[q]),temp[q]);
                  }
                return temp;    
                }
           }
ease     = {
           liniar:function(start,end,pasi,index){
                if (index==0) return start;
                else if (index==pasi) return end;
                else return start+Math.ceil((index*(end-start))/pasi);
               },
            pow:function(start,end,pasi,index){
                pos=Math.pow(2, 8 * (index/pasi - 1));
                if (index==0) return start;
                else if (index==pasi) return end;
                else return start+Math.ceil((end-start)*pos);
               },
            eio:function(start,end,pasi,index){
                pos=index/pasi;
                if (pos <= 0.5) 
                    pos=Math.pow(2, 8 * (2*pos - 1)) / 2 
                    else  pos=(2 - Math.pow(2, 8 * (2 * (1 - pos) - 1))) / 2;
                if (index==0) return start;
                else if (index==pasi) return end;
                else return start+Math.ceil((end-start)*pos);
               },
            eo :function(start,end,pasi,index){
                if (index==0) return start;
                else if (index==pasi) return end;
                else return start+Math.ceil((end-start)*(1-Math.pow(1-index/pasi,3)));
               },   
            ei :function(start,end,pasi,index){
                if (index==0) return start;
                else if (index==pasi) return end;
                else return start+Math.ceil((end-start)*(Math.pow(index/pasi,3)));
               },               
	        back: function(start,end,pasi,index){
                p=index/pasi;
                x=-1.618;
                if (index==0) return start;
                else if (index==pasi) return end;
                else return start+(end-start)*(Math.pow(p, 2) * ((x+ 1) * p - x));
	            },
        	            
	        backout:function(start,end,pasi,index){
                p=index/pasi;
               	var ts=p*p;
				var tc=ts*p;				
                if (index==0) return start;
                else if (index==pasi) return end;
                else return start+(end-start)*(8.292*tc*ts + -21.88*ts*ts + 22.08*tc + -12.69*ts + 5.1975*p);
	            }                                             
           }    
           
function AnimationRun(){
 var q=0;
 for(var i=0;i<animation.length;i++)
   if (animation[i].splaying==1)
   {
    runIt(animation[i]);
    q=1;
   }
 if (q==0) 
  {
  window.clearInterval(timerAnimation); 
  animationPlaying=0;
  }
}           
           
//Dom stuff
function setOpacity(_el,_op){
 if (_el.style.MozOpacity)   _el.style.MozOpacity = _op/100.0
 else
 if (_el.style.filter)       _el.style.filter     = "Alpha(opacity="+_op+")"
 else
 if (_el.style.opacity)      _el.style.opacity    = _op/100.0;
}           
           


var animationFrom=[115,224];
var animationTo=[323,16];/*[153,186];*/

var a4_animationFrom=[115,224,11,350];//[115,224,98,350];
var a4_animationTo=[323,16,-49,18];/*[223,116,41,118]*/;


var a1=ani(500,1,"px","backout",["meniu1","meniu1"],["width","left"],animationFrom,animationTo);
var a2=ani(500,1,"px","backout",["meniu2","meniu2"],["width","left"],animationFrom,animationTo);           
var a3=ani(500,1,"px","backout",["meniu3","meniu3"],["width","left"],animationFrom,animationTo); 
var a4=ani(500,1,"px","backout",["meniu4","meniu4","smily1","submeniu2"],["width","left","left","left"],a4_animationFrom,a4_animationTo); 
var login=ani(500,1,"px","backout",["login","login"],["width","left"],animationFrom,animationTo); 

var animatii=[];


function play(id)
  {
	  if(!animatii[id])
	      {
		   animatii[id]=ani(2500,1,"rgb","eo",[id],["backgroundColor"],[[255,255,255]],[[220,240,253]]);
		  }
	  animatii[id].reload([[220,240,253]]);
  }
function stop(id)
  {
	   animatii[id].reload([[255,255,255]]);
  }
  
  
 var loginTimer; 
 function loginShow()
 {
	 if (loginTimer) window.clearTimeout(loginTimer);
	 login.reload([328,16,-59]);
 }
 
  function loginHide()
 {
	 if (loginTimer) window.clearInterval(loginTimer);
	 loginTimer=window.setTimeout("login.reload([115,229,11])",2000);
 }
