var fadeFactor=0;
var fadeDegree=10;
var fadeSpeed=10;
var fadeDirection=0;
var fadeOut;
var imgLeft=0;
var imgTop=0;
var imgWidth=0;
var imgHeight=0;
var timer;

function fadeAll(valDiv){
  var newFadeVal=(fadeFactor/100);
  if(document.all)
    document.getElementById(valDiv).style.filter='alpha(Opacity='+fadeFactor+')';
  else 
    document.getElementById(valDiv).style.MozOpacity=(newFadeVal);
  
  nLeft = imgLeft-((imgWidth/2)*newFadeVal);
  nTop  = imgTop-((imgHeight/2)*newFadeVal);
  nWidth  = imgWidth+((imgWidth)*newFadeVal);
  nHeight = imgHeight+((imgHeight)*newFadeVal);
  
  document.getElementById("imgzoom").style.left=nLeft+'px';
  document.getElementById("imgzoom").style.top=nTop+'px';
  document.getElementById("ig").style.width=nWidth+'px';
  document.getElementById("ig").style.height=nHeight+'px';
  
  if(fadeDirection==1)
    tempofadeM(fadeFactor,valDiv);
  else 
    tempofade(fadeFactor,valDiv);
}

function tempofade(fad,valDiv) {
   fadeFactor=fadeFactor+fadeDegree;
   if (fadeFactor<=100)
      fadeOut=setTimeout("fadeAll('"+valDiv+"')",fadeSpeed);
   else {
   	// alert("width=" + document.getElementById("ig").style.width); 
   	// alert("height=" + document.getElementById("ig").style.height); 
      return;
   }
}

function tempofadeM(fad,valDiv) {
   fadeFactor=fadeFactor-fadeDegree;
   if(fadeFactor>0)
      fadeOut=setTimeout("fadeAll('"+valDiv+"')",fadeSpeed);
   else {
     document.getElementById("imgzoom").style.display="none";
     return;
   }
}

function zoomIn(oThis,destUrl,imgName) {
   clearTimeout(fadeOut);
   fadeDirection=0;
   iHtmlImg='<a href="'+destUrl+'"><img id="ig" src="'+imgName+'" style="border:solid 1px #6f002f;"></a>';
   imgLeft=getParentLeft(oThis,oThis.offsetParent.tagName,oThis.offsetLeft);
   imgTop=getParentTop(oThis,oThis.offsetParent.tagName,oThis.offsetTop);
   imgWidth=oThis.width;
   imgHeight=oThis.height;
   document.getElementById("imgzoom").onmouseout=function(){zoomOut();}
   document.getElementById("imgzoom").style.left=imgLeft+'px';
   document.getElementById("imgzoom").style.top=imgTop+'px';
   document.getElementById("imgzoom").style.width=imgWidth+'px';
   document.getElementById("imgzoom").style.height=imgHeight+'px';
   document.getElementById("imgzoom").innerHTML=iHtmlImg;
   timer = setTimeout("showZoom()", 400);
}

function zoomBig(oThis,destUrl,imgName) {
   iHtmlImg='<a href="'+destUrl+'"><img id="ig" src="'+imgName+'" style="border:solid 1px #6f002f;"></a>';
   imgLeft=getParentLeft(oThis,oThis.offsetParent.tagName,oThis.offsetLeft);
   imgTop=getParentTop(oThis,oThis.offsetParent.tagName,oThis.offsetTop);
   imgWidth=427; // oThis.width;
   imgHeight=512; //oThis.height;
   document.getElementById("imgzoom").innerHTML=iHtmlImg;
   document.getElementById("imgzoom").style.left=imgLeft+'px';
   document.getElementById("imgzoom").style.top=imgTop+'px';
   document.getElementById("imgzoom").style.width=imgWidth+'px';
   document.getElementById("imgzoom").style.height=imgHeight+'px';
   document.getElementById("imgzoom").style.display='block';
   document.getElementById("imgzoom").onclick=function(){zoomOutBig();}
}

function showZoom() {
   clearTimeout(timer);	
   fadeFactor=0;
   document.getElementById("imgzoom").style.MozOpacity=0;
   document.getElementById("imgzoom").style.display="";
   fadeAll("imgzoom");
}

function getParentTop(oThis,p,pos){
  oN=oThis;
  pN=p;
  while(pN!="BODY"){
     pos=pos+oN.offsetParent.offsetTop;
     pN=oN.offsetParent.tagName;
     oN=oN.offsetParent;
  }
  return pos;
}

function getParentLeft(oThis,p,pos2){
  oN=oThis;
  pN=p;
  while(pN!="BODY") {
    pos2=pos2+oN.offsetParent.offsetLeft;
    pN=oN.offsetParent.tagName;
    oN=oN.offsetParent;
  }
  return pos2;
}

function zoomOut() {
  fadeDirection=1;
  clearTimeout(timer);  
  fadeAll("imgzoom");
}

function zoomOutBig() {
   document.getElementById("imgzoom").innerHTML='';
   document.getElementById("imgzoom").style.display='none';
}

function cancelZoom() {
   clearTimeout(timer);
}

