﻿// JScript 檔

Type.registerNamespace("NewsAjax");
NewsAjax.Direction = function(){};
NewsAjax.Direction.prototype = {
        Left:0,
        Right:1,
        Up:2,
        Down:3
    } 
NewsAjax.Direction.registerEnum("NewsAjax.Direction");
NewsAjax.Marqee = function(element) {
    NewsAjax.Marqee.initializeBase(this, [element]);    
    this.EnumDirection  = NewsAjax.Direction.Left;
    this.Speed = 30;
    this.TimeId = null;
}

NewsAjax.Marqee.prototype = {
    initialize: function() {
        NewsAjax.Marqee.callBaseMethod(this, 'initialize');        
        this.get_element().innerHTML += this.get_element().innerHTML;
        this.get_element().style.overflow = "hidden";
        if(this.EnumDirection==NewsAjax.Direction.Left||this.EnumDirection==NewsAjax.Direction.Right)
        {
            this.get_element().style.whiteSpace="nowrap";            
        }
        this._onMouseOverHandler = Function.createDelegate(this,this._onMouseOver);
        this._onMouseOutHandler = Function.createDelegate(this,this._onMouseOut);
        this._onMarqeeHandler = Function.createDelegate(this,this._onMarqee);
        $addHandler(this.get_element(), "mouseover",this._onMouseOverHandler);
        $addHandler(this.get_element(), "mouseout",this._onMouseOutHandler);
        this.TimeId = setInterval(this._onMarqeeHandler,this.Speed);
        // Add custom initialization here
    },_onMarqee:function(){
        switch(this.EnumDirection)
        {
            case NewsAjax.Direction.Right:
                if(this.get_element().scrollLeft<=0){                     
                    this.get_element().scrollLeft = this.get_element().scrollWidth/2;                    
                }else{
                    this.get_element().scrollLeft --;
                }
            break;
            case NewsAjax.Direction.Up:
                if(this.get_element().scrollTop>=(this.get_element().scrollHeight) /2){            
                    this.get_element().scrollTop = 0;
                }else{
                    this.get_element().scrollTop ++;
                }
            break;
            case NewsAjax.Direction.Down:
                if(this.get_element().scrollTop<=0){                               
                    this.get_element().scrollTop = (this.get_element().scrollHeight) /2;
                }else{
                    this.get_element().scrollTop --;
                }
            break;
            default:
                if(this.get_element().scrollLeft>=this.get_element().scrollWidth/2){            
                    this.get_element().scrollLeft = 0;
                }else{
                    this.get_element().scrollLeft ++;
                }
            break;
            
        }
        
    },_onMouseOver:function(){
        clearInterval(this.TimeId);        
    },_onMouseOut:function(){
        this.TimeId = setInterval(this._onMarqeeHandler,this.Speed);
    },
    dispose: function() {        
        //Add custom dispose actions here
        NewsAjax.Marqee.callBaseMethod(this, 'dispose');
    }
}
NewsAjax.Marqee.registerClass('NewsAjax.Marqee', Sys.UI.Behavior);

if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
