var img=new Image(),tmr;
var frames=8,tmr=null,count=0,c,images=[],i=0,j=0,cX,cY,cW,cH,cmd,current,begin=false,act,img,ref,k=0;
var ie=(navigator.appVersion.indexOf('IE')!=-1);

function startLoad(path,command){
   document.images["loader"].style.left="-2000px";
   document.getElementById("loading").style.left=(ie)?(((document.body.offsetWidth-220)/2)+document.body.scrollLeft):(((window.innerWidth-220)/2)+window.pageXOffset);
   document.getElementById("loading").style.top=(ie)?(((document.body.offsetHeight-34)/2)+document.body.scrollTop):(((window.innerHeight-34)/2)+window.pageYOffset);
   img=new Image();
   img.src=path;
   cmd=command;
   setTimeout('checkLoad()',500);
}
function checkLoad(){
   clearTimeout(tmr)
   if(img.complete){
       document.getElementById("loading").style.left="-2000px";
       document.images["loader"].style.left="-2000px";
       calc(cmd);
       return
   }
   
   tmr=setTimeout('checkLoad()',100)
}
function calc(command,xx,yy){

              c=[];
              w=img.width;
              h=img.height;
              if(!xx){
                  x=(ie)?(((document.body.offsetWidth-w)/2)+document.body.scrollLeft):(((window.innerWidth-w)/2)+window.pageXOffset);
                  y=(ie)?(((document.body.offsetHeight-h)/2)+document.body.scrollTop):(((window.innerHeight-w)/2)+window.pageYOffset);
                  count=-1;
              }
              cW=w/(frames*4);
              cH=h/(frames*4);
              cX=x+(w/2);
              cY=y+(h/2);
              cmd=command;                                      
              for(i=0;i<((frames*4)+4);i+=4){
                  c[i]  =Math.round(cX-((cW*i)/2));
                  c[i+1]=Math.round(cY-((cH*i)/2));
                  c[i+2]=Math.round(cW*i);
                  c[i+3]=Math.round(cH*i)
              }
              document.images["loader"].src=img.src;     
              popup();
   
}
function popup(){

    clearTimeout(tmr);
    if(cmd=='popup'){
          count++              
          if(count==9){
               return
          }
    }
    if(cmd=='hide'){
          count--
          if(count==-1){
               return   
          }  
    }    
    document.images["loader"].style.left=c[count*4]+"px";
    document.images["loader"].style.top=c[(count*4)+1]+"px";
    document.images["loader"].style.width=c[(count*4)+2]+"px";
    document.images["loader"].style.height=c[(count*4)+3]+"px";

    tmr=setTimeout('popup()',5)
}
function fade(){
    clearTimeout(tmr3);
    if(f==95)
        popup();
}
function close_(){
    //cmd='hide';
    calc('hide',x,y);
}
var tmr2;
function toolbar(){
    clearTimeout(tmr2)
    var tx=(x+w)-70;
    var ty=y+2;
    document.images["close"].style.top=ty+"px";
    document.images["close"].style.left=tx+"px";
}
function hide(){
    document.images['close'].style.left='-2000px';
}
var m=false;
function Mc_move(){
   if(m&&ie){
       document.images["loader"].style.left=event.clientX-offX;
       document.images["loader"].style.top=event.clientY-offY;
       return false
   }
   return true
}
function Mc_down(){
   if(ie){
      m=true;
      offX=event.clientX-document.images["loader"].offsetLeft;
      offY=event.clientY-document.images["loader"].offsetTop;
      return false
   }
   return true
} 
function Mc_up(){
   if(m&&ie){
      m=false;
      x=document.images["loader"].offsetLeft;
      y=document.images["loader"].offsetTop; 
      return false
   }
   return true
}