﻿var togetherMaxRows = 6;    // 총 리스트 갯수
var togetherShowRows = 4;   // 보여줄 수 있는 갯수


function MainContentsChange() { }

MainContentsChange.getChangeImageTab = function(_imageTab, _imageValue) {
    document.getElementById(_imageTab).src = _imageValue;
}

MainContentsChange.getChangeLink = function(_id, _link) {
    document.getElementById(_id).href = _link;
}

MainContentsChange.getChangeClassName = function(_id, _className) {
    document.getElementById(_id).className = _className;
}

MainContentsChange.getDisplayHidden = function(_id) {
    document.getElementById(_id).style.display = "none";
}

MainContentsChange.getDisplayShow = function(_id) {
    document.getElementById(_id).style.display = "";
}

MainContentsChange.getHtmlDisplay = function(_id, _html) {
    document.getElementById(_id).innerHTML = _html;
}

MainContentsChange.getElementInput = function(_id, _value) {
    document.getElementById(_id).value = _value;
}

MainContentsChange.getElementImageOnOff = function(_id, _selectNumber, _prevValue, _nextVale) {
    document.getElementById(_id + parseInt(_selectNumber)).src = document.getElementById(_id + parseInt(_selectNumber)).src.replace(_prevValue, _nextVale);
}

MainContentsChange.getImageTabLoop = function(_imageTab, _selectNumber, _maxNumber, _imageSrc) {
    for (var iLoopCnt = 0; iLoopCnt < parseInt(_maxNumber); iLoopCnt++) {
        if (iLoopCnt == parseInt(_selectNumber)) {
            MainContentsChange.getChangeImageTab(_imageTab + '' + parseInt(iLoopCnt + 1), _imageSrc + '' + parseInt(iLoopCnt + 1) + "_on.gif");
        } else {
            MainContentsChange.getChangeImageTab(_imageTab + '' + parseInt(iLoopCnt + 1), _imageSrc + '' + parseInt(iLoopCnt + 1) + "_off.gif");
        }
    }
}

MainContentsChange.getClassTabLoop = function(_className, _selectNumber, _maxNumber, _beforeClass, _afterClass) {
    for (var iLoopCnt = 0; iLoopCnt < parseInt(_maxNumber); iLoopCnt++) {
        if (iLoopCnt == parseInt(_selectNumber)) {
            MainContentsChange.getChangeClassName(_className + '' + iLoopCnt, _afterClass);
            MainContentsChange.getElementInput('currentrow', _selectNumber);
        } else {
            MainContentsChange.getChangeClassName(_className + '' + iLoopCnt, _beforeClass);
        }
    }
}

MainContentsChange.getImageOnOffLoop = function(_id, _selectNumber, _maxNumber, _beforeImage, _afterImage) {
    for (var iLoopCnt = 0; iLoopCnt < parseInt(_maxNumber); iLoopCnt++) {
        if (iLoopCnt == parseInt(_selectNumber)) {
            MainContentsChange.getElementImageOnOff(_id, _selectNumber, _beforeImage, _afterImage);
        } else {
            MainContentsChange.getElementImageOnOff(_id, iLoopCnt, _afterImage, _beforeImage);
        }
    }
}

MainContentsChange.getMovePlayer = function(_id, _value) {
    var _movePlayer = ""
    _movePlayer += "<object style=\"height: 422px; width: 750px\">";
    _movePlayer += "<param name=\"movie\" value=\"http://www.youtube.com/v/" + _value + "?rel=0\"><param name=\"allowFullScreen\" value=\"true\">";
    _movePlayer += "<param name=\"allowScriptAccess\" value=\"always\">";
    _movePlayer += "<param name=\"wmode\" value=\"transparent\">";
    _movePlayer += "<embed src=\"http://www.youtube.com/v/" + _value + "?rel=0\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" allowfullscreen=\"true\" allowScriptAccess=\"always\" width=\"750\" height=\"422\"></object>";

    return _movePlayer;
}

