﻿// JScript File

function $(sId)
{
  var d = document;
  var oObj = d.getElementById?d.getElementById(sId):d.all?d.all[sId]:d.divs[sId];
  return oObj;
}

function setTransition(){
if (document.all){
  document.images.bannerADrotator.filters.revealTrans.Transition=Math.floor(Math.random()*23);
  document.images.bannerADrotator.filters.revealTrans.apply();
}
}

function MM_openBrWindow(theURL,winName,features)
{
	window.open(theURL,winName,features);
	return false;
}

function playTransition()
{
if (document.all)
  document.images.bannerADrotator.filters.revealTrans.play()
}

function PlayImg(){
if(adNum<bannerAD.length-1)adNum++ ;
  else adNum=0;
    setTransition();
    document.images.bannerADrotator.src=bannerAD[adNum];
    $("bannerADLink").setAttribute("href", bannerADlink[adNum]);
    playTransition();
    theTimer=setTimeout("PlayImg()", 4000);
}

function ResizeImgByFixHeight(ImgD, FitHeight)
{
    var image = new Image();
    image.src = ImgD.src;
    if(image.height <= FitHeight)
    {
        return;
    }
    else
    {
        ImgD.height = FitHeight;
    }
}

function ResizeImg(ImgD, FitWidth, FitHeight)
{
    var image = new Image();
    image.src = ImgD.src;
    if((image.width <= 0) || (image.height <= 0))
    {
        return;
    }
    if(image.width <= FitWidth && image.height <= FitHeight)
    {
        return;
    }
    
    //第一种 宽大,高小; 2. 宽大,高稍大. 3.宽稍大,高大. 4.宽小高大.
    
    if(image.width/image.height >= FitWidth/FitHeight)
    {
    //宽比高厉害.
        ImgD.width = FitWidth;
        ImgD.height = image.height * (FitWidth / image.width);

    } 
    else
    {
        ImgD.height = FitHeight;
        ImgD.width = image.width * (FitHeight / image.height);
    }
}

function AdRotator(sId, iSecs)
{
	this.iNum=0;
	this.sId=sId;
	this.iSecs=iSecs;
	this.asAd=new Array();
	this.asLink=new Array();
	this.asDe=new Array();
	this.aoPreload=new Array();
}

AdRotator.prototype.playTransition=function ()
{
	if (document.all)
		$(this.sId).filters.revealTrans.play();
}

AdRotator.prototype.add=function (sAd, sLink, sDe)
{
	this.asAd[this.asAd.length]=sAd;
	this.asLink[this.asLink.length]=sLink;
	this.asDe[this.asDe.length]=sDe;
}

AdRotator.prototype.start=function ()
{
	for (i=0; i<this.asAd.length; i++)
	{
		this.aoPreload[i]=new Image();
		this.aoPreload[i].src=this.asAd[i];
	}
	if (this.asAd.length >= 1)
	{
		$(this.sId).style.display = "block";
		this.PlayImg();
	}
}

AdRotator.prototype.setTransition=function()
{
	if (document.all)
	{
		$(this.sId).filters.revealTrans.Transition=Math.floor(Math.random()*23);
		$(this.sId).filters.revealTrans.apply();
	}
}

AdRotator.prototype.PlayImg=function()
{
	if(this.iNum<this.asAd.length-1)
		this.iNum++ ;
	  else
		this.iNum=0;

	this.setTransition();
	$(this.sId).src=this.asAd[this.iNum];
	$(this.sId+"Link").setAttribute("href", this.asLink[this.iNum]);
	this.playTransition();
	var oObj=this;
	setTimeout(function(){oObj.PlayImg()}, this.iSecs);
}


function ResumeError() 
{ 
return true; 
} 
window.onerror = ResumeError; 

function LoadAds(loader, ad)
{
var ad = $(ad);
loader = $(loader);
if (ad && loader)
{
	ad.appendChild(loader);
	loader.style.display='block';
	ad.style.display='block';
}
}
