// browser check
var ScrollPicsBrowserType = (navigator.appVersion.match(/MSIE/) && !navigator.appVersion.match(/MSIE\s8\.0/)) ? 'IE' : 'NS' ;
// JavaScript Document
function gnway_scroll_pics_by_tongfu(ex, pics, w, h, sec, urls){
    this.tfex=ex;
    this.tfpics=pics;
    this.tfurls=urls;
    this.tfobjs;
    this.tfwidth=w;
    this.tfheight=h;
    this.num;
    this.tfDoc;
    this.tfBody;
    this.tfStepTop;
    this.tfCurTop;
    this.tfMaxTop;
    this.tfInterval;
    this.tfStepSpeed;
    this.tfStepSpeed2;
    this.tfButtons;
    this.tfCurObj;
    this.tfCurId;
    this.tfTimeout;
    this.tfTimeoutSec=sec;
    this.init=function(){
        this.num=this.tfpics.length;
        this.tfStepTop = 0;
        this.tfCurTop = 0;
        this.tfMaxTop = 0;
        this.tfInterval = null;
        this.tfStepSpeed = 60;
        this.tfStepSpeed2 = 0;
        this.tfTimeout = null;
    }
    this.draw=function(){
        document.write('<iframe id="scroll_pics_'+this.tfex+'" src="about:blank" name="name_scroll_pics_'+this.tfex+'" width="'+this.tfwidth+'" height="'+this.tfheight+'" frameborder="no"></iframe>');
    }
    this.show=function(){
        this.tfCurObj = null;
        this.tfCurId = null;
        myObj = (ScrollPicsBrowserType == 'IE') ? window.frames['scroll_pics_'+this.tfex] : document.getElementById('scroll_pics_'+this.tfex) ;
        myDoc = this.tfDoc = (ScrollPicsBrowserType == 'IE') ? myObj.document : myObj.contentWindow.document ;
        myDoc.close();
        myDoc.open();
        myDoc.write('<html><head><title></title></head><body style="margin:0px;"></body></html>');
        myDoc.close();
        myBody = this.tfBody = myDoc.body;
        myBody.style.overflow = 'hidden';
        nDivObj = this.tfButtons = myDoc.createElement("DIV");
        nDivObj.style.position = 'absolute';
        nDivObj.style.top = (this.tfheight-16)+'px';
        nDivObj.style.left = '0px';
        nDivObj.style.width = '100%';
        nDivObj.style.display = 'block';
        nDivObj.style.textAlign = 'right';
        nDivObj.style.backgroundImage = 'url(./images/bg_scroll_pic_btn.png)';
        nDivObj.style.backgroundPosition = 'right';
        nDivObj.style.backgroundRepeat = 'no-repeat';
        this.tfobjs = new Array();
        for(tfi=0;tfi<this.num;tfi++){
            if(this.tfpics[tfi] != null){
                nObj = myDoc.createElement("IMG");
                nObj.src = this.tfpics[tfi];
                nObj.style.border = '0px';
                nObj.width = this.tfwidth;
                nObj.height = this.tfheight;
                if(this.tfurls != null
                	&& this.tfurls[tfi] != null){
	                nObjA = myDoc.createElement("A");
	                nObjA.href = this.tfurls[tfi];
	                nObjA.target = '_parent';
	                nObjA.appendChild(nObj);
	                myBody.appendChild(nObjA);
                }
                else myBody.appendChild(nObj);
                nSpanObj = this.tfobjs[tfi] = myDoc.createElement("SPAN");
                nSpanObj.style.fontSize = '12px';
                nSpanObj.style.fontFamily = 'Geneva, Arial, Helvetica, sans-serif';
                nSpanObj.style.backgroundColor = 'black';
                nSpanObj.style.color = 'white';
                nSpanObj.style.paddingLeft = '6px';
                nSpanObj.style.paddingRight = '6px';
                nSpanObj.style.borderRight = 'solid 1px white';
                nSpanObj.style.textAlign = 'center';
                nSpanObj.style.pointer = 'Arrow';
                nSpanObj.innerHTML = tfi+1;
                nSpanObj.ctrl = this;
                nSpanObj.self = nSpanObj;
                nSpanObj.pid = tfi;
                nSpanObj.onmouseover=function(){
                    this.ctrl.selChangeTo(this.pid);
                }
                nDivObj.appendChild(nSpanObj);
            }
        }
        nObjLast = myDoc.createElement("DIV");
        nObjLast.style.width = '100%';
        nObjLast.style.height = '100px';
        nObjLast.style.display = 'block';
        myBody.appendChild(nObjLast);
        myBody.appendChild(nDivObj);
        //
        this.selChangeTo(0);
    }
    this.selChangeTo=function(id){
        if(this.tfobjs[id] != null){
            obj = this.tfobjs[id];
            if(obj.ctrl.tfCurId != obj.pid){
                if(obj.ctrl.tfCurObj != null)
                    obj.ctrl.tfCurObj.style.backgroundColor = 'black';    
                obj.style.backgroundColor = 'red';
                obj.ctrl.tfCurObj = obj.self;
                obj.ctrl.tfCurId = obj.pid;
                obj.ctrl.scrollToPic(obj.pid);
            }
        }
    }
    this.countScroll=function(id, scrollSpeed){
        myBody = this.tfBody;
        curTop = this.tfCurTop = myBody.scrollTop;
        picTop = this.tfMaxTop = id*this.tfheight;
        picTop = (picTop > curTop) ? picTop -= this.tfheight : picTop += this.tfheight ;
        stepTop = this.tfStepTop = parseInt((picTop-curTop)/scrollSpeed);
        ///alert(this.tfCurTop+'!='+this.tfMaxTop+'||('+id+'+1)*'+this.tfheight+'-16');
        if(this.tfCurTop != this.tfMaxTop){
            this.tfCurTop = ((id+1)*this.tfheight-16);
            return true;
        }
        return false;
    }
    this.cycle=function(){
        this.tfInterval2 = setTimeout(this.tfex+".doCycle()", this.tfTimeoutSec);
    }
    this.doCycle=function(){
        if(isNaN(this.tfCurId))
            this.tfCurId = 0;
        curId = this.tfCurId;
        if(curId < this.num)
            curId++;
        if(curId == this.num)
            curId = 0;
        //alert(curId);
        this.selChangeTo(curId);
        //
        this.cycle();
    }
    this.showButtons=function(){
        this.tfButtons.style.top = this.tfCurTop+'px';
        this.tfButtons.style.display = '';
    }
    this.hideButtons=function(){
        clearTimeout(this.tfInterval2);
        this.tfButtons.style.display = 'none';
    }
    this.scrollToPic=function(id){
        if(id >= 0 && id < this.num && this.tfInterval == null){
            if(this.countScroll(id, this.tfStepSpeed)){
                ///alert(this.tfStepTop+'/'+this.tfStepSpeed+'|'+this.tfCurTop+'/'+this.tfMaxTop);
                this.hideButtons();
                this.tfInterval = setInterval(this.tfex+".doScrollToPic()", 10);
            }
        }
    }
    this.doScrollToPic=function(){
        if(this.tfStepTop != 0){
            if(this.tfStepTop > 0)
                this.tfStepTop--;
            else
                this.tfStepTop++;
            myBody = this.tfBody;
            if(this.tfStepTop > 0)
                myBody.scrollTop += this.tfStepSpeed;
            else
                myBody.scrollTop -= this.tfStepSpeed;
        }
        else{
            myBody = this.tfBody;
            willTop = this.tfMaxTop-myBody.scrollTop;
            willTop2 = willTop/6;
            if(willTop > 0){
                if(willTop < 15)
                    myBody.scrollTop = this.tfMaxTop;
                else
                    myBody.scrollTop += willTop2;
            }
            else{
                if(willTop > -15)
                    myBody.scrollTop = this.tfMaxTop;
                else
                    myBody.scrollTop += willTop2;
            }
            if(myBody.scrollTop == this.tfMaxTop){
                this.showButtons();
                clearInterval(this.tfInterval);
                this.init();
            }
        }
    }
    this.init();
}