﻿//----------------------------------------------
// Create 2008-06-23 Menos
//----------------------------------------------
/*
    Area(영역) : 없어도 된다. 영역별 마우스 체크시에 넣으려고 했으나 각각의 텝 메뉴 이벤트 발생으로 인해 불필요해졌음.
    imageId (텝이미지 아이디)
    menuImg(탭이미지) : array()
    menuForm(탭메뉴형식)  : IMG, HTML, BGIMG
    menuDiv(메뉴 변경DIV) : array()
    list(리스트) : array()
    direction : 방향 ( 0 변화없음, 1 오른쪽진행 )
    timegap : 탭 이동시간 간격
*/
var Tab2 = function(area, ImgName, menuImg, menuForm, menuDiv, list, direction, timegap) {
    this.area = document.getElementById(area);
    this.ImgName = ImgName;
    this.menuImg = menuImg;
    this.menuForm = menuForm;
    this.menuDiv = menuDiv;
    this.list = list;
    this.direction = direction;
    this.timegap = timegap  ;
    
    this.menuImgCnt = menuImg.length;
    this.startIdx = 0;
    
    if(list.length > 0) {
        this.endIdx = list.length-1;
    }
    this.setTimeOut = null;
}

Tab2.prototype = {
    Init : function() {
        var This = this;
        //this.area.onmouseover = function() { window.clearTimeout(This.setTimeOut);  }
        //this.area.onmouseout = function() { this.setTimeOut = window.setTimeout(function () { This.Run(); }, This.timegap); }
    },    
    Run : function() {
        var This = this;
        
        if (this.direction == 1) { This.MoveLeft(); }
    },
    MoveLeft : function() {
        var This = this;
        window.clearTimeout(this.setTimeOut);
        
        var objIdx = parseInt(this.startIdx);
        var changeIdx = objIdx-1
        
        if(changeIdx < 0) 
            changeIdx = this.endIdx;            
        
        if(this.list != undefined) {
            if(this.list.length > 1) {
                for(var i=0; i<this.list.length; i++)
                    document.getElementById(this.list[i]).style.display = "none";
                document.getElementById(this.list[this.startIdx]).style.display = ""; 
            }
        }
        
        if(this.menuDiv != undefined) {
            if(this.menuDiv.length > 1) {
                for(i=0; i<this.menuDiv.length; i++)
                    document.getElementById(this.menuDiv[i]).style.display = "none";
                document.getElementById(this.menuDiv[this.startIdx]).style.display = "";
            }
        }
        
        if(this.ImgName != "") {
            if(document.getElementById(this.ImgName) != null) {
                if(this.menuImg != undefined || this.menuImg != "") {
                    if(this.menuForm == "IMG")
                        document.getElementById(this.ImgName).src = this.menuImg[this.startIdx];
                    else if(this.menuForm == "BGIMG")
                        document.getElementById(this.ImgName).style.backgroundImage = "url('"+this.menuImg[this.startIdx]+"')";
                }
            }
        }
        
        if(this.startIdx < this.endIdx)
            this.startIdx++;
        else
            this.startIdx = 0;
            
        this.setTimeOut = window.setTimeout(function () { This.Run(); }, This.timegap);
    },
    AreaOn: function(num) { 
        var This = this;
        var minNum = 0;
        var maxNum = 0;
        
        window.clearTimeout(This.setTimeOut);        
        
        maxNum = num+1;
        minNum = num-1;
        if(minNum < 0 )
            minNum = this.endIdx;
        if(maxNum > this.endIdx)
            maxNum = 0;
        
        if(this.list != undefined) {
            if(this.list.length > 0) {
                for(var i=0; i<this.list.length; i++)
                    document.getElementById(this.list[i]).style.display = "none";
                document.getElementById(this.list[num]).style.display = ""; 
            }
        }
        
        if(this.menuDiv != undefined) {
            if(this.menuDiv.length > 0) {
                for(i=0; i<this.menuDiv.length; i++)
                    document.getElementById(this.menuDiv[i]).style.display = "none";
                document.getElementById(this.menuDiv[num]).style.display = "";
            }
        }
        
        if(this.menuImg != undefined) {
            if(this.menuForm == "IMG")
                document.getElementById(this.ImgName).src = this.menuImg[num];
            else if(this.menuForm == "BGIMG")
                document.getElementById(this.ImgName).style.backgroundImage = "url('"+this.menuImg[num]+"')";
        }

        this.startIdx = num;
            
    }, 
    AreaOut: function() {
        var This = this;
        this.setTimeOut = window.setTimeout(function () { This.Run(); }, This.timegap);
    }
}