<!--
// ¿øº» ¼Ò½º : steelheart
// »çÀÌÆ® : http://steelheart.pe.kr/
/*
 * var quick1 = new StaticMenu("quick1", document.all["Layer1"], document.all["ANIMATE"], 910, 281, null, null, 50, 10);
 * quick1.InitializeStaticMenu();
 * var [ÀÎ½ºÅÏ½º¸í] = new StaticMenu("[ÀÎ½ºÅÏ½º¸í]", [´ë»ó·¹ÀÌ¾î Object], [°íÁ¤À¯¹« checkbox Object], ... ÀÌÇÏ ÇÊ¿ä¿¡ µû¶ó);
 *
 *
 * InstanceName         : ¼±¾ðµÈ instanceÀÇ ÀÌ¸§ : timer ÁöÁ¤½Ã ´ë»ó object ¼±º°¿¡ »ç¿ë
 * STATICMENU           : º¸¿©Áö´Â Layer : ½ÇÁ¦ ÀÌ Layer¸¦ ÄÁÆ®·Ñ
 * ANIMATE              : ½ºÅ©·Ñ ÀÛµ¿ À¯¹«ÀÇ checkbox : ¹Ì»ç¿ë½Ã hidden À¸·Î ¸¸µé¾îÁ® ÀÖ¾î¾ß ÇÔ
 * stmnLEFT             : Layer ÀÇ left ½ÃÀÛÀ§Ä¡
 * stmnGAP1             : Layer ÀÇ top ½ÃÀÛÀ§Ä¡
 * stmnGAP2             : ½ºÅ©·Ñ µÇ¾î º¸¿©Áú ¶§ À¥ºê¶ó¿ìÀúÀÇ top°úÀÇ ¿©¹é : 0Àº top 0pxÀÇ À§Ä¡
 * stmnBASE             : Layer°¡ Ã³À½ º¸¿©Áö±â ½ÃÀÛÇÏ´Â top À§Ä¡
 * stmnActivateSpeed    : ½ºÅ©·Ñ Á÷ÈÄ Layer°¡ ¿¢¼Ç¿¡ µé¾î°¡´Â delay time
 * stmnScrollSpeed      : Layer°¡ ½ºÅ©·Ñ µÇ´Â ¼Óµµ
 *
 */

function StaticMenu(TimerName, STATICMENU, ANIMATE, stmnLEFT, stmnGAP1, stmnGAP2, stmnBASE, stmnActivateSpeed, stmnScrollSpeed){
    this.TimerName = TimerName;
    this.STATICMENU = STATICMENU;
    this.ANIMATE = ANIMATE;
    if(stmnLEFT == null) // ½ºÅ©·Ñ¸Þ´ºÀÇ ÁÂÃø À§Ä¡
        this.stmnLEFT = 10;
    else
        this.stmnLEFT = stmnLEFT;
    if(stmnGAP1 == null) // ÆäÀÌÁö Çì´õºÎºÐÀÇ ¿©¹é
        this.stmnGAP1 = 1000;
    else
        this.stmnGAP1 = stmnGAP1; // ÆäÀÌÁö Çì´õºÎºÐÀÇ ¿©¹é
    if(stmnGAP2 == null) // ½ºÅ©·Ñ½Ã ºê¶ó¿ìÀú »ó´Ü°ú ¾à°£ ¶ç¿ò. ÇÊ¿ä¾øÀ¸¸é 0À¸·Î ¼¼ÆÃ
        this.stmnGAP2 = 0;
    else
        this.stmnGAP2 = stmnGAP2;
    if(stmnBASE == null) // ½ºÅ©·Ñ¸Þ´º ÃÊ±â ½ÃÀÛÀ§Ä¡ (¾Æ¹«·¸°Ô³ª ÇØµµ »ó°üÀº ¾øÁö¸¸ stmnGAP1°ú ¾à°£ Â÷ÀÌ¸¦ ÁÖ´Â°Ô º¸±â ÁÁÀ½)
        this.stmnBASE = 10;
    else
        this.stmnBASE = stmnBASE;
    if(stmnActivateSpeed == null) // ¿òÁ÷ÀÓÀ» °¨ÁöÇÏ´Â ¼Óµµ (¼ýÀÚ°¡ Å¬¼ö·Ï ´Ê°Ô ¾Ë¾ÆÂ÷¸²)
        this.stmnActivateSpeed = 50; 
    else
        this.stmnActivateSpeed = stmnActivateSpeed;
    if(stmnScrollSpeed == null) // ½ºÅ©·ÑµÇ´Â ¼Óµµ (Å¬¼ö·Ï ´Ê°Ô ¿òÁ÷ÀÓ)
        this.stmnScrollSpeed = 10; 
    else
        this.stmnScrollSpeed = stmnScrollSpeed;
    this.stmnTimer = null;

    this.ToggleAnimate = function (){
        if(!this.ANIMATE.checked){
            this.RefreshStaticMenu();
            this.SaveCookie("ANIMATE", "true", 300);
        }else{
            clearTimeout(this.stmnTimer);
            this.STATICMENU.style.top = this.stmnGAP1;
            this.SaveCookie("ANIMATE", "false", 300);
        }
    }
    
    this.InitializeStaticMenu = function (){
        this.STATICMENU.style.left = this.stmnLEFT;
        if(this.ReadCookie("ANIMATE") == "false"){
            this.ANIMATE.checked = true;
            this.STATICMENU.style.top = document.body.scrollTop + this.stmnGAP1;
        }else{
            this.ANIMATE.checked = false;
            this.STATICMENU.style.top = document.body.scrollTop + this.stmnBASE;
            this.RefreshStaticMenu();
        }
    }
    this.RefreshStaticMenu = function (){
        var stmnStartPoint, stmnEndPoint, stmnRefreshTimer;

        stmnStartPoint = parseInt(this.STATICMENU.style.top, 10);
        stmnEndPoint = document.body.scrollTop + this.stmnGAP2;
        if(stmnEndPoint < this.stmnGAP1) stmnEndPoint = this.stmnGAP1;

        stmnRefreshTimer = this.stmnActivateSpeed;

        if( stmnStartPoint != stmnEndPoint ){
            stmnScrollAmount = Math.ceil( Math.abs( stmnEndPoint - stmnStartPoint ) / 15 );
            this.STATICMENU.style.top = parseInt(this.STATICMENU.style.top, 10) + ( ( stmnEndPoint < stmnStartPoint ) ? -stmnScrollAmount : stmnScrollAmount );
            stmnRefreshTimer = this.stmnScrollSpeed;
        }
        this.stmnTimer = setTimeout (this.TimerName+".RefreshStaticMenu();", stmnRefreshTimer);
    }
    this.ReadCookie = function (name){
        var label = name + "=", labelLen = label.length, cLen = document.cookie.length;
        for(i=0;i < cLen;i++){
            var j = i + labelLen;
            if(document.cookie.substring(i, j) == label){
                var cEnd = document.cookie.indexOf(";", j);
                if(cEnd == -1) cEnd = document.cookie.length;
                    return unescape(document.cookie.substring(j, cEnd));
            }
        }
        return "";
    }
    this.SaveCookie = function (name, value, expire){
        var eDate = new Date();
        eDate.setDate(eDate.getDate() + expire);
        document.cookie = name + "=" + value + "; expires=" +  eDate.toGMTString()+ "; path=/";
    }
}
//-->