MainContentsChange.getTopUnitView = function(_number, _id, _type, _detailImage, _subject, _href, _target) {
    var _topUnitDetail = "";
    if (_type == "IMG") {
        _topUnitDetail += "<div class=\"view\" id=\"divmovie" + _number + "\"><a href=\""+_href+"\" target=\""+_target+"\"><img src=\"" + _detailImage + "\" alt=\"\" width=\"750\" height=\"422\" /></a></div>";
    } else {
        _topUnitDetail += "<div class=\"view\" id=\"divmovie" + _number + "\">" + this.getMovePlayer('divmovie' + _number, _detailImage) + "</div>";
    }

    _topUnitDetail += "<div class=\"data\">";
    _topUnitDetail += "<span class=\"txt\">" + _subject + "</span>";
    _topUnitDetail += "<span class=\"view\"><a href=\"" + _href + "\" target=\"" + _target + "\"><img src=\"/images/common/button/item2.etc.gif\" alt=\"상세보기\" /></a></span>";
    _topUnitDetail += "<span class=\"sns\">";
    _topUnitDetail += "<a href=\"#\" onclick=\"goSNS(2,'" + _href + "','" + _subject + "');return false;\"><img src=\"/images/common/icon/item1.sns.gif\" alt=\"FaceBook\" /></a>";
    _topUnitDetail += "<a href=\"#\" onclick=\"goSNS(1,'" + _href + "','" + _subject + "');return false;\"><img src=\"/images/common/icon/item2.sns.gif\" alt=\"Twitter\" /></a>";
    _topUnitDetail += "<a href=\"#\" onclick=\"goSNS(3,'" + _href + "','" + _subject + "');return false;\"><img src=\"/images/common/icon/item3.sns.gif\" alt=\"me2Day\" /></a>";
    _topUnitDetail += "</span>";
    _topUnitDetail += "</div>";

    this.getHtmlDisplay(_id, _topUnitDetail);
}

MainContentsChange.getHtmlOneView = function(_jsonGroupName, _jsonName, _viewId, _callback) {

    var _objGroupName = eval(_jsonGroupName);
    var _objGroupNameLength = _objGroupName.length;
    var _jsonHtml = "";
    var _objSubGroup = "";

    // 상단 6개 목록
    if (_jsonGroupName == "MainTopUnit") {
        for (var i = 0; i < _objGroupNameLength; i++) {
            _jsonHtml += "<li class=\"item" + i + "\">";
            _jsonHtml += "<a href=\"#\" id=\"unitid" + i + "\" onclick=\"MainContentsChange.getTopUnitView('" + i + "','movieItemView','" + _objGroupName[i].type + "', '" + _objGroupName[i].detailImage + "', '" + _objGroupName[i].title + "','" + _objGroupName[i].url + "','" + _objGroupName[i].target + "');";
            _jsonHtml += "MainContentsChange.getClassTabLoop('unitid'," + i + "," + parseInt(_objGroupNameLength) + ", '', 'on');";
            _jsonHtml += "MainContentsChange.getImageOnOffLoop('unitImg'," + i + "," + parseInt(_objGroupNameLength) + ",'_off','_on');";
            _jsonHtml += "return false;\" ";
            //_jsonHtml += "onmouseout=\"javascript:alert(this.className);\" ";
            _jsonHtml += "onmouseout=\"javascript:if ( this.className == 'on' ) { ";
            _jsonHtml += "  document.getElementById('unitImg" + i + "').src = document.getElementById('unitImg" + i + "').src.replace('_off','_on'); ";
            _jsonHtml += "  } else { ";
            _jsonHtml += "  document.getElementById('unitImg" + i + "').src = document.getElementById('unitImg" + i + "').src.replace('_on','_off');  ";
            _jsonHtml += "  } \" ";

            //if (i < 1) { /* 2011.05.16 수정함*/
            if (_objGroupName[i].firstview == "Y") {
                MainContentsChange.getTopUnitView(i, 'movieItemView', _objGroupName[i].type, _objGroupName[i].detailImage, _objGroupName[i].title, _objGroupName[i].url, _objGroupName[i].target);
                _jsonHtml += " class=\"on\" ";
            }
            _jsonHtml += " ><img src=\"" + _objGroupName[i].thumbImg + "\" id=\"unitImg" + i + "\" alt=\"\" onmouseover=\"javascript:this.src = this.src.replace('_off','_on');\" height=\"150\" /><span></span></a></li>";

        }

    }
    // 이벤트
    if (_jsonGroupName == "MainEvent") {
        for (var i = 0; i < _objGroupNameLength; i++) {
            _jsonHtml += "<span><a href=\"" + _objGroupName[i].url + "\" target=\"" + _objGroupName[i].target + "\" ><img src=\"" + _objGroupName[i].detailImg + "\" alt=\"" + _objGroupName[i].title + "\" /></a></span>";
        }
    }

    this.getHtmlDisplay(_viewId, _jsonHtml);

    if (_callback) _callback();
}

