var isSwf=false;
var swfFunct='';

function getLinkTopSwf(bgSrc, popSwfNo, linkName, bgWidth, bgHeight) {
  var el = document.getElementById(linkName);
  var totalOffsetTop = 0;
  var totalOffsetLeft = 0;
  swfFunct = popSwfNo;
  popClose();
  while (el != null) {
    totalOffsetTop += el.offsetTop;
    totalOffsetTop -= el.scrollTop;
    totalOffsetLeft += el.offsetLeft;
    el = el.offsetParent;
  }
  bgW = bgWidth;
  bgH = bgHeight;
  bgWidthMax = bgW;
  bgRatio = bgW/bgH;

  document.popBgImg.src=bgSrc;
  document.getElementById('pop').style.width = bgW;
  document.getElementById('pop').style.height = bgH;
  document.getElementById('pop').style.top = (totalOffsetTop-(bgH)/2)+"px";
  document.getElementById('pop').style.left = (totalOffsetLeft-(bgW/2))+"px";
  document.popBgImg.style.top = (bgH/2)+"px";
  document.popBgImg.width = 0;
  document.popImg.width = 0;
  document.getElementById('pop').style.display='block';
  bgImgWidth=0;
  bgImgTop=bgH/2;
  bgImgLeft=bgW/2;

  isSwf=true;
  scaleBg();
}

function getLinkTop(bgSrc, imgSrc, linkName, bgWidth, bgHeight, imgWidth, imgHeight) {
  var el = document.getElementById(linkName);
  var totalOffsetTop = 0;
  var totalOffsetLeft = 0;
  popClose();
  while (el != null) {
    totalOffsetTop += el.offsetTop;
    totalOffsetTop -= el.scrollTop;
    totalOffsetLeft += el.offsetLeft;
    el = el.offsetParent;
  }
  bgW = bgWidth;
  bgH = bgHeight;
  bgRatio = bgW/bgH;
  imgW = imgWidth;
  imgH = imgHeight;
  ratio=imgW/imgH;
  if(ratio > bgRatio) {
//     alert('ratio = '+ratio+' > '+bgRatio);
    if(bgW > imgW) {
      bgWidthMax=imgW;
      ImgWidthMax=imgW-30;
    }else {
      bgWidthMax=bgW;
      ImgWidthMax=bgW-30;
    }
  }else {
//     alert('ratio = '+ratio+' < '+bgRatio);
    if(bgH > imgH) {
      bgWidthMax=bgRatio*imgH;
      ImgWidthMax=imgW-30;
//       alert(bgWidthMax);
    } else {
      bgWidthMax=bgW;
      ImgWidthMax=bgH*ratio-(30*ratio);
//       alert(bgWidthMax+";	 imgWMax="+ImgWidthMax);
    }
  }


  document.popBgImg.src=bgSrc;
  document.popImg.src=imgSrc;
  document.getElementById('pop').style.width = bgWidthMax;
  document.getElementById('pop').style.height = bgWidthMax/bgRatio;
  document.getElementById('pop').style.top = (totalOffsetTop-(bgWidthMax/bgRatio)/2)+"px";
  document.getElementById('pop').style.left = (totalOffsetLeft-(bgWidthMax/2))+"px";
  document.popBgImg.style.top = ((bgWidthMax/bgRatio)/2)+"px";
  document.popImg.style.top = ((bgWidthMax/bgRatio)/2)+"px";
  document.popBgImg.width = 0;
  document.popImg.width = 0;
  document.getElementById('pop').style.display='block';
  bgImgWidth=0;
  bgImgTop=(bgWidthMax/bgRatio)/2;
  bgImgLeft=bgWidthMax/2;
  ImgWidth=0;
  ImgTop=((bgWidthMax/bgRatio)/2);
  ImgLeft=bgWidthMax/2;
  isSwf=false;
  swfFunct='';
  scaleBg();
}

var bgImgWidth=0;
var bgWidthMax=0;
var bgImgTop=0;
var bgImgLeft=0;
var alertTimerId = 0;
var bgW=0;
var bgH=0;
var bgRatio=0;

function scaleBg() {
  bgImgWidth+=Math.ceil(bgWidthMax/10);
  bgImgTop-=Math.ceil((bgWidthMax/bgRatio)/20);
  bgImgLeft-=(bgWidthMax/20)	;
//   alert(bgWidthMax);
  if(bgImgWidth<bgWidthMax) {
    document.popBgImg.style.top = bgImgTop+"px";
    document.popBgImg.style.left = bgImgLeft+"px";
    document.popBgImg.width = bgImgWidth;
    alertTimerId = setTimeout("scaleBg()",50);
  } else {
    document.popBgImg.style.top = "0px";
    document.popBgImg.style.left = "0px";
    document.popBgImg.width = bgWidthMax;
    //     alert('l='+document.popBgImg.style.left+'  t='+document.popBgImg.style.top)
    if(isSwf==true) {
      document.getElementById('backPopLink').style.top='-20px';
      document.getElementById('backPopLink').style.background='#ffffff';
    }else {
      document.getElementById('backPopLink').style.top='13px';
      document.getElementById('backPopLink').style.background='transparent';
    }
    if(document.popBack.width) document.getElementById('backPopLink').style.left=(bgWidthMax-document.popBack.width-14)+'px';
    else document.getElementById('backPopLink').style.right='14px';
    document.popBack.style.display='block';
    if(isSwf==false) alertTimerId = setTimeout("scaleImg()",50);
    else {
      setTimeout(swfFunct+"()",0);
      document.getElementById('popSwf').style.display='block';
    }
  }
}

var ImgWidth=0;
var ImgWidthMax=0;
var ImgTop=0;
var ImgLeft=0;
var alertTimerId = 0;
var imgH=0;
var imgW=0;
var ratio=0;

function scaleImg() {
  ImgWidth+=Math.ceil(ImgWidthMax/10);
  ImgTop-=Math.ceil((ImgWidthMax/ratio)/20);
  ImgLeft-=Math.ceil(ImgWidthMax/20);

  if(ImgWidth<ImgWidthMax) {
    document.popImg.style.top = ImgTop+"px";
    document.popImg.style.left = ImgLeft+"px";
    document.popImg.width = ImgWidth;
    alertTimerId = setTimeout("scaleImg()",50);
  } else {
    document.popImg.style.top = (((bgWidthMax/bgRatio)-(ImgWidthMax/ratio))/2)+"px";
    document.popImg.style.left = (((bgWidthMax)-(ImgWidthMax))/2)+"px";
    document.popImg.width = ImgWidthMax;
  }
}

function popClose() {
  document.getElementById('pop').style.display='none';
  document.getElementById('popSwf').style.display='none';
  document.popBack.style.display='none';
}
