﻿    function Rolling(ObjName){
        this.ObjName = ObjName;
        
        this.SetRollingNumber = function(RollingNumber){
            this.RollingNumber = RollingNumber;
        }
        
        this.SetSetting = function(RollingHtml, OverHtml, DivName, DivWidth, DivHeight, RollingSpeed){
            this.RollingHtml = RollingHtml;
            this.OverHtml = OverHtml;
            this.DivName = DivName;
            this.DivWidth = DivWidth;
            this.DivHeight = DivHeight;
            this.RollingSpeed = RollingSpeed;
            
            this.SetRollingNumber(0);
        }
        
        this.GetSetting = function(){
            return{
                RollingHtml : this.RollingHtml,
                OverHtml : this.OverHtml,
                DivName : this.DivName,
                DivWidth : this.DivWidth,
                DivHeight : this.DivHeight,
                ObjName : this.ObjName,
                RollingSpeed : this.RollingSpeed,
                RollingNumber : this.RollingNumber,
                RollingHtmlLength : this.RollingHtml.length,
                IntervalId : this.IntervalId
            }
        }
        
        this.DivDisplayState = function(DivName){
            return $get(DivName).style.display;
        }
        
        this.BaseDivDrow = function(){
            var SettingValue = this.GetSetting();
            
            document.writeln("<div style=\"position:absolute;\">");
            document.writeln("<div id=\"" + SettingValue.DivName + "\" style=\"width:" + SettingValue.DivWidth + "px;height:" + SettingValue.DivHeight + "px;top:-10;position:relative;z-index:200;\" onmouseover=\"" + SettingValue.ObjName + ".RollingStop();" + SettingValue.ObjName + ".OverDivOpen();\" onmouseout=\"" + SettingValue.ObjName + ".RollingStart();\"></div>");
            document.writeln("<div id=\"Over" + SettingValue.DivName + "\" style=\"display:none;width:" + SettingValue.DivWidth + "px;position:relative;left:0;top:-30;z-index:200;\" onmouseover=\"" + SettingValue.ObjName + ".RollingStop();" + SettingValue.ObjName + ".OverDivOpen();\" onmouseout=\"" + SettingValue.ObjName + ".RollingStart();" + SettingValue.ObjName + ".OverDivClose();\"></div>");
            document.writeln("</div>");
        }
        
        this.HtmlDrow = function(){
            var SettingValue = this.GetSetting();
            
            if(SettingValue.RollingNumber == SettingValue.RollingHtmlLength){
                SettingValue.RollingNumber = 0;
                this.SetRollingNumber(0);
            }
                
            $get(SettingValue.DivName).innerHTML = SettingValue.RollingHtml[SettingValue.RollingNumber];
            this.SetRollingNumber(SettingValue.RollingNumber + 1);
        }
        
        this.RollingStart = function(){
            var SettingValue = this.GetSetting();
            
            this.IntervalId = setInterval(SettingValue.ObjName + ".HtmlDrow()", SettingValue.RollingSpeed);
        }
        
        this.RollingStop = function(){
            var SettingValue = this.GetSetting();
            
            clearInterval(SettingValue.IntervalId);
        }
        
        this.OverHtmlDrow = function(){
            var SettingValue = this.GetSetting();
            
            $get("Over" + SettingValue.DivName).innerHTML = SettingValue.OverHtml;
        }
        
        this.OverDivOpen = function(){
            var SettingValue = this.GetSetting();
            var DivName = "Over" + SettingValue.DivName;
            
            $get(DivName).style.display = "block";
            
        }
        
        this.OverDivClose = function(){
            var SettingValue = this.GetSetting();
            var DivName = "Over" + SettingValue.DivName;
            
            $get(DivName).style.display = "none";
            
        }
        
        this.Init = function(RollingHtml, OverHtml, DivName, DivWidth, DivHeight, RollingSpeed){
            this.RollingHtml = "";
            this.OverHtml = "";
            this.DivName = "";
            this.DivWidth = 0;
            this.DivHeight = 0;
            this.RollingSpeed = 0;
            
            this.SetSetting(RollingHtml, OverHtml, DivName, DivWidth, DivHeight, RollingSpeed);
            this.BaseDivDrow();
            this.OverHtmlDrow();
            
            var SettingValue = this.GetSetting();
            
            this.HtmlDrow()
            this.SetRollingNumber(SettingValue.RollingNumber + 1);
            this.RollingStart();
        }
    }


/*
<script type="text/javascript" src="/BasicJs/MicrosoftAjax.js"></script>
<script type="text/javascript" src="/BasicJs/Rolling.js"></script>
<script type="text/javascript">
    Rolling1 = new Rolling("Rolling1"); //롤링 객채 생성 (넘기는 파라미터 값으로 Div 생성)

    RollingHtml = Array(); //롤링할 HTML

    RollingHtml[0] = "<table width='100%' height='80'><tr>${ImageInfo}</tr></table>";
    RollingHtml[1] = "<table width='100%' height='80'><tr>${ImageInfo}</tr></table>";
    RollingHtml[2] = "<table width='100%' height='80'><tr>${ImageInfo}</tr></table>";
    RollingHtml[3] = "<table width='100%' height='80'><tr>${ImageInfo}</tr></table>";

    Rolling1.Init(RollingHtml, "", "Rolling1Div", 265, 75, 2000); //롤링할 HTML, 마우스 오버시 표시될 Div용 HTML, 가로 크기, 세로 크기, 속도
</script>
*/
