﻿/*이미지 변경*/

var HotelImgObj = new Array();
var GolfImgObj = new Array();
var TourImgObj = new Array();
var OptionImgObj = new Array();

function ImgTransfer(ObjName,ObjArr,ObjNameArr,ObjPathArr,ImgDivCt,ImgReplaceArr)
{
    //이미지 리스트 아이디명
    this.name = ObjName;    
    //이미지 리스트 개수
    this.ImgDivCt = ImgDivCt;
    //첫번째 이미지 아이디명
    this.FirstImgObj = null;
    if (document.getElementById(this.name +"First") != null) this.FirstImgObj = document.getElementById(this.name +"First");
    this.FirstImgTitleObj = null;
    if (document.getElementById(this.name +"FirstTitle") != null) this.FirstImgTitleObj = document.getElementById(this.name +"FirstTitle");
    
    //이미지경로 리스트 배열
    this.ImgArr = ObjArr;
    //이미지이름 리스트 배열
    this.ImgNameArr = ObjNameArr;
    //이미지 링크경로 리스트 배열
    this.ImgPathArr = ObjPathArr;

    this.ImgReplaceArr = ImgReplaceArr; 
    
    this.ImgShowCt = -1;
    this.FirstImgShowCt = -1;
    
    this.AlertMsg = false;
    
    /*이미지 리스트 이동*/
    this.Move = function(Diff){
                    if (this.ImgDivCt > this.ImgArr.length) 
                    {
                        try{if (this.AlertMsg) MoaAlertPop("더 이상 사진정보가 없습니다.");}
                        catch(e){}
                        return;
                    }
                    var TempImgName="";
                    for(var ImgCt=1; ImgCt <= this.ImgDivCt; ImgCt++)
                    {
                        this.ImgShowCt += Diff;
                        if(this.ImgArr.length < this.ImgShowCt + 1 ) this.ImgShowCt = 0;
                        if(this.ImgShowCt < 0) this.ImgShowCt = this.ImgArr.length-1;
                        
                        if (document.getElementById(this.name + ImgCt) != null) 
                        {
                            document.getElementById(this.name + ImgCt).setAttribute("src",this.ImgArr[this.ImgShowCt]);
                            TempImgName = "　";
                            if (this.ImgNameArr != null && this.ImgShowCt < this.ImgNameArr.length && this.ImgNameArr[this.ImgShowCt] != "") TempImgName = this.ImgNameArr[this.ImgShowCt];
                            document.getElementById(this.name + ImgCt).setAttribute("alt",TempImgName);
                            
                            if (this.ImgPathArr != null) document.getElementById(this.name + ImgCt).setAttribute("title",this.ImgPathArr[this.ImgShowCt]);
                        }
                        if (document.getElementById(this.name +"Selected"+ ImgCt) != null) document.getElementById(this.name +"Selected"+ ImgCt).className = "";
                    }//end for
                }//end method
    /*이미지 리스트 이동*/
    this.FirstMove = function(Diff){
                        this.FirstImgShowCt += Diff;
                        if(this.ImgArr.length <= this.FirstImgShowCt + 1 ) this.FirstImgShowCt = 0;
                        if(this.FirstImgShowCt < 0) this.FirstImgShowCt = this.ImgArr.length-1;
                        
                        var SelectedImg = this.ImgArr[this.FirstImgShowCt];
                        if (this.ImgReplaceArr.length > 1) SelectedImg = SelectedImg.replace(this.ImgReplaceArr[0],this.ImgReplaceArr[1]); 
                            
                        if (this.FirstImgObj != null) this.FirstImgObj.setAttribute("src",SelectedImg);
                        if (this.FirstImgTitleObj != null && this.ImgNameArr != null)   //이미지 타이틀
                        {
                            if (this.FirstImgShowCt < this.ImgNameArr.length && this.ImgNameArr[this.FirstImgShowCt] != "")
                            {
                                if (this.ImgPathArr != null)
                                    this.FirstImgTitleObj.innerHTML = "<a href=\"" +this.ImgPathArr[this.FirstImgShowCt]+ "\" target='_blank'>" + this.ImgNameArr[this.FirstImgShowCt] + "</a>";
                                else
                                    this.FirstImgTitleObj.innerHTML = this.ImgNameArr[this.FirstImgShowCt];
                            }
                            else
                                this.FirstImgTitleObj.innerHTML = "　";
                        }
                }//end method
                            
    /*선택박스*/
    this.Select = function(Idx){
                    //.select만  했을때 FirstImgObj값을 설정해주기위해 다시 값셋팅
                    this.FirstImgObj = document.getElementById(this.name +"First");
                    this.FirstImgTitleObj = document.getElementById(this.name +"FirstTitle");
                    var SelectedImg="";
                    for(var ImgCt=1; ImgCt <= this.ImgDivCt; ImgCt++)
                    {
                        var ImgObj = document.getElementById(this.name +"Selected");
                        if (document.getElementById(this.name +"Selected") != null)
                        {
                            if (Idx == ImgCt)
                            {
                                if (ImgObj.childNodes[Idx-1].childNodes[0].nodeName == "DIV")
                                {
                                    ImgObj.childNodes[Idx-1].childNodes[0].className = "pos_a forpng SmallImgSelectedBox";
                                }
                                else
                                {
                                    with(ImgObj.childNodes[Idx-1].insertBefore(document.createElement("div"),ImgObj.childNodes[Idx-1].childNodes[0]))
                                    {
                                        className = "pos_a forpng SmallImgSelectedBox";
                                    }                               
                                }
                            }
                            else if (ImgObj.childNodes[ImgCt-1].childNodes[0].nodeName == "DIV")
                            {
                                ImgObj.childNodes[ImgCt-1].removeChild(ImgObj.childNodes[ImgCt-1].childNodes[0]);
                            }
                        }
                        else if (document.getElementById(this.name +"Selected"+ ImgCt) != null)
                        {
                            if (Idx == ImgCt)
                                document.getElementById(this.name +"Selected"+ ImgCt).className = "SmallImgSelectedBox";
                            else
                                document.getElementById(this.name +"Selected"+ ImgCt).className = "";
                        }//end if
                        
                        if (Idx == ImgCt && this.FirstImgObj != null) 
                        {
                            if (document.getElementById(this.name + ImgCt).getAttribute("alt") == "None")
                            {                                
                                alert("등록된 사진이 없습니다.");
                                return;
                            }
                            
                            SelectedImg = document.getElementById(this.name + ImgCt).getAttribute("src");
                            if (this.ImgReplaceArr.length > 1) SelectedImg = SelectedImg.replace(this.ImgReplaceArr[0],this.ImgReplaceArr[1]); 
                            
                            this.FirstImgObj.setAttribute("src",SelectedImg);
                            this.FirstImgObj.setAttribute("alt",document.getElementById(this.name + ImgCt).getAttribute("alt"));
                            if (this.FirstImgTitleObj != null)   //이미지 타이틀
                            {
                                if (document.getElementById(this.name + ImgCt).getAttribute("title") != "")
                                    this.FirstImgTitleObj.innerHTML = "<a href=\"" +document.getElementById(this.name + ImgCt).getAttribute("title")+ "\" target='_blank'>" + document.getElementById(this.name + ImgCt).getAttribute("alt") + "</a>";
                                else
                                    this.FirstImgTitleObj.innerHTML = document.getElementById(this.name + ImgCt).getAttribute("alt");
                             }   
                            SelectedImg = "";
                        }
                    }//end for
                }//end method
                            
    this.Move(1);                       
    this.Select(1); 
    this.AlertMsg = true;                      
}//end method


