﻿// JScript 文件是用于产生对联广告by鲍海峰
var advCollection;
var delta = 0.8;
var Toppx = 200;   //上端位置
var indexs =-1;
  function setColor(obj)
  {
     obj.style.color = "green";
  }
  function setLeaveColor(obj)
  {
     obj.style.color = "red";
  }      
function makeAdvs()
{
	this.advs = new Array;
}
makeAdvs.prototype.insertAdv =  function(id,left,top,divInnerHtml,index)
{   
	var ClosebuttonHtml = '<div align="right" style="position: absolute;bottom:0px;right:0px;margin:1px;padding:2px;z-index:2000;"><a href="###" onclick="closeAdvs('+index+')" onmouseover="setColor(this);" onmouseleave="setLeaveColor(this)" style="color:red;text-decoration:none;font-size:12px;">关闭</a></div>';
    document.write('<DIV id='+id+' style="Z-INDEX: 10; POSITION: absolute;background-color:#EEEEE2;  width:100px; height:320px;left:'+(typeof(left)=='string'?eval(left):left)+';top:'+(typeof(top)=='string'?eval(top):top)+'">'
                 +'<div align="center" style="background-color:#EEEEE2;width:100%; height:100%;">' +divInnerHtml+'</div>'
                 +ClosebuttonHtml
                 +'</DIV>');
	var advItem = {};
	advItem.adv = document.getElementById(id);
	advItem.left = left;
	advItem.top = top;
	advItem.index =index;
	this.advs[this.advs.length]	= advItem;
	
	if(index==0)
	{
        var L = document.getElementById("CoupletAdversFrameL");
         if(L == null){
            L = document.createElement("IFRAME");
            L.name = "CoupletAdversFrameL";
            L.id = "CoupletAdversFrameL";
           
            L.style.cssText="position:absolute;left:0px;top:0px;";
            L.style.zIndex=-100;                                    
            L.setAttribute("frameborder", "0", 0);
            L.width = document.getElementById(id).offsetWidth;
            L.height = document.getElementById(id).offsetHeight;
         }
         document.getElementById(id).appendChild(L);
     }
     else
     {
         var R = document.getElementById("CoupletAdversFrameR");
         if(R == null){
            R = document.createElement("IFRAME");
            R.name = "CoupletAdversFrameR";
            R.id = "CoupletAdversFrameR";
           
            R.style.cssText="position:absolute;left:0px;top:0px;";
            R.style.zIndex=-100;                                    
            R.setAttribute("frameborder", "0", 0);
            R.width = document.getElementById(id).offsetWidth;
            R.height = document.getElementById(id).offsetHeight;
         }
         document.getElementById(id).appendChild(R); 
     }     
}
makeAdvs.prototype.play = function()
{advCollection = this.advs;
 setInterval("play()",10);}
function play()
{
	if(screen.width <= 800)
	{
		for(var index =0;index < advCollection.length;index ++)
	    {
	    	advCollection[index].adv.style.display ="none";
	    } 
		return;
	}
	if(indexs >= 0)
	{
	    for(var index =0;index < advCollection.length;index ++)
	     {
	        if(advCollection[index].index == indexs)
	        {
	            advCollection[index].adv.style.display ="none";
	            advCollection[index].index = -1;
	         }
	      }
	}
	for(var index =0 ; index < advCollection.length;index++)
    {
       if(advCollection[index].index==-1)
          continue;
    	var adv = advCollection[index].adv;
    	var left = typeof(advCollection[index].left)=="string"?eval(advCollection[index].left):advCollection[index].left;
    	var top = typeof(advCollection[index].top)=="string"?eval(advCollection[index].top):advCollection[index].top;
    	if(adv.offsetLeft !=(document.body.scrollLeft+left))
    	{
    		var dx =(document.body.scrollLeft+left-adv.offsetLeft)*delta;
    		dx =(dx>0?1:-1)*Math.ceil(Math.abs(dx));
    		adv.style.left =(adv.offsetLeft +dx)+"px";
    	}
        adv.style.top =document.documentElement.scrollTop+Toppx+"px";;
    	adv.style.display="";
    }
}

function closeAdvs(index)
{
    indexs = index;
	return;
}