MainContentsChange.getHtmlArraryView = function(_jsonGroupName, _jsonName, _viewId) {

    var _jsonHtml = "";
    var _objGroupName = eval(_jsonGroupName);
    var _objGroupNameLength = _objGroupName.length;

    for (var i = 0; i < _objGroupNameLength; i++) {

        if (_objGroupName[i].jsonName == _jsonName) {

            var _objSubGroup = eval(_objGroupName[i].data);
            var _objSubGroupLength = _objSubGroup.length;

            if (_jsonName == "companyinfo" || _jsonName == "childreninfo" || _jsonName == "campaigninfo") {
                for (var isub = 0; isub < _objSubGroupLength; isub++) {
                    if (isub < 1) {
                        _jsonHtml += "<li class=\"on\" id=\"together" + isub + "\" ";
                    } else {
                        _jsonHtml += "<li id=\"together" + isub + "\" ";
                    }
                    if (isub < parseInt(togetherShowRows)) {
                        _jsonHtml += " style=\"display:'';\" >";
                    } else {
                        _jsonHtml += " style=\"display:none;\" >";
                    }
                    _jsonHtml += "<span class=\"label\"><em>" + _objSubGroup[isub].type + "</em></span> <a href=\"" + _objSubGroup[isub].url + "\" target=\"" + _objSubGroup[isub].target + "\" onmouseover=\"MainContentsChange.getClassTabLoop('together'," + isub + "," + parseInt(_objSubGroupLength) + ", '', 'on');\">" + _objSubGroup[isub].title + "</a><span class=\"img\"><img src=\"" + _objSubGroup[isub].thumbImg + "\" alt=\"\" width=\"129\" height=\"95\"/></span></li>";

                    MainContentsChange.getChangeLink("accompanymore", _objSubGroup[0].moreUrl);
                }

                //                if (_objSubGroupLength >= togetherShowRows) {
                MainContentsChange.getDisplayShow("movebutton");
                //                } else {
                //                    MainContentsChange.getDisplayHidden("movebutton");
                //                }

                this.getElementInput('grouptype', _jsonName);   // 선택된 그룹
                this.getElementInput('currentrow', 0);          // 현재 선택된 값
                this.getElementInput('totalTogetherCount', _objSubGroupLength);   // 총 갯수

            } else if (_jsonName == "people" || _jsonName == "photogallery" || _jsonName == "movie") {
                for (var isub = 0; isub < _objSubGroupLength; isub++) {
                    _jsonHtml += "<h2><img src=\"" + _objSubGroup[isub].titleImg + "\" /></h2>";
                    _jsonHtml += "<a href=\"" + _objSubGroup[isub].url + "\" target=\"" + _objSubGroup[isub].target + "\">";
                    _jsonHtml += "<strong class=\"tit\">" + _objSubGroup[isub].title + "</strong>";
                    _jsonHtml += "<span class=\"cnt\">" + _objSubGroup[isub].summary + "</span>";
                    _jsonHtml += "<span class=\"img\"><img src=\"" + _objSubGroup[isub].thumbImg + "\" alt=\"\"  width=\"97\" height=\"77\"/></span>";
                    _jsonHtml += "</a>";
                    _jsonHtml += "<span class=\"more\"><a href=\"" + _objSubGroup[isub].moreUrl + "\"><img src=\"/images/common/button/more.etc.gif\" alt=\"MORE\" /></a></span>";
                }
            } else if (_jsonName == "news" || _jsonName == "notice" || _jsonName == "volunteer") {
                for (var isub = 0; isub < _objSubGroupLength; isub++) {
                    _jsonHtml += "<li><a href=\"" + _objSubGroup[isub].url + "\">" + _objSubGroup[isub].title + "</a></li>";
                }
                this.getChangeLink("noticeviewmore", _objSubGroup[0].moreUrl);

            } else if (_jsonName == "smssupport") {
                //_jsonHtml += "<div class=\"listwrap\" id=\"roll\" style=\"height:14px; overflow:hidden;width:300px;\">";
                _jsonHtml += "  <ul>";
                for (var isub = 0; isub < _objSubGroupLength; isub++) {
                    if (isub == 0) {
                        //_jsonHtml += "<span class=\"item1\" id=\"smsport_" + isub + "\" >(" + _objSubGroup[isub].sender + ")" + _objSubGroup[isub].title + "</span>";
                        _jsonHtml += "<li class=\"item1\" id=\"smsport_" + isub + "\" >&nbsp&nbsp(" + _objSubGroup[isub].sender + ") " + _objSubGroup[isub].title + "</li>";
                    } else {
                        //_jsonHtml += "<span class=\"item1\" id=\"smsport_" + isub + "\" style=\"display:none;\"  >(" + _objSubGroup[isub].sender + ")" + _objSubGroup[isub].title + "</span>";
                        _jsonHtml += "<li class=\"item1\" id=\"smsport_" + isub + "\" style=\"display:'';\"  >&nbsp&nbsp(" + _objSubGroup[isub].sender + ") " + _objSubGroup[isub].title + "</li>";
                    }
                }
                _jsonHtml += "  </ul>";
                //_jsonHtml += "</div>";
                this.getElementInput("smsTotal", isub);
            }
        }
    }
    if (_jsonName == "companyinfo") { MainContentsChange.getChangeLink("accompanymore", "/Together/News/MinistryNewsList.asp"); }
    if (_jsonName == "childreninfo") MainContentsChange.getChangeLink("accompanymore", "/Together/News/ChildNewsList.asp");
    if (_jsonName == "campaigninfo") MainContentsChange.getChangeLink("accompanymore", "/Together/FeedBack/FeedBackList.asp");
    this.getHtmlDisplay(_viewId, _jsonHtml);

}

