var animSteps = 10;
var viewWidth=0;
var viewHeight=0;

function getTop() {
   if (window.innerHeight) {
      return window.pageYOffset;
   }  else if (document.documentElement && document.documentElement.scrollTop) {
      return document.documentElement.scrollTop;
   }  else if (document.body) {
      return document.body.scrollTop;
   }
}

function setWidthHeight() {
   if (self.innerWidth) {
      viewWidth = self.innerWidth;
      viewHeight = self.innerHeight;
   }  else if (document.documentElement &&
               document.documentElement.clientWidth) {
      viewWidth = document.documentElement.clientWidth;
      viewHeight = document.documentElement.clientHeight;
   }  else if (document.body) {
      viewWidth = document.body.clientWidth;
      viewHeight = document.body.clientHeight;
   }
} 
function findPosX(obj) {
   var curleft = 0;
   if (obj.offsetParent) {
      while (obj.offsetParent) {
         curleft += obj.offsetLeft;
         obj = obj.offsetParent;
      }
   } else if (obj.x)
      curleft += obj.x;
   return curleft;
}
function findPosY(obj) {
   var curtop = 0;
   if (obj.offsetParent) {
      while (obj.offsetParent) {
         curtop += obj.offsetTop;
         obj = obj.offsetParent;
      }
   }  else if (obj.y)
      curtop += obj.y;
   return curtop;
}   
function init() {
   fixBodyLeft();
   window.onresize=fixBodyLeft;
}
function fixBodyLeft() {
}
function initPage() {
   var topFrame= (top==self);
   if(!topFrame) top.location.href="/";
}
function initPI() {
   fixBubbles();
   initPage();
   setWidthHeight();
   var els = document.getElementsByTagName("img");
   for(var i=0;i<els.length;i++) {
      //alert(els[i].getAttribute("class"));
      if(els[i].className=="popImage" || els[i].getAttribute("class")=="popImage") {

         els[i].onmouseover=function() {
            stopanim=false;

            this.oldPosition = this.style.position;
            this.oldZIndex = this.style.zIndex;
            this.oldWidth = this.style.width;
            this.oldHeight = this.style.height;
            this.oldBorder = this.style.border;

            if(!this.imgLoaded) {
               var parent = this.parentNode;
               var loadingSpan = document.createElement('span');
               loadingSpan.innerHTML='Loading...';
               loadingSpan.className='loading';
               this.loadingSpan=loadingSpan;
               parent.insertBefore(loadingSpan,this);
               this.onload=function() {
                  this.parentNode.removeChild(this.loadingSpan);
                  this.imgLoaded=true;
               } //els[i].onmouseover=function() ;
               this.oldSRC = this.src;
            }

            this.style.position = "absolute";
            this.style.zIndex = 10;

            var xinc = (this.imWidth-this.style.width) / animSteps;
            var yinc = (this.imHeight-this.style.height) / animSteps;
            object = this;

            var imgURL = this.src.substring(
                                    this.src.lastIndexOf("img=")+4);
            imgURL = imgURL.replace(/_48/,'');
            // If this is a moblog image, also get rid of the /php/ in the
            // path.
            // imgURL = imgURL.replace(/\/php\//,'');
            this.src=imgURL;
            if(animoff) {
               this.style.width = this.imWidth+"px";
               this.style.height = this.imHeight+"px";
            } else {
               var curY = findPosY(this);
               var scrY = getTop();
               var endMargin = Math.floor(this.imHeight/2-24);
               //alert("imHeight="+this.imHeight+", curY="+curY+", scrY="+scrY+", endMargin="+endMargin);
               endMargin = ((curY-endMargin)<scrY)?(curY-scrY):endMargin;
               endMargin = Math.max(0,endMargin);
               sizeAnim(48,48,this.imWidth,this.imHeight,animSteps,endMargin,0);
            }

            this.style.border = "3px solid black";
         }
         els[i].onmouseout=function() {
            stopanim=true;
            this.onload=function() {}
            this.style.marginTop="0px";
            this.style.position = this.oldPosition;
            this.style.zIndex = this.oldZIndex;
            //this.style.width = this.oldWidth;
            //this.style.height = this.oldHeight;
            this.style.width = '48px';
            this.style.height = '48px';
            this.style.border = "0";
            this.src = this.oldSRC;

            var nodes=this.parentNode.childNodes;

            for(var i=0;i<nodes.length;i++) {
               if(nodes[i].nodeName=='SPAN') {
                  this.parentNode.removeChild(nodes[i]);
               }
            }
         } //els[i].onmouseout=function()  
      } //if(els[i].className=="popImage" || els[i].getAttribute("clas 
   } //for(var i=0;i<els.length;i++)  
} //function initPI() 
//set object before calling this
var object=false;
var stopanim=false;
var debug = true;
function sizeAnim(startW,startH,eW,eH,numSteps,endMargin,curStep) {
   if(object) {
      if(!stopanim) {
         object.style.width = (startW + (eW-startW)*curStep/numSteps )+"px";
         var height = startH + (eH-startH)*curStep/numSteps;
         object.style.height = height+"px";
         var step1 = (height-48);
         var step2 = step1 / 2;
         var margin = endMargin*curStep/numSteps;
         object.style.marginTop = '-'+margin+"px";
         if(curStep < numSteps) {
            setTimeout('sizeAnim('+startW+','+startH+','+eW+','+eH+','+numSteps+','+endMargin+','+(curStep+1)+')',10);
         } else {
            //alert("doctop="+document.getTop()+", imtop="+findPosY(object));
         }
      }
   } //if(object) 
}
function fixBubbles() {
  var els = document.getElementsByTagName("DIV");
  for(var i=0;i<els.length;i++) {
     var e=els[i];
     if(e.className=="bubble") {
        var content = e.innerHTML;
        e.innerHTML='<div class="topbar"></div><div class="wrap"><div class="content">'+content+'</div></div><div class="bottombar"></div>';
     }
  }
}
var mHover = function() {
   var m = document.getElementById("mainmenu");
   if(!m) return;
   var els = m.getElementsByTagName("LI");
   for (var i=0; i<els.length; i++) {
      els[i].onmouseover=function() {
         this.className+=" mhover";
      }
      els[i].onmouseout=function() {
         this.className=this.className.replace(new RegExp(" mhover\\b"), "");
      }
   } 
}
if (window.attachEvent) window.attachEvent("onload", mHover);
window.onresize=setWidthHeight;


