﻿/*
style:滚动方向,左0、右1、上2、下3
*/
function Scroll(id,width,height,speed,style)
{
    var obj=new Array(),para=new Array(),run;
    this.id=id;
    this.w=width;
    this.h=height;
    this.speed=speed;
    this.style=style;
    var sObj=document.getElementById(id);
    var topObj=this;

    this.init=function(){
        var tmp="";
        if (this.style<=1){
            tmp+="<div id=\""+this.id+"_demo\" style=\"overflow:hidden;width:"+this.w+"px;height:"+this.h+"px;text-align:center;\"> ";
            tmp+="  <table cellspacing=\"0\" cellPpadding=\"0\" align=\"center\" border=\"0\" cellspace=\"0\">";
            tmp+="    <tr> ";
            tmp+="       <td id=\""+this.id+"_demo1\" valign=\"top\">"+sObj.innerHTML+"</td>";
            tmp+="       <td id=\""+this.id+"_demo2\" valign=\"top\"></td>";
            tmp+="    </tr>";
            tmp+="  </table>";
            tmp+="</div>";
        }
        else{
            tmp+="<div id=\""+this.id+"_demo\" style=\"overflow:hidden;width:"+this.w+"px;height:"+this.h+"px;text-align:center;\"> ";
            tmp+="   <div id=\""+this.id+"_demo1\">"+sObj.innerHTML+"</div>";
            tmp+="   <div id=\""+this.id+"_demo2\"></div>";
            tmp+="</div>";
        }
        document.writeln(tmp);
        obj[0]=document.getElementById(this.id+"_demo");
        obj[1]=document.getElementById(this.id+"_demo1");
        obj[2]=document.getElementById(this.id+"_demo2");
        obj[2].innerHTML=obj[1].innerHTML;
    }
    this.marquee=function(){
        switch(topObj.style)
        {
            case 0:
                if(obj[0].scrollLeft>=obj[1].scrollWidth) obj[0].scrollLeft=0;
                else obj[0].scrollLeft++;
                break;
            case 1:
                if(obj[0].scrollLeft<=0) obj[0].scrollLeft=obj[1].scrollWidth;
                else obj[0].scrollLeft--;
                break;
            case 2:
                if(obj[0].scrollTop>=obj[1].scrollHeight) obj[0].scrollTop=0;
                else obj[0].scrollTop++;
                break;
            case 3:
                if(obj[0].scrollTop<=0) obj[0].scrollTop=obj[1].scrollHeight;
                else obj[0].scrollTop--;
                break;  
         }
    }
    this.play=function(){
        if (!sObj) return;
        sObj.style.display="none";
        this.init();
        run=setInterval(this.marquee,this.speed);
        obj[0].onmouseover=function(){clearInterval(run);}
        obj[0].onmouseout=function(){run=setInterval(topObj.marquee,topObj.speed);}
    }
}


/*CSS自适应高度*/

function P7_colH(){ 
 var i,oh,hh,h=0,dA=document.p7eqc,an=document.p7eqa;if(dA&&dA.length){
 for(i=0;i<dA.length;i++){dA[i].style.height='auto';}for(i=0;i<dA.length;i++){
 oh=dA[i].offsetHeight;h=(oh>h)?oh:h;}for(i=0;i<dA.length;i++){if(an){
 dA[i].style.height=h+'px';}else{P7_eqA(dA[i].id,dA[i].offsetHeight,h);}}if(an){
 for(i=0;i<dA.length;i++){hh=dA[i].offsetHeight;if(hh>h){
 dA[i].style.height=(h-(hh-h))+'px';}}}else{document.p7eqa=1;}
 document.p7eqth=document.body.offsetHeight;
 document.p7eqtw=document.body.offsetWidth;}
}
function P7_eqT(){ 
 if(document.p7eqth!=document.body.offsetHeight||document.p7eqtw!=document.body.offsetWidth){
 P7_colH();}
}
function P7_equalCols(){ 
 if(document.getElementById){document.p7eqc=new Array;for(i=0;i<arguments.length;i++){
 document.p7eqc[i]=document.getElementById(arguments[i]);}setInterval("P7_eqT()",10);}
}
function P7_eqA(el,h,ht){ 
 var sp=10,inc=10,nh=h,g=document.getElementById(el),oh=g.offsetHeight,ch=parseInt(g.style.height);
 ch=(ch)?ch:h;var ad=oh-ch,adT=ht-ad;nh+=inc;nh=(nh>adT)?adT:nh;g.style.height=nh+'px';
 oh=g.offsetHeight;if(oh>ht){nh=(ht-(oh-ht));g.style.height=nh+'px';}
 if(nh<adT){setTimeout("P7_eqA('"+el+"',"+nh+","+ht+")",sp);}
}