MainContentsChange.isObject = function(_objectName) {

    var objData = "";

    try { objData = eval(_objectName); } catch (Error) { };

    if (objData == "")
        return false;
    else
        return true;
}

MainContentsChange.getObjData = function(_objectName) {

    if (!MainContentsChange.isObject(_objectName))
        return;
    else
        return eval(_objectName);
}

// 언론보도 / 공지사항
function getMediaNoticeChange(_id, _jsonName, _moreLink) {
    MainContentsChange.getImageTabLoop("bbstab", _id, 3, "/images/main/tab_bbs");   // 탭 변경
    MainContentsChange.getClassTabLoop("bbstabli", _id, 3, "", "on");
    MainContentsChange.getHtmlArraryView("MainNewsNotice", _jsonName, "noticeview");
    //MainContentsChange.getChangeLink("noticeviewmore", _moreLink);  // 더보기 링크
}

// 동행
function getAcCompanyMouseOver(_id, _jsonName, _moreLink) {
    MainContentsChange.getImageTabLoop("accompany", _id, 3, "/images/main/tab_accompany");

    MainContentsChange.getElementInput('grouptype', _jsonName);
    MainContentsChange.getElementInput('totalTogetherCount', 0);
    MainContentsChange.getElementInput('currentrow', 0);

    MainContentsChange.getHtmlArraryView('MainContentsInfo', _jsonName, 'accompanyList');
    //MainContentsChange.getChangeLink("accompanymore", _moreLink);

}

/*
//=============== 동행 버튼 이동==================
*/
function RowChange() { }

// 위로( 하나씩 줄어둠 )
RowChange.getPrev = function() {
    var _GroupType = document.getElementById("grouptype");
    var _TotalTogetherCount = document.getElementById("totalTogetherCount");
    var _CurrentValue = document.getElementById("currentrow");
    if (_TotalTogetherCount.value > 0) {

        var _ShowValue = parseInt(_CurrentValue.value - 1);

        togetherMaxRows = _TotalTogetherCount.value;
        if (_ShowValue < 0) { _ShowValue = parseInt(_TotalTogetherCount.value - 1); } // 처음인 경우 맨 뒷에 것을 선택으로 함

        // 보여줘야 순번이 4보다 큰경우
        if (togetherShowRows <= _ShowValue) {
            for (var i = parseInt(_ShowValue - togetherShowRows); i >= 0; i--) {
                MainContentsChange.getDisplayHidden("together" + "" + i);
            }

            for (var i = togetherShowRows; i < _ShowValue; i++) {
                MainContentsChange.getDisplayShow("together" + i);
            }

            MainContentsChange.getDisplayShow("together" + _ShowValue);
            MainContentsChange.getElementInput('currentrow', _ShowValue);
            MainContentsChange.getClassTabLoop("together", _ShowValue, parseInt(_TotalTogetherCount.value), "", "on");
        }
        else if (togetherShowRows >= _ShowValue) {
            for (var i = parseInt(togetherMaxRows); i < togetherShowRows; i--) {
                MainContentsChange.getDisplayHidden("together" + "" + i);
            }
            for (var i = _ShowValue; i < togetherShowRows; i++) {
                MainContentsChange.getDisplayShow("together" + i);
            }
            MainContentsChange.getElementInput('currentrow', _ShowValue);
            MainContentsChange.getClassTabLoop("together", _ShowValue, parseInt(_TotalTogetherCount.value), "", "on");
        }
    }
}

