﻿var _transitions = new Array();
_transitions[0] = "progid:DXImageTransform.Microsoft.Fade(duration=1)";
_transitions[1] = "progid:DXImageTransform.Microsoft.GradientWipe(duration=1)";
_transitions[2] = "progid:DXImageTransform.Microsoft.Pixelate(maxSquare=10,duration=1)";
_transitions[3] = "special case";


//이벤트리스트 xml객체모션시작노드명((Root부터 시작)), 이미지노드명,버튼이미지노드명,이미지폭, 이미지높이, 버튼 이미지폭, 버튼 이미지높이, 모션타입지정여부, 호출빈도, (윤선영 추가) 타이틀객체명, (윤선영 추가) 타이틀노드명
function BtnSlide_init(XMLObj, SlideObjName, BtnObj, BtnChildYN, BtnCurrentclassName, NodeName, ImgNodeName, PathNodeName, ImgWidth, ImgHeight, BtnImgWidth, BtnImgHeight, current_transition, Interval, TitleObjName, TitleNodeName)
{
    this.SlideObj = document.getElementById(SlideObjName);
    if(XMLObj == null || this.SlideObj == null) return;
    this.MotionXmlNode = Get_selectNodes(XMLObj, NodeName);
    if (this.MotionXmlNode == null) return;
    
    this.BtnObj = BtnObj;
    
    this.BtnChildYN = BtnChildYN;
    this.BtnCurrentclassName = BtnCurrentclassName;
     
    this.curImg = 0;
    this.ImgWidth = ImgWidth;
    this.ImgHeight = ImgHeight;
    this.BtnImgWidth = BtnImgWidth;
    this.BtnImgHeight = BtnImgHeight;
    this.current_transition = current_transition;   //모션 형태값 지정여부
    
    /*이미지, 경로, 버튼이미지의 노드 위치 찾기*/
    this.ImgNodeNum = -1;
    this.PathNodeNum = -1;
    this.TitleNodeNum = -1;
    for(var Ct=0; Ct < this.MotionXmlNode[0].childNodes.length; Ct++)
    {       
        if (this.ImgNodeNum < 0 && this.MotionXmlNode[0].childNodes[Ct].nodeName == ImgNodeName) 
            this.ImgNodeNum = Ct;
                    
        if (this.PathNodeNum < 0 && this.MotionXmlNode[0].childNodes[Ct].nodeName == PathNodeName) 
            this.PathNodeNum = Ct;   
            
        // 2010.08.03 윤선영 추가
        if (this.TitleNodeNum < 0 && this.MotionXmlNode[0].childNodes[Ct].nodeName == TitleNodeName) 
            this.TitleNodeNum = Ct;
    }//end for
        
    //이미지 미리 불러오기
    this.MotionPreloadRange = function() 
    {
        var arrPreload = new Array();
        for (var Ct=0; Ct < this.MotionXmlNode.length; Ct++) {
            arrPreload[Ct] = new Image();
            arrPreload[Ct].src = Get_NodeValue(this.MotionXmlNode[Ct].childNodes[this.ImgNodeNum]);
        }//end for
    }//end method
    
    //강제 변경
    this.Change = function(CurImg,Obj){
        
        this.Motion_stop();
        if (this.BtnChildYN)    //버튼의 객체에 하위객체가 존재하는 경우
	        this.BtnObj[this.curImg].childNodes[0].className = "";
	    else
	        this.BtnObj[this.curImg].className = "";
	        
        this.curImg = CurImg-1;
        this.changeSlide();
        this.Motion_play(Obj);
        
    }//end method
    
    this.changeSlide = function()
    {	
	    var do_transition;
	    if (this.current_transition == (_transitions.length-1))
		    do_transition = Math.floor(Math.random() * (_transitions.length-1));
	    else 
		    do_transition = this.current_transition;
        
	    if (this.MotionXmlNode.length != 0) 
	    {	    
            if (++this.curImg >= this.MotionXmlNode.length) this.curImg = 0;
            var _Target = Get_AttributeNode(this.MotionXmlNode[this.curImg].childNodes[this.PathNodeNum],"target");                
            if (_Target != "") _Target = " target='" + _Target + "'";                
            var _Path = Get_AttributeNode(this.MotionXmlNode[this.curImg],"idx");
            if (_Path != "") _Path = "&eidx=" + _Path;
            _Path = Get_NodeValue(this.MotionXmlNode[this.curImg].childNodes[this.PathNodeNum]) + _Path;
            var slideImage = "<a href=\""+ _Path +"\" "+_Target+"><img src=\"" + Get_NodeValue(this.MotionXmlNode[this.curImg].childNodes[this.ImgNodeNum]) + "\" onerror=\"setNoImg(this,'"+this.ImgWidth+"x"+this.ImgHeight+"');\" /><\/a>";
            	        
	        try{
                this.SlideObj.style.filter = _transitions[do_transition];
                this.SlideObj.filters[0].Apply();		
                //var _Target = Get_AttributeNode(this.MotionXmlNode[this.curImg].childNodes[this.PathNodeNum],"target"); // 2011.07.19 윤선영 타켓부분 위로 올림
                //if (_Target != "") _Target = " target='" + _Target + "'";                
	            this.SlideObj.innerHTML = slideImage;		    
	            this.SlideObj.filters[0].Play();	
	        }catch(e) {
	            this.SlideObj.innerHTML = slideImage;	            
	        }
	        
	        var PreCurImg = this.curImg - 1;
	        if (PreCurImg < 0) PreCurImg = this.MotionXmlNode.length -1;
	        if (this.BtnChildYN)    //버튼의 객체에 하위객체가 존재하는 경우
	        {
	            this.BtnObj[PreCurImg].childNodes[0].className = "";
	            this.BtnObj[this.curImg].childNodes[0].className = this.BtnCurrentclassName;
	        }
	        else
	        {
	            this.BtnObj[PreCurImg].className = "";
	            this.BtnObj[this.curImg].className = this.BtnCurrentclassName;
	        }
	        
	        // 2010.08.03 윤선영 추가
	        try{
	            this.TitleObj = document.getElementById(TitleObjName);
	            if (this.TitleObj != null) 
	                this.TitleObj.innerText = Get_NodeValue(this.MotionXmlNode[this.curImg].childNodes[this.TitleNodeNum]);
	        }catch(e) {
	            this.TitleObj.innerText = "";	            
	        }
	                
	    }//end if
    }//end method

    this.MotionTimerId = -1;
    this.interval = Interval;
    this.Motion_play = function(Obj)
    {
        if (this.MotionTimerId == -1) 
		    this.MotionTimerId = window.setInterval(function(){Obj.changeSlide();}, this.interval);
    }//end method
    
    this.Motion_stop = function()
    {
        window.clearInterval(this.MotionTimerId);
        this.MotionTimerId = -1;
    }//end method

    
}//end method