function ImgTransfer_TA(ObjName,ObjArray,ImgDivCt,ImgReplaceArr)
{
    var ObjArr = new Array();
    var ObjNameArr = new Array();
    var ObjPathArr = null;
    //이미지 리스트 아이디명
    this.name = ObjName;    
    //이미지 리스트 개수
    this.ImgDivCt = ImgDivCt;
    //첫번째 이미지 아이디명
    this.FirstImgObj = null;
    
    if (document.getElementById(this.name +"First") != null) this.FirstImgObj = document.getElementById(this.name +"First");
    this.FirstImgTitleObj = null;
    if (document.getElementById(this.name +"FirstTitle") != null) this.FirstImgTitleObj = document.getElementById(this.name +"FirstTitle");
    
    for(i = 0; i < ObjArray.length; i++)
    {
        ObjArr[i] = ObjArray[i].url.toString();
        ObjNameArr[i] = ObjArray[i].alt.toString();
    }
    
    //이미지경로 리스트 배열
    this.ImgArr = ObjArr;
    //이미지이름 리스트 배열
    this.ImgNameArr = ObjNameArr;
    //이미지 링크경로 리스트 배열
    this.ImgPathArr = ObjPathArr;
    
    this.ImgReplaceArr = ImgReplaceArr; 
    
    this.ImgShowCt = -1;
    this.FirstImgShowCt = -1;
    
    this.AlertMsg = false;
    
    /*이미지 리스트 이동*/
    this.Move = function(Diff){
                    if (this.ImgDivCt > this.ImgArr.length) 
                    {
                        try{if (this.AlertMsg) MoaAlertPop("더 이상 사진정보가 없습니다.");}
                        catch(e){}
                        return;
                    }
                    var TempImgName="";
                    for(var ImgCt=1; ImgCt <= this.ImgDivCt; ImgCt++)
                    {
                        this.ImgShowCt += Diff;
                        if(this.ImgArr.length < this.ImgShowCt + 1 ) this.ImgShowCt = 0;
                        if(this.ImgShowCt < 0) this.ImgShowCt = this.ImgArr.length-1;
                        
                        if (document.getElementById(this.name + ImgCt) != null) 
                        {
                            document.getElementById(this.name + ImgCt).setAttribute("src",this.ImgArr[this.ImgShowCt]);
                            TempImgName = "　";
                            if (this.ImgNameArr != null && this.ImgShowCt < this.ImgNameArr.length && this.ImgNameArr[this.ImgShowCt] != "") TempImgName = this.ImgNameArr[this.ImgShowCt];
                            document.getElementById(this.name + ImgCt).setAttribute("alt",TempImgName);
                            
                            if (this.ImgPathArr != null) document.getElementById(this.name + ImgCt).setAttribute("title",this.ImgPathArr[this.ImgShowCt]);
                        }
                        if (document.getElementById(this.name +"Selected"+ ImgCt) != null) document.getElementById(this.name +"Selected"+ ImgCt).className = "";
                    }//end for
                }//end method
    /*이미지 리스트 이동*/
    this.FirstMove = function(Diff){
                        this.FirstImgShowCt += Diff;
                        if(this.ImgArr.length <= this.FirstImgShowCt + 1 ) this.FirstImgShowCt = 0;
                        if(this.FirstImgShowCt < 0) this.FirstImgShowCt = this.ImgArr.length-1;
                        
                        var SelectedImg = this.ImgArr[this.FirstImgShowCt];
                        if (this.ImgReplaceArr.length > 1) SelectedImg = SelectedImg.replace(this.ImgReplaceArr[0],this.ImgReplaceArr[1]); 
                            
                        if (this.FirstImgObj != null) this.FirstImgObj.setAttribute("src",SelectedImg);
                        if (this.FirstImgTitleObj != null && this.ImgNameArr != null)   //이미지 타이틀
                        {
                            if (this.FirstImgShowCt < this.ImgNameArr.length && this.ImgNameArr[this.FirstImgShowCt] != "")
                            {
                                if (this.ImgPathArr != null)
                                    this.FirstImgTitleObj.innerHTML = "<a href=\"" +this.ImgPathArr[this.FirstImgShowCt]+ "\" target='_blank'>" + this.ImgNameArr[this.FirstImgShowCt] + "</a>";
                                else
                                    this.FirstImgTitleObj.innerHTML = this.ImgNameArr[this.FirstImgShowCt];
                            }
                            else
                                this.FirstImgTitleObj.innerHTML = "　";
                        }
                }//end method
                            
    /*선택박스*/
    this.Select = function(Idx){
                    var SelectedImg="";
                    for(var ImgCt=1; ImgCt <= this.ImgDivCt; ImgCt++)
                    {
                        var ImgObj = document.getElementById(this.name +"Selected");
                        if (document.getElementById(this.name +"Selected") != null)
                        {
                            if (Idx == ImgCt)
                            {
                                if (ImgObj.childNodes[Idx-1].childNodes[0].nodeName == "DIV")
                                {
                                    ImgObj.childNodes[Idx-1].childNodes[0].className = "pos_a forpng SmallImgSelectedBox";
                                }
                                else
                                {
                                    with(ImgObj.childNodes[Idx-1].insertBefore(document.createElement("div"),ImgObj.childNodes[Idx-1].childNodes[0]))
                                    {
                                        className = "pos_a forpng SmallImgSelectedBox";
                                    }                               
                                }
                            }
                            else if (ImgObj.childNodes[ImgCt-1].childNodes[0].nodeName == "DIV")
                            {
                                ImgObj.childNodes[ImgCt-1].removeChild(ImgObj.childNodes[ImgCt-1].childNodes[0]);
                            }
                        }
                        else if (document.getElementById(this.name +"Selected"+ ImgCt) != null)
                        {
                            if (Idx == ImgCt)
                                document.getElementById(this.name +"Selected"+ ImgCt).className = "SmallImgSelectedBox";
                            else
                                document.getElementById(this.name +"Selected"+ ImgCt).className = "";
                        }//end if
                        
                        if (Idx == ImgCt && this.FirstImgObj != null) 
                        {
                            if (document.getElementById(this.name + ImgCt).getAttribute("alt") == "None")
                            {                                
                                alert("등록된 사진이 없습니다.");
                                return;
                            }
                            SelectedImg = document.getElementById(this.name + ImgCt).getAttribute("src");
                            if (this.ImgReplaceArr.length > 1) SelectedImg = SelectedImg.replace(this.ImgReplaceArr[0],this.ImgReplaceArr[1]); 
                            
                            this.FirstImgObj.setAttribute("src",SelectedImg);
                            this.FirstImgObj.setAttribute("alt",document.getElementById(this.name + ImgCt).getAttribute("alt"));
                            if (this.FirstImgTitleObj != null)   //이미지 타이틀
                            {
                                if (document.getElementById(this.name + ImgCt).getAttribute("title") != "")
                                    this.FirstImgTitleObj.innerHTML = "<a href=\"" +document.getElementById(this.name + ImgCt).getAttribute("title")+ "\" target='_blank'>" + document.getElementById(this.name + ImgCt).getAttribute("alt") + "</a>";
                                else
                                    this.FirstImgTitleObj.innerHTML = document.getElementById(this.name + ImgCt).getAttribute("alt");
                             }   
                            SelectedImg = "";
                        }
                    }//end for
                }//end method
                            
    this.Move(1);                       
    this.Select(1); 
    this.AlertMsg = true;                      
}//end method