// 아래로
RowChange.getNext = function() {
    var _GroupType = document.getElementById("grouptype");
    var _TotalTogetherCount = document.getElementById("totalTogetherCount");
    var _CurrentValue = document.getElementById("currentrow");
    if (_TotalTogetherCount.value > 0) {
        var _ShowValue = parseInt(_CurrentValue.value) + 1;

        togetherMaxRows = _TotalTogetherCount.value;
        
        if (_ShowValue >= togetherMaxRows) { _ShowValue = 0; }  // 초기값 셋팅
        if (_TotalTogetherCount.value < togetherShowRows) { togetherShowRows = _TotalTogetherCount.value; }
//        alert(togetherMaxRows);
  //      alert(_ShowValue);
    //    alert(togetherShowRows);
        if (togetherShowRows <= _ShowValue) {

            for (var i = parseInt(_ShowValue - togetherShowRows); i >= 0; i--) {
                MainContentsChange.getDisplayHidden("together" + "" + i);
            }

            for (var i = togetherShowRows; i < _ShowValue; i++) {
                MainContentsChange.getDisplayShow("together" + i);
            }
            if (_ShowValue <= togetherMaxRows) {
                MainContentsChange.getDisplayShow("together" + _ShowValue);
                MainContentsChange.getElementInput('currentrow', _ShowValue);
                MainContentsChange.getClassTabLoop("together", _ShowValue, parseInt(_TotalTogetherCount.value), "", "on");
            }
        } else if (togetherShowRows > _ShowValue) {
            for (var i = parseInt(togetherMaxRows); i < togetherShowRows; i--) {
                MainContentsChange.getDisplayHidden("together" + "" + i);
            }
            for (var i = _ShowValue; i < togetherShowRows; i++) {
                MainContentsChange.getDisplayShow("together" + i);
            }
            MainContentsChange.getElementInput('currentrow', _ShowValue);
            MainContentsChange.getClassTabLoop("together", _ShowValue, parseInt(_TotalTogetherCount.value), "", "on");
        }
    }
}


var smsTogetherMaxRows = 50;
var smsTogetherShowRows = 1;

function SmsChange() {

    var _TotalTogetherCount = document.getElementById("smsTotal");
    var _CurrentValue = document.getElementById("smsCurrent");
    
    if (_TotalTogetherCount.value > 0) {
        var _ShowValue = parseInt(_CurrentValue.value) + 1;

        smsTogetherMaxRows = _TotalTogetherCount.value;

        if (_ShowValue >= smsTogetherMaxRows) { _ShowValue = 0; }  // 초기값 셋팅

        if (_TotalTogetherCount.value < smsTogetherShowRows) { smsTogetherShowRows = _TotalTogetherCount.value; }

        // 최대값인 경우
        if (_ShowValue >= _TotalTogetherCount.value) {
            MainContentsChange.getDisplayHidden("smsport_" + parseInt(_TotalTogetherCount.value-1));
        } else if (_ShowValue == 0) {
            MainContentsChange.getDisplayHidden("smsport_" + parseInt(_TotalTogetherCount.value-1));
        } else {
            MainContentsChange.getDisplayHidden("smsport_" + parseInt(_ShowValue-1));
        }

        MainContentsChange.getDisplayShow("smsport_" + _ShowValue);
        MainContentsChange.getElementInput('smsCurrent', _ShowValue);
        
    }
}


    
