﻿(function ($) {

    /* 폼을 페이지에 맞춥니다. */
    $.fn.fitHeight = function (options) {
        var _self = this;

        this.childList = this.children("div");
        this._browserHeight = $(window).height();

        this._targetArray = [];

        /** 높이를 브라우저에 맞춥니다. */
        this.fitHeightTarget = [
            {
                root: "#header",
                content: [".myMBox", ".gnbWrap", ".membershipWrap", ".lnbWrap", ".miniMypWrap", "ul.viewerWrap", "div.posterWrap"]
            },
			{
			    root: "#container",
			    content: [".readyStepWrap"]
			},
			{
			    root: "#footer"
			}
		];

        /* fit height of  */
        this.fitHeightForm = function () {
            var bheight = _self._browserHeight;
            this.parent().children("div").height(bheight);
            $.each(this.fitHeightTarget, function (i, item) {
                if (!!item.root) {
                    if (!!item.content && item.content.length > 0) {
                        $.each(item.content, function (i, subItem) {
                            $(item.root).find(subItem).css("height", bheight + "px");
                        });
                    } else {
                        $(item.root).css("height", bheight + "px");
                    }
                }
            });
        };

        /* content resizing to browser size */
        this.heightInit = function () {
            _self.parent().height(_self._browserHeight);
            this.childList.each(function (sectionIndex) {
                $(this).children("div").height(_self._browserHeight).each(function () {
                    $(this).children("div:not('.nofit')").height(_self._browserHeight);
                });
            });
        };

        $(window).resize(function () {
            _self._browserHeight = $(window).height();
            _self.heightInit();
            _self.fitHeightForm();
        });

        _self.fitHeightForm();
        _self.heightInit();

    };

    $.fn.rollingEffect = function (options) {
        var $item = $(this);

        var defaults = $.extend({
            button: ".btn",
            content: "img",
            duration: 2400
        }, options);

        var viewHeight = 0;
        var viewWidth = 0;
        var rollingContent = null;
        var btnslength = $item.find(defaults.button).length;
        var rollingId = null;

        function rolling(startIndex) {
            clearInterval(rollingId);
            var selectedIndex = 0;
            rollingId = setInterval(function () {
                selectedIndex = startIndex++ % btnslength;
                rollingContent.animate({
                    marginLeft: "-" + viewWidth * selectedIndex + "px"
                }, 800);

                if (!!defaults.button) {
                    $item.find(defaults.button).removeClass("hover");
                    $item.find(defaults.button).eq(selectedIndex).addClass("hover");
                }
            }, defaults.duration);
        };

        setTimeout(function () {
            var imgs = $item.children(".roll_img");
            //			viewHeight = imgs.find("img").height();
            //			viewWidth  = imgs.find("img").width();
            viewHeight = 195;
            viewWidth = 209;

            rollingContent = $item.children(defaults.content).wrapAll($("<div>", {
                id: "rolling-content",
                css: {
                    height: viewHeight,
                    width: viewWidth * imgs.length
                }
            })).parent();
            rollingContent.wrap($("<div>", {
                css: {
                    width: viewWidth,
                    height: viewHeight,
                    overflow: "hidden",
                    marginBottom: "2px"
                }
            }));

            rolling(0);

            if (!!defaults.button) {
                $item.find(defaults.button).each(function (btnIndex) {
                    $(this).href().click(function () {
                        $item.find(defaults.button).removeClass("hover");
                        $(this).addClass("hover");
                        rolling(btnIndex);
                        rollingContent.animate({
                            marginLeft: "-" + viewWidth * btnIndex + "px"
                        }, 400);
                    });
                });
            }

        }, 10);

    };

    // 단일 섹션 모션 정의
    $.fn.extend({
        up: function () { },
        down: function () { },
        showLeftRight: function (distance, duration, disappear, callback) {
            var c = $.isFunction(disappear) ? disappear : callback;
            var d = $.isFunction(disappear) ? true : disappear;

            this.data("distance", distance)
			.data("duration", duration)
			.data("margin", -distance)
			.motion(d, c);
        },
        showRightLeft: function (distance, duration, disappear, callback) {
            var c = $.isFunction(disappear) ? disappear : callback;
            var d = $.isFunction(disappear) ? true : disappear;

            this.data("distance", distance)
			.data("duration", duration)
			.data("margin", distance)
			.motion(d, c);
        },
        hideRightLeft: function (distance, duration, callback) {
            var $self = $(this).wrapAll($("<div>", {
                'class': 'sectionA',
                width: distance + "px"
            }));

            $self.animate({ marginLeft: "-" + distance + "px" }, duration);
            $self.parent().animate({ width: "0px" }, duration, function () {

                if ($.isFunction(callback)) {
                    callback("post", $self);
                }
                $self.parent().empty().remove();
            });
        },
        motion: function (disappear, callback) {
            var $self = this;
            var distance = this.data("distance");
            var duration = this.data("duration");
            var margin = this.data("margin");

            if (!distance) return;

            if (disappear === false) {
                this.wrapAll($("<div>", {
                    'class': 'sectionA',
                    'css': {
                        'width': distance + "px",
                        'border': 'none',
                        'zIndex': 1
                    }
                })).parent().animate({ 'width': "0px" }, duration, function () {
                    $self.unwrap();
                    if ($.isFunction(callback)) {
                        callback("pre", $self);
                    }
                });
            } else {

                var $w = this.css({
                    'width': distance + "px",
                    'marginLeft': margin + "px"
                }).wrapAll($("<div>", {
                    'class': 'sectionA',
                    'css': {
                        'width': "0px",
                        'border': 'none',
                        'zIndex': 1
                    }
                }));

                $w.parent().animate({ width: distance + "px" }, duration);
                $w.animate({ 'marginLeft': 0 + "px" }, duration, function () {
                    $self.unwrap();
                    if ($.isFunction(callback)) {
                        callback("pre", $self);
                    }
                });
            }
        }
    });

    // true / false 여부에 따라 해당 섹션만큼 닫히고 열기 기능
    $.event.special.moveLeft = {};
    $.event.special.moveRight = {};

    // 전체 모션 이벤트 처리
    $.fn.slideEffect = function (options) {

        var _self = this;

        // 내부 사용 DOM 용 속성
        this.HIGHLIGHT_KEY = ".view-highlight";
        this.IS_WRAPPED = ".is_wrapped";
        this.BORDER_SIZE = 1.5;
        this.BACKGROUND_COLOR = "#f9f9f9";

        // default option
        this._settings = $.extend({
            wheelTarget: "",
            duration: 600,
            wheelRate: 8,
            thumbsize: 80,
            highlight: {
                id: "",
                position: "before", // first, before, after
                action: function (data) { }
            },
            callback: function () { }
        }, options, true);

        var $footer = $("#footer");
        var $header = $("#header");
        var $leftMenu;

        this._headerWidth = $header.width();

        this._currentBrowserWidth = $(window).width();
        this._currentBrowserHeight = $(window).height();
        this._cursor = 0;

        this._childList = this.children("div:visible").not("div.view-highlight, div.fixed, div.ownerLeft, div.ownerRight, div.ownerUp");

        this.abs = Math.abs;
        this.round = Math.round;

        this.initialize = function () {

            if (!!$.browser.msie) {
                $("body").attr("scroll", "no");
            } else {
                $("body").css({ overflow: "hidden" });
            }

            var wrapSize = $footer.width();

            _self._childList.each(function (i, item) {
                var sw = _self.getSectionWidth($(this)) + 1;
                $(this).css({
                    width: sw + "px",
                    "backgroundColor": _self.BACKGROUND_COLOR
                });
                wrapSize += sw;
            });

            _self.parent().css({ overflow: "hidden", height: _self._currentBrowserHeight + "px" });

            // 섹션 휠 이벤트 바인드
            _self.wheelEventBind(_self._childList);
            _self.wheelEventBind(this.children("div.fixed:visible"));

            wrapSize += (parseInt(_self._childList.length * _self.BORDER_SIZE));

            /* Width setting */
            _self.width(wrapSize);
            $("#wrap").width("100%");

            // 고정 섹션 추가시 footer left 맞추기 위함.
            var fixedSection = 0;

            // 숨은 섹션 초기화 작업
            _self.children(".ownerLeft, .fixed, .ownerRight, .ownerUp").each(function (index) {
                var $item = $(this).addClass("view-highlight");
                var $baseSection = null;

                var $sectionList = _self.children("div");
                var itemIndex = $sectionList.index($item);
                var ownerIndex = 0;
                var depth = 1;
                var direction = "left";

                function getBaseSec($list) {
                    var $baseSec = null;
                    $list.each(function (i) {
                        $baseSec = $(this);
                        if ($baseSec.is(":visible")) {
                            return false;
                        }
                    });
                    return $baseSec;
                }

                if ($item.is(".ownerLeft")) {
                    $baseSection = getBaseSec($sectionList.eq(itemIndex).nextAll());
                } else if ($item.is(".ownerRight")) {
                    $baseSection = getBaseSec($sectionList.eq(itemIndex).prevAll());
                    direction = "right";
                } else if ($item.is(".ownerUp")) {
                    $baseSection = getBaseSec($sectionList.eq(itemIndex).prevAll());
                    direction = "up";
                } else if ($item.is(".fixed")) {
                    if ($item.is(":visible")) {
                        // 초기부터 떠 있는 하이라이트 섹션 처리
                        _self.focusSection($item);
                        _self._headerWidth += $item.width();
                        fixedSection += $item.width() + 1;
                    }
                    $item.attr({ "is-highlight": "true" });
                    $baseSection = $item.next();
                }

                ownerIndex = ($item.is(".fixed") ? _self.getChildList() : $sectionList).index($baseSection);
                depth = $item.is(".fixed") ? 1 : (!!$baseSection.attr("depth") ? parseInt($baseSection.attr("depth")) + 1 : 1);
                var identity = "optional-section" + ownerIndex;

                $baseSection.attr({
                    "depth": depth,
                    "hidden-section": identity,
                    "section-index": ownerIndex
                });

                $item.attr({
                    "identity": identity + "-" + depth,
                    "direction": direction
                });

            }).each(function (i, item) {
                _self.getChildList().first().before($(item));
            });

            // Moveable 영역 wrapping 
            _self.getChildList().wrapAll($("<div>", {
                "class": "is_wrapped",
                css: {
                    "position": "absolute",
                    "width": wrapSize,
                    "left": _self._headerWidth - $header.width() + "px",
                    "z-index": "-1"
                }
            })).parent().append($footer.addClass("sectionA"));

            /* Member 영역 (#header) 초기화 */
            $header.find(".navWrap").children().not(":visible").each(function () {
                $(this).wrapAll($("<div>", {
                    id: "memberWrap",
                    css: { width: '0px', overflow: 'hidden', float: "left", display: "none" }
                }
				)).show();
            });

            _self.find("div.imgRolling").each(function () {
                $(this).rollingEffect({
                    content: "a.roll_img",
                    button: "a.btn"
                });
            });

            _self.getMoveableList().not("#footer").each(function (i) {
                $(this).attr({ "self-index": i });
            });

            getWrapper().bind("moveLeft", {}, function (event, distance) {
                getWrapper().animate({
                    left: "-=" + distance
                }, _self._settings.duration);
                _self._cursor += 1;
            })
			.bind("moveRight", {}, function (event, distance) {
			    getWrapper().animate({
			        left: "+=" + distance
			    }, _self._settings.duration);
			    _self._cursor -= 1;
			});
        };

        $.event.special.openElement = {
            setup: function (data) {
                // 열려 있는 확장 창을 닫습니다.
                var $openedList;
                if (data.current == "member") {
                    // 회원 로그인 헤더 폼
                    $openedList = _self.getOptionalMemberFormList(":visible");
                } else {
                    // 페이지 콘텐츠
                    $openedList = _self.find(".view-highlight:visible");
                }

                $openedList.each(function (i, item) {
                    $(item).triggerHandler("closeElement");
                });

                return false;
            }
        };

        $.event.special.closeElement = {
            setup: function (param) {
                var $self = $(this);
                // 닫기 모션
                if (!!param.close) {
                    $self.find(param.close)
					.href().click(function (e) {
					    $self.triggerHandler("closeElement");
					});
                }
                return false;
            }
        };

        this.getWidth = function ($item) {
            var childwidth = 0;
            if ($item.is("#view-wrap")) {
                $item.children("div:visible").each(function () {
                    childwidth += _self.getSectionWidth($(this)) + 1;
                });
            } else {
                childwidth = _self.round($item.width()) + 1;
            }
            return childwidth;
        },

		this.range = function ($list, max, min) {
		    var firstIndex = 0;
		    for (firstIndex; firstIndex < $list.length; firstIndex++) {
		        var $item = $list.eq(firstIndex);
		        var itemLeft = $item.offset().left;
		        if (itemLeft >= min && itemLeft <= max) {
		            break;
		        }
		    }
		    return firstIndex;
		};

        this.getRangeDiff = function ($list, left, max, min, sr) {
            var term = 0;
            var firstIndex = _self.range($list, left, min);
            var diff = sr - max;
            for (var i = firstIndex; i < $list.length; i++) {
                var itemWidth = _self.getWidth($list.eq(i));
                term += itemWidth;
                if (diff <= itemWidth) {
                    break;
                }
                diff -= itemWidth;
            }
            return term;
        };

        function getWrapper() {
            return _self.children(_self.IS_WRAPPED);
        }

        this.slideSection = function ($section, isLeft) {

            if (isLeft) {
                getWrapper().trigger("moveLeft", $section.width());
            } else {

                getWrapper().trigger("moveRight", $section.prev().width());
            }

        };


        /* 섹션 슬라이딩 이벤트 이전 열림 섹션 닫기 처리 */
        this.sliding = function (index) {

            var $targetList = _self.find("div.view-highlight:visible");

            $targetList.each(function () {
                $(this).triggerHandler("closeElement");
            });

            setTimeout(function () {
                _self.slidingMotion(index);
            }, $targetList.length > 0 ? _self._settings.duration : 0);

        };

        /* 섹션 슬라이딩 이벤트 처리 - Sliding motion for section */
        this.slidingMotion = function (index) {

            var indexDiff = index - _self._cursor;

            if (_self.is(':animated')) {
                _self.stop();
                return;
            }

            var term = 0;
            var $wraped = _self.children(_self.IS_WRAPPED);
            var selected = $wraped.children("div").eq(index);
            var selectedLeft = _self.round(selected.offset().left);
            var selectedRight = selectedLeft + _self.getWidth(selected);
            var $list = $wraped.children("div:visible");
            var max = $(window).width();
            var min = _self._headerWidth;
            if (selectedLeft >= min && selectedRight <= max) return;
            var notShortage = !(selectedRight - selectedLeft > max - min);

            if (notShortage && selectedRight <= min) {
                term = _self.abs(selectedLeft - min);
            } else if (notShortage && selectedLeft > max) {
                term = _self.getRangeDiff($list, selected.offset().left, max, min, selectedRight);
            } else if (notShortage && selectedLeft < max && selectedRight > max) {
                term = _self.getRangeDiff($list, selected.offset().left, max, min, selectedRight);
            } else {
                term = _self.abs(selectedLeft - min);
            }

            _self._cursor = index;
            term = (indexDiff > 0 ? -1 : 1) * _self.round(term);
            return $wraped.animate({ left: "+=" + term }, _self._settings.duration);

        };

        // 브라우저 사이즈 재계산
        this.browserSizeCalculate = function () {
            _self._currentBrowserWidth = $(window).width();
            _self._currentBrowserHeight = $(window).height();
        };

        this.getOptionalMemberFormList = function (opt) {
            return $header.find(".membershipWrap, .miniMypWrap").parent(opt);
        };

        // 헤더쪽 숨겨진창(로그인, 마이페이지 등) 모션 처리
        this.openHeaderElement = function (index, param) {

            var duration = _self._settings.duration;
            var $memberForm = _self.getOptionalMemberFormList().eq(index);

            if ($memberForm.hasClass("form-active")) return false;

            if ($memberForm.children(".need-scrollbar").length > 0) {

                setTimeout(function () {
                    var $sWrapper = $memberForm.find(".scrollWrap");
                    if (!$sWrapper.is(".scroll-activated")) {
                        $sWrapper.addClass("scroll-activated");
                        $sWrapper.children().first()
						.tinyscrollbar({
						    sizethumb: 40,
						    usedisable: true,
						    autosize: true
						});
                    }
                }, duration);
            }


            var $form = $memberForm.find(".membershipWrap, .miniMypWrap");
            if ($form.children(".header_scroll").length > -1) {
                if ($memberForm.find(".pageScrollWrap").length < 1) {
                    $form.children(".header_scroll")
					            .wrapAll($("<div>", {
					                'id': "wrapContents",
					                'class': 'pageScrollWrap',
					                css: {
					                    'position': 'relative',
					                    zIndex: '998'
					                }
					            }));

                    $form.children().not(".pageScrollWrap")
					            .wrapAll($("<div>", {
					                id: "wrapHeader",
					                css: { 'position': 'relative', zIndex: '999' }
					            }));

                    setTimeout(function () {
                        var contentTop = 0;
                        $form.find("#wrapHeader").children().each(function () {
                            contentTop += parseInt($(this).css("padding-bottom"));
                        });
                        $form.find("#wrapHeader").height($form.find("#wrapHeader").height() - (!!$.browser.msie ? contentTop : 0));
                    }, (!!$memberForm.is(":animated") ? 20 : 420));

                } else {
                    if (!!$memberForm.data('section_wheel')) {
                        $memberForm.data('section_wheel').scrollUpdate();
                    }
                }

                _self.wheelEventBind($memberForm);
            }


            /**
            * 헤더 로그인, 마이페이지, 비밀번호 변경 등 숨겨져 있는 창 모션 처리
            */
            $memberForm.bind("openElement", { current: "member" }, function () {
                setTimeout(function () {
                    if (!$memberForm.is(":animated")) {
                        var formWidth = $memberForm.children().width() + 1;

                        $memberForm.show().animate({ width: formWidth }, duration).addClass("form-active");
                        $header.animate({ width: "+=" + formWidth }, duration);
                        _self.animate({ left: "+=" + formWidth }, duration);
                        $memberForm.unbind("openElement");
                        _self._headerWidth += formWidth;
                    }
                    return false;
                }, $header.is(":animated") ? duration : 0);
            }).triggerHandler("openElement");

            var closeParameter = $.extend(param, { current: "member" });
            $memberForm.bind("closeElement", closeParameter, function () {
                headerAnimated = true;
                if (!$memberForm.is(":animated")) {
                    var formWidth = $memberForm.width();
                    $memberForm.animate({ width: "0px" }, duration, function () {
                        $memberForm.hide();
                    }).removeClass("form-active");
                    $header.animate({ width: "-=" + formWidth }, duration);
                    _self.animate({ left: "-=" + formWidth }, duration);
                    $memberForm.unbind("closeElement");

                    _self._headerWidth -= formWidth;
                    return false;
                }
            });
        };

        // 기존 섹션을 가져옵니다. 이동 가능한 섹션은 wrap 을 생성하여 추가 합니다.
        this.getBaseSection = function (baseSection) {
            var $target = _self.getSectionElement(baseSection); ;
            var $blockSec;

            if (baseSection.is(".fixed") || $target.is(".fixed")) {
                if (baseSection.is(".fixed")) {
                    $blockSec = _self.children("div:visible").first();
                } else {
                    $blockSec = getWrapper();
                    $blockSec.data("section_fixed", true);
                }
            } else {
                var sectionIndex = baseSection.attr("section-index");
                $blockSec = _self.getSectionByIndex(sectionIndex);
                if (!$blockSec.is("#view-wrap")) {
                    $blockSec.wrap($("<div>", {
                        id: "view-wrap",
                        'class': "sectionA",
                        'section-index': sectionIndex,
                        "self-index": $blockSec.attr("self-index"),
                        css: { width: _self.round($blockSec.width()) }
                    }));
                } else {

                    $blockSec = $blockSec.children(":visible").not(_self.HIGHLIGHT_KEY).first();
                }
            }
            return $blockSec;
        };

        this.getSectionByIndex = function (index) {
            return getWrapper().children("[section-index='" + index + "']:visible");
        };

        // 섹션 클래스 를 비교하여 폭을 가져옵니다.
        this.getSectionWidth = function (form) {
            //			if(!form.attr("class")) return;
            var formClasses = form.attr("class").split(" ");

            var sectionWidth = 0;
            $.each(formClasses, function (i, item) {
                if (!!item && item.indexOf("wd") > -1) {
                    sectionWidth = item.substring(2);
                    return false;
                }
            });
            return parseInt(sectionWidth);
        };

        // 숨겨진 섹션을 보여줌니다.
        this.showElement = function ($section, $template, param, callback) {
            if (_self.is(":animated")) return false;

            // 추가 섹션 포커싱
            var heightObj = { height: this._currentBrowserHeight };
            $template.addClass("seCrt").find(".innTpA").children("h3.secTit")
				.before($('<div>', { "class": "crtBgLt", css: heightObj }))
				.before($('<div>', { "class": "crtBgRt", css: heightObj }));

            _self.wheelEventBind($template);

            if ($template.attr("direction") === "up") {
                _self.updownElement($template, $section, param);
            } else {
                _self.appendElement($template, $section, param, callback);
            }

            if (!!$leftMenu && $section.parent().is("#view-wrap")) {
                $section.parent().mouseenter(function () {
                    $leftMenu.each(function (index) {
                        _self.justBlur($leftMenu.eq(index), index);
                    });
                    var sectionIndex = _self.getMoveableList().index($(this));
                    _self.justFocus($leftMenu.eq(sectionIndex), sectionIndex);
                });
            }
        };

        this.getSectionElement = function (section, formDepth) {
            var depth = "1";
            if (!!formDepth) {
                depth = formDepth;
            }
            var identity = section.attr("hidden-section") + "-" + depth;
            return _self.find("div[identity='" + identity + "']").not(":visible");
        },

        // 데이터를 바인딩 할 해당 섹션의 기본 폼을 가져옵니다.
		this.getTemplate = function (section, formDepth) {
		    var $clonedSection = _self.getSectionElement(section, formDepth).clone(true);

		    $clonedSection.find("select").commonForm().select();
		    $clonedSection.find(".radio label").commonForm().radio();
		    $clonedSection.find(".check label").commonForm().checkbox();

		    return $clonedSection;
		};

        function getInvisibleSectionCount() {
            var $wrap = getWrapper();
            var count = 0;
            var remain = _self.round(_self._headerWidth - $wrap.offset().left);
            $wrap.children("div:visible").each(function (i, item) {
                if (remain <= 2) {
                    return false;
                }
                remain -= _self.getWidth($(item));
                count++;
            });
            return count;
        };

        /* index 위치에 파라미터 방향으로 섹션을 추가합니다. */
        this.appendElement = function (data, baseSection, param, callback) {
            ;
            if (!data) return false;
            var isFixed = baseSection.is(".fixed") || $(data).is(".fixed");
            var $sec = _self.getBaseSection(baseSection);

            if (baseSection.is("highlight-activated")) return false;

            if (!data.is(":visible")) data.show();

            var contentWidth = _self.getSectionWidth(data);
            var duration = _self._settings.duration;
            data.addClass("view-highlight").css({ "width": "0px" });
            var $wrapped = getWrapper();

            /**
            * < 숨겨진 추가 섹션 열기 >
            * 1. 열려있는 추가 섹션을 닫고 ( duration * 1 ) 
            * 2. 사이즈에 맞추어 섹션을 이동 ( duration * 2 )
            * 3. 그 후 추가 섹션이 열림 
            * */
            data.bind("openElement", param, function (e) {
                var $self = $(this);
                var waitting = duration;
                // 사이즈에 맞추어 열려있는 섹션을 닫습니다.
                setTimeout(function () {

                    var $childList = _self.getMoveableList();
                    var secIndex = baseSection.attr("section-index");

                    var term = 0;

                    var secWidth = $sec.offset().left + _self.getWidth($sec);
                    if (!!$sec.data("section_fixed") && $sec.data("section_fixed") == true) {
                        secWidth = baseSection.offset().left + baseSection.width();
                    }

                    var diff = secWidth + _self.getSectionWidth(data) - $(window).width();
                    var invisibleCount = getInvisibleSectionCount();

                    if (diff > 0 && invisibleCount != secIndex) {

                        $childList
						.slice(invisibleCount, $sec.attr("self-index"))
						.each(function (i, item) {
						    var $item = $(item);

						    if ($item.is(baseSection)) {
						        return false;
						    }
						    var itemWidth = _self.getWidth($item);

						    term -= itemWidth;
						    if (diff < itemWidth) {
						        return false;
						    }
						    diff -= itemWidth;
						});

                        $wrapped.animate({ left: "+=" + term }, duration);
                    }

                    // 모션 중이면 이전 모션이 종료 후 다음 모션이 실행.
                    setTimeout(function () {

                        if (isFixed) { // 맨 앞 고정 섹션
                            $wrapped.animate({ left: "+=" + (contentWidth + 1) + "px" }, duration);
                            _self._headerWidth += contentWidth;
                        } else {
                            $wrapped.animate({ width: ("+=" + (contentWidth + 2) + "px") }, duration); // 모션에 따라 움직이는 생성된 창
                            _self.animate({ width: "+=" + contentWidth }, duration);
                        }

                        baseSection.addClass("highlight-activated");

                        (data.attr("direction") === "right" ? $sec.after($self) : $sec.before($self));

                        $sec.parent().animate({ width: "+=" + (contentWidth + 2) }, duration);

                        $self.showLeftRight(contentWidth, duration + 13, callback);

                        // 모션이 일어남과 동시에 수행
                        if ($.isFunction(param.preprocess)) {
                            param.preprocess.call();
                        }

                    }, $wrapped.is(":animated") ? waitting : 0);

                }, $wrapped.is(":animated") ? waitting : 0);

            }).triggerHandler("openElement");

            // 열려진 추가 섹션 닫기
            data.bind("closeElement", param, function () {
                var $self = $(this);
                var dw = _self.round($self.width());

                if (isFixed) {
                    $wrapped.animate({ left: "-=" + (dw + 1) + "px" }, duration);
                    _self._headerWidth -= contentWidth;
                } else {
                    $wrapped.animate({ width: ("-=" + (dw + 2) + "px") }, duration);
                    $sec.parent().animate({ width: "-=" + (dw + 2) }, duration);
                }
                baseSection.removeClass("highlight-activated");
                _self.width("-=" + dw + "px");

                $self.hideRightLeft(dw, duration - 13, callback);
            });
        };

        this.updownElement = function ($data, $baseSection, param) {
            if (!$data) return false;

            var height = $baseSection.find("#wheel_target_id").height();

            $baseSection.append($data);

            $data.css({
                top: height,
                position: "absolute",
                backgroundColor: _self.BACKGROUND_COLOR,
                zIndex: '9999'
            }).show();

            $data.animate({ top: "0px" }, _self._settings.duration);

            $data.hover(function () {
                _self.focusSection($data);
            }, function () {
                _self.blurSection($data);
            });

            $baseSection.find(param.close).href()
			.click(function () {
			    $data.animate({ top: height }, _self._settings.duration, function () {
			        $data.remove();
			    });
			});

        };

        this.focusSection = function ($sec) {
            if (!$sec.is(".seCrt")) {
                var heightObj = { height: this._currentBrowserHeight };
                $sec.addClass("seCrt")
					.find(".innTpA")
					.children("h3.secTit")
					.before($('<div>', { "class": "crtBgLt", css: heightObj }))
					.before($('<div>', { "class": "crtBgRt", css: heightObj }));
            }
        };

        this.blurSection = function ($sec) {
            $sec.removeClass("seCrt")
				.find("div.crtBgLt, div.crtBgRt").remove();
        };

        this.swapImage = function ($obj, flag) {
            try {
                var imgSrc = $obj.find("img").attr("src");
                $obj.find("img").attr({ src: flag ? imgSrc.replace("_off", "_on") : imgSrc.replace("_on", "_off") });
            } catch (e) { }
        };

        this.getChildList = function () {
            return _self.children(":visible").not(_self.HIGHLIGHT_KEY);
        };

        //*** Left Menu 세팅
        this.justFocus = function ($obj, index) {
            var $sec = _self.getMoveableList().eq(index);
            if ($sec.is("#view-wrap")) {
                $sec.children().each(function () {
                    _self.focusSection($(this));
                });
            } else {
                _self.focusSection($sec);
            }
            _self.swapImage($obj, true);
        };

        this.justBlur = function ($obj, index) {
            var $sec = _self.getMoveableList().eq(index);
            if ($sec.is("#view-wrap")) {
                $sec.children().each(function () {
                    _self.blurSection($(this));
                });
            } else {
                _self.blurSection($sec);
            }
            _self.swapImage($obj, false);
        };

        this.getMoveableList = function () {
            return getWrapper().children(":visible");
        };

        // left 메뉴를 초기화
        this.leftMenuInitialize = function ($list) {
            var $cList = _self.getMoveableList();

            if ($list.length < 1) {
                if ($cList.length > 0) {
                    _self.focusSection($cList.eq(0).is("#view-wrap") ? $cList.eq(0).children().last() : $cList.eq(0));
                }
                return false;
            }

            $leftMenu = $list;

            $list.each(function (i) {
                var $item = $(this);

                if (!$item.find("a").attr("href")) {
                    $item.find("a").href();
                }

                $item.click(function () {
                    _self.sliding(i);
                    $list.each(function (menuIndex) {
                        if (menuIndex != i) _self.justBlur($(this), menuIndex);
                    });

                    $cList.removeClass("view-active");
                    $cList.eq(i).addClass("view-active");
                    _self.focusSection($cList.eq(i));
                    _self.swapImage($item, true);
                });
            });

            $cList.each(function (i, item) {
                var $item = $(item);
                $item.mouseenter(function () {
                    $list.each(function (index) {
                        if (index != i) {
                            _self.justBlur($list.eq(index), index);
                        }
                    });
                    $cList.removeClass("view-active");
                    _self.focusSection($item);
                    $item.addClass("view-active");
                    _self.swapImage($list.eq(i), true);
                });
            });

            $cList.first().addClass("view-active");
            _self.justFocus($list.first(), 0);
        };

        // 섹션 휠 / 스크롤 처리를 위한 사용자 이벤트
        $.event.special.sectionScrollbar = {
            setup: function (data) {
                return false;
            }
        };

        // 섹션에 휠 이벤트를 연결합니다.
        this.wheelEventBind = function ($obj) {
            $obj.each(function () {
                var $item = $(this);
                $item.mouseenter(function (event) {
                    $item.bind("sectionScrollbar", {}, function (event, isMouseenter) {
                        if (!$item.is(".wheelable")) {
                            setTimeout(function () {
                                $item.addClass("wheelable").data('section_wheel', new SectionScroll($item, _self._settings));
                            }, 10);
                        } else {
                            if (!!$item.data("section_wheel")) {
                                if (isMouseenter) {
                                    $item.data('section_wheel').scrollUpdate();
                                } else {
                                    $item.data('section_wheel').update();
                                }
                            }
                        }
                    }).triggerHandler("sectionScrollbar", true);
                }).mouseleave(function (event) {
                    if ($item.is(".wheelable")) {
                        if (!!$item.data('section_wheel')) {
                            $item.attr({ "display-section": "false" }).data('section_wheel').hide();
                        }
                    }
                });
            });

        };

        $(window).resize(function () {
            _self.browserSizeCalculate();
            if (_self.find(".wheelable").length > 0) _self.find(".wheelable").triggerHandler("sectionScrollbar");
        });
        /************************************/
        // 헤더 멤버 부분
        this.showLogin = function (form) {

            _self.openHeaderElement(0, {
                close: "a.memClose"
            });
        };

        this.showChangePassword = function (form) {

            _self.openHeaderElement(1, {
                close: "a.memClose"
            });
        };

        this.showMyPage = function (form) {
            var $img = $(form).find("img");
            var imgSrc = $img.attr("src");
            $img.attr({ src: imgSrc.replace("_off", "_on") });
            _self.openHeaderElement(3, {
                close: "a.memClose"
            });
        };

        this.showLoginError = function (form) {
            _self.openHeaderElement(2, {
                close: "a.memClose"
            });
        };

        this.showLoginNonMember = function (form) {

            _self.openHeaderElement(4, {
                close: "a.memClose"
            });

        };

        /************************************/

        // 페이지 초기화
        this.initialize();
        this.browserSizeCalculate();

        // 좌측 탭 메뉴에 페이지 모션 연결
        if (!!options.leftMenu) {
            this.leftMenuInitialize($(options.leftMenu));
        }

        return this;
    };

    /***********************************/

    // 섹션 휠 / 스크롤 처리 객체 
    function SectionScroll(target, options) {
        var _objectSelf = this;
        var _item = target;
        var _wrapper;
        var _wheelTarget = _item.find(options.wheelTarget)
			.css({
			    overflow: "hidden",
			    height: _item.find(options.wheelTarget).height()
			});
        var iScroll, iPosition = { start: 0, now: 0 }, iMouse = {};

        var min = Math.min;
        var max = Math.max;

        if (_item.find("#wheel_target_id").children().length < 1) {
            _wheelTarget.children().wrapAll($("<div>", {
                id: "wheel_target_id",
                css: { position: "relative", marginTop: "0px",
                    float: "left",
                    width: _item.find(options.wheelTarget).width()
                }
            }));
        }


        _wrapper = _item.find("#wheel_target_id");
        _wheelTarget.before($('<div class="sec_scrollbar"><div class="sec_track"><div class="sec_thumb"> </div></div></div>'));

        var _viewport = {};
        var oScrollbar = { obj: $('.sec_scrollbar', _item) };
        var oTrack = { obj: $('.sec_track', oScrollbar.obj) };
        var oThumb = { obj: $('.sec_thumb', oScrollbar.obj) };
        var oWrapper = _wheelTarget;
        /*
        var mLeft = 15;
        if (_item.width() - _wheelTarget.width() == 0) {
        mLeft = -10;
        }
        */
        var mLeft = 15;
        var widthDiff = _item.width() - _wheelTarget.width();
        if (widthDiff > -10 && widthDiff < 10) {
            mLeft = -10;
        }

        oScrollbar.obj.css("marginLeft", _wheelTarget.width() + mLeft);

        _wrapper.addClass("masked");
        _wrapper.before($('<div>', { 'class': 'masking', css: { zIndex: "20", display: "none"} }));
        function initialize() {

            if (!_wheelTarget || !_wheelTarget.offset()) {
                return;
            }
            _objectSelf.update();

            if (($(window).height() - _wheelTarget.offset().top) > _wrapper['y']) {
                _item.find(".sec_scrollbar").hide();
            } else {
                _item.find(".sec_scrollbar").show();
                setEvents();
            }
            return _objectSelf;
        }

        this.removeScroll = function () {
            _wrapper.children().unwrap();
            _item.find(".sec_scrollbar").remove();
            _item.find(".masking").remove();
        };

        this.scrollUpdate = function () {
            if (!_wheelTarget || !_wheelTarget.offset()) {
                return false;
            }

            if ($(window).height() - _wheelTarget.offset().top > _wrapper.height()) {
                _item.find(".sec_scrollbar").hide();
                unbindEvents();
            } else {
                _item.find(".sec_scrollbar").show();
                setEvents();
            }
        };

        this.update = function (sScroll) {
            // 섹션 스크롤 하단 20px
            if (!_wheelTarget || !_wheelTarget.offset()) {
                return false;
            }
            _viewport['y'] = $(window).height() - _wheelTarget.offset().top - 20;

            var _vpY = _viewport['y'];
            _wrapper['y'] = _wrapper.height();
            if ($(window).height() - _wheelTarget.offset().top > _wrapper['y']) {
                _item.find(".sec_scrollbar").hide();
                unbindEvents();
            } else {
                _item.find(".sec_scrollbar").show();
                setEvents();
            }

            _wrapper.ratio = _vpY / _wrapper['y'];
            oTrack['y'] = _vpY;
            oThumb['y'] = min(oTrack['y'], max(0, options.thumbsize)); // oThumb['y'] = Math.min(oTrack['y'], Math.max(0, oTrack['y'] * _wrapper.ratio));
            oScrollbar.ratio = (_wrapper['y'] - _viewport['y']) / (oTrack['y'] - oThumb['y']); // oScrollbar.ratio = _wrapper['y'] / _vpY;
            iScroll = (sScroll == 'relative' && _wrapper.ratio <= 1) ? min((_wrapper['y'] - _vpY), max(0, iScroll)) : 0;
            iScroll = (sScroll == 'bottom' && _wrapper.ratio <= 1) ? (_wrapper['y'] - _vpY) : isNaN(parseInt(sScroll)) ? iScroll : parseInt(sScroll);
            setSize();
        };

        this.show = function () {
            _item.find(".masking").show();
            _item.find(".sec_scrollbar").show();
        };

        this.hide = function () {
            _item.find(".masking").hide();
            _item.find(".sec_scrollbar").hide();
        };

        function setSize() {
            oThumb.obj.css('top', iScroll / oScrollbar.ratio);
            _wrapper.css('top', -iScroll);
            iMouse['start'] = oThumb.obj.offset()['top'];
            var sCssSize = "height";
            oScrollbar.obj.css(sCssSize, oTrack['y']);
            oTrack.obj.css(sCssSize, oTrack['y']);
            oThumb.obj.css(sCssSize, oThumb['y']);
        };
        function unbindEvents() {
            try {
                if (this.addEventListener) {
                    oWrapper[0].removeEventListener('DOMMouseScroll', wheel, false);
                    oWrapper[0].removeEventListener('mousewheel', wheel, false);
                } else {
                    oWrapper[0].onmousewheel = null;
                }
            } catch (e) { }
        };
        function setEvents() {
            oThumb.obj.bind('mousedown', start);
            oThumb.obj[0].ontouchstart = function (oEvent) {
                oEvent.preventDefault();
                oThumb.obj.unbind('mousedown');
                start(oEvent.touches[0]);
                return false;
            };
            oTrack.obj.bind('mouseup', drag);
            try {
                if (this.addEventListener) {
                    oWrapper[0].addEventListener('DOMMouseScroll', wheel, false);
                    oWrapper[0].addEventListener('mousewheel', wheel, false);
                } else {
                    oWrapper[0].onmousewheel = wheel;
                }
            } catch (e) { }
        };

        function start(oEvent) {
            _wheelTarget.find(".masking").show();
            iMouse.start = oEvent.pageY;
            var oThumbDir = parseInt(oThumb.obj.css('top'));
            iPosition.start = oThumbDir == 'auto' ? 0 : oThumbDir;
            $(document).bind('mousemove', drag);
            document.ontouchmove = function (oEvent) {
                $(document).unbind('mousemove');
                drag(oEvent.touches[0]);
            };
            $(document).bind('mouseup', end);
            oThumb.obj.bind('mouseup', end);
            oThumb.obj[0].ontouchend = document.ontouchend = function (oEvent) {
                $(document).unbind('mouseup');
                oThumb.obj.unbind('mouseup');
                end(oEvent.touches[0]);
            };
            return false;
        };

        function end(oEvent) {
            _wheelTarget.find(".masking").hide();
            $(document).unbind('mousemove', drag);
            $(document).unbind('mouseup', end);
            oThumb.obj.unbind('mouseup', end);
            document.ontouchmove = oThumb.obj[0].ontouchend = document.ontouchend = null;
            return false;
        };

        function drag(oEvent) {
            if (!(_wrapper.ratio >= 1)) {
                iPosition.now = Math.min((oTrack['y'] - oThumb['y']), Math.max(0, (iPosition.start + ((oEvent.pageY) - iMouse.start))));
                iScroll = iPosition.now * oScrollbar.ratio;
                _wrapper.css('top', -iScroll);
                oThumb.obj.css('top', iPosition.now);
            }
            return false;
        };

        var timeId = null;
        function wheel(oEvent) {
            var $masking = _wheelTarget.find(".masking");

            if (!!timeId) clearTimeout(timeId);
            if (!$masking.is(".visible")) $masking.show();
            timeId = setTimeout(function () {
                timeId = null;
                $masking.hide();
            }, 600);

            oEvent = $.event.fix(oEvent || window.event);
            var iDelta = oEvent.wheelDelta ? oEvent.wheelDelta / 120 : -oEvent.detail / 3;
            iScroll -= iDelta * 40;
            iScroll = Math.min((_wrapper['y'] - _viewport['y']), Math.max(0, iScroll));
            oThumb.obj.css("top", iScroll / oScrollbar.ratio);
            _wrapper.css("top", -iScroll);
            oEvent.stopPropagation();
            oEvent.preventDefault();
            oEvent.cancelBubble = false;
            return false;
        }
        return initialize();
    }

    $.fn.extend({
        liHeight: 0,
        up: function () {
            if ($(window).height() < (this.liHeight * (this.find("li:visible").length - 1))) {
                this.find("li:visible").first().hide();
            }
        },
        down: function () {
            this.find("li").not(":visible").last().show();
        },
        wheelForm: function (rate) {
            var _self = this;
            _self.liHeight = _self.find("li:eq(0)").height();

            _self
				.wrap($("<div>", { css: { position: "relative", overflow: "hidden", height: ($(window).height() - $(this).offset().top)} }))
				.bind("mousewheel", function (event, data) {
				    data < 0 ? _self.up() : _self.down();
				});

            _self.keydown(function (e) {
                if (e.keyCode == 40) _self.up();
                else if (e.keyCode == 38) _self.down();
                e.stopPropagation();
                e.preventDefault();
                e.cancelBubble = false;
            });

            $(window).resize(function () {
                _self.parent().height($(window).height());
            });
        }
    });

    var types = ['DOMMouseScroll', 'mousewheel'];

    $.event.special.mousewheel = {
        setup: function () {
            if (this.addEventListener) {
                for (var i = types.length; i; ) {
                    this.addEventListener(types[--i], handler, false);
                }
            } else {
                this.onmousewheel = handler;
            }
        },

        teardown: function () {
            if (this.removeEventListener) {
                for (var i = types.length; i; ) {
                    this.removeEventListener(types[--i], handler, false);
                }
            } else {
                this.onmousewheel = null;
            }
        }
    };

    $.fn.extend({
        mousewheel: function (fn) {
            return fn ? this.bind("mousewheel", fn) : this.trigger("mousewheel");
        },

        unmousewheel: function (fn) {
            return this.unbind("mousewheel", fn);
        }
    });


    function handler(event) {

        var orgEvent = event || window.event, args = [].slice.call(arguments, 1), delta = 0, returnValue = true, deltaX = 0, deltaY = 0;
        event = $.event.fix(orgEvent);
        event.type = "mousewheel";

        // Old school scrollwheel delta
        if (event.wheelDelta) { delta = event.wheelDelta / 120; }
        if (event.detail) { delta = -event.detail / 3; }

        // New school multidimensional scroll (touchpads) deltas
        deltaY = delta;

        // Gecko
        if (orgEvent.axis !== undefined && orgEvent.axis === orgEvent.HORIZONTAL_AXIS) {
            deltaY = 0;
            deltaX = -1 * delta;
        }

        // Webkit
        if (orgEvent.wheelDeltaY !== undefined) { deltaY = orgEvent.wheelDeltaY / 120; }
        if (orgEvent.wheelDeltaX !== undefined) { deltaX = -1 * orgEvent.wheelDeltaX / 120; }

        // Add event and delta to the front of the arguments
        args.unshift(event, delta, deltaX, deltaY);

        return $.event.handle.apply(this, args);
    };

    // 풀 다운 목록
    $.fn.extend({
        href: function () {
            var $current = this;
            if (!$current.attr("href") || $current.attr("href") == "#") {
                $current.removeAttr("href")
				.css({ cursor: "pointer" });
            }
            return $current;
        },
        scrollFit: function (opt) {
            var wheelController = this.data("section_wheel");

            var option = $.extend({
                delay: 20,
                scroll: null
            }, opt);

            if (!!wheelController) {
                setTimeout(function () {
                    // 타겟은 클릭이 일어난 탭이므로 약간의 딜레이를 주어 다음 탭의 사이즈에 맞게
                    // 계산을 할 수 있도록 처리
                    wheelController.update(option.scroll);
                }, option.delay);
            }
        },
        pullDownList: function (option) {
            var $self = this;
            if (!option.buttonName) return;
            if (!$self.attr("class")) return;
            var param = $.extend({ min: 6, duration: 600 }, option);
            var minHeight = $self.height();
            var $paging = $self.next();

            $self.nextAll().wrapAll($("<div>", {
                id: option.identity
            })).parent()
			.find(param.buttonName).href()
			.live("click", function () {

			    var $img = $(this).find("img");
			    var min = param.min;
			    var selfHeight = $self.height();
			    var $wrapper;

			    if (!$self.parent().is(".pull-down-wrap")) {
			        $wrapper = $self.wrap($("<div>", {
			            'class': "pull-down-wrap",
			            css: { height: selfHeight + "px", overflow: "hidden" }
			        })).parent();
			    } else {
			        $wrapper = $self.parent();
			    }

			    $self.find("li:last").removeClass("last");
			    if (!$self.hasClass("pull-active")) {
			        // 데이터 바인딩
			        var result = param.action($self);
			        if (result) {
			            $self.addClass("pull-active");
			            $wrapper.animate({ height: $self.height() + "px" }, 400, function () {
			                $img.attr({ "src": $img.attr("src").replace("_down", "_up") });
			                if ($paging.is(".paging")) $paging.show();
			                $self.find("li:last").addClass("last");
			                setTimeout(function () {
			                    $("div.sectionA", document.getElementById("container"))
									.not(".view-highlight").each(function () {
									    if (!!$(this).find($self).html()) {
									        $(this).data("section_wheel").update();
									    }
									});
			                }, 400);
			            });
			        }

			    } else {
			        if ($paging.is(".paging")) $paging.hide();
			        $wrapper.animate({ height: minHeight + "px" }, 400, function () {
			            $self.find("li").eq(min - 1).nextAll().remove();
			            $self.removeClass("pull-active");
			            $img.attr({ "src": $img.attr("src").replace("_up", "_down") });
			            $self.find("li:last").addClass("last");
			            setTimeout(function () {
			                $("div.sectionA", document.getElementById("container"))
								.not(".view-highlight").each(function () {
								    if (!!$(this).find($self).html()) {
								        $(this).data("section_wheel").update();
								    }
								});
			            }, 400);
			        });
			    }
			});
        }
    });

    $.fn.extend({
        seatLayer: function (option) {

            var $layerItem = $('<div class="layer" style="display:none;position:absolute;"></div>');

            $("#container").append($layerItem);

            this.find("li").each(function () {
                var $row = $(this);
                $row.find("a:not('.out')").each(function () {
                    var $col = $(this);
                    $col.hover(function () {
                        $layerItem.empty();
                        if (!!$col.attr("seat")) {
                            var seatList = $col.attr("seat").split(";");
                            $('<strong class="seat1">' + seatList[0] + '</strong>').appendTo($layerItem);
                            $('<span class="bar">|</span>').appendTo($layerItem);
                            $('<strong class="seat2">' + seatList[1] + '</strong>').appendTo($layerItem);
                        }
                        var l = $col.offset().left - $("#header").width() - 13;
                        var t = $col.offset().top - 30;
                        $layerItem.css({
                            top: t,
                            left: l
                        }).show();
                    }, function () {
                        $layerItem.hide();
                    });
                });
            });

        }
    });

})(jQuery);

$(document).ready(function () {

    /***** 공통 적용 *****/

    // 페이지 공통 브라우저 높이 맞춤
    $("#container").fitHeight();

    // 페이지 모션 처리 
    var slider = $("#container").slideEffect({
        wheelTarget: ".pageScrollWrap",
        duration: 400,
        leftMenu: "#header ol.stepList li"
    });

    $("#container").data("slider", slider);

    /***** 헤더 *****/

    // 포스터 휠 액션처리	
    $(".posterList").wheelForm();

    // 로그인
    $("#btn_login").href().live("click", function () {
        slider.showLogin(this);
        return false;
    });

    // 마이 페이지
    /*
    $("#header .sbmBtA:eq(0)").href().live("click", function () {
    //slider.showLoginError(this);
    return false;
    });
    */
    // 마이 페이지
    $("#header img[alt='마이페이지']").parent().href()
	.click(function () {
	    slider.showMyPage(this);
	    return false;
	});

    // 비밀번호 변경
    $("#header .sbmBtA:eq(2)").href().live("click", function (i) {
        slider.showChangePassword(this);
        return false;
    });

    /***** 페이지 일반 *****/

    // M3_event_expand.html 사용
    slider.getMoveableList().each(function (i, item) {
        var $section = $(this);
        if ($section.is(".is_event")) {

            $section.find(".num01").find(".eventExpand img").live("click", function () {
                var $template = slider.getTemplate($section);

                slider.showElement($section, $template, {
                    close: ".slideClose"
                });
            });

            $section.find(".num01").find(".mgb20 img").live("click", function () {
                var eventid = $(this).parents("a").attr("href");
                var aeventid = eventid.split("#");
                eventid = aeventid[1];
                var pars = "EVENTID=" + eventid;
                /*레이러 팝업일경우 예외처리하는 부분*/
                if (eventid == "1274") {
                    Event2012MovieReplay();
                }
                else {
                    var url = "/Event/ajaxEventDetail.aspx";          // URL
                    $.ajax({
                        type: "post",
                        url: url,
                        data: pars,
                        success: function (msg) {
                            //document.getElementById('MegaEventDetail01').innerHTML = msg;
                            //currentid = "MegaEventDetail01";
                            var $template = slider.getTemplate($section);
                            $template.find("#MegaEventDetail01").html(msg);
                            $template.find("#MegaEventDetail02").html("");
                            $template.find("#MegaEventDetail03").html("");
                            slider.showElement($section, $template, {
                                position: $section.attr("direction"),
                                close: ".slideClose"
                            });
                        }
                    });
                }


                /*
                var $template = slider.getTemplate($section);
			
                slider.showElement($section, $template, {
                close : ".slideClose"
                });
                */
            });
        }


        //		$section.find("#multi2").live("click", function(){
        //			var $template = slider.getTemplate($section);
        //			/* 이부분에서 ajax 요청등을 호출 */
        //			
        //			slider.showElement($section, $template, {
        //				close : "a:eq(1)"
        //			});
        //			
        //			return false;
        //		});

        if ($section.is(".movie_event")) {
            $section.find(".num02").find(".eventExpand img").live("click", function () {
                var $template = slider.getTemplate($section);

                slider.showElement($section, $template, {
                    close: ".slideClose"
                });
            });

            $section.find(".num02").find("p.mgb20 a").live("click", function () {
                //var eventid = $(this).parents("a").attr("href");
                var eventid = $(this).attr("href");
                var aeventid = eventid.split("#");
                eventid = aeventid[1];
                var pars = "EVENTID=" + eventid;
                /*레이러 팝업일경우 예외처리하는 부분*/
                if (eventid == "1274") {
                    Event2012MovieReplay();
                }
                else {
                    var url = "/Event/ajaxEventDetail.aspx";          // URL
                    $.ajax({
                        type: "post",
                        url: url,
                        data: pars,
                        success: function (msg) {
                            //document.getElementById('MegaEventDetail01').innerHTML = msg;
                            //currentid = "MegaEventDetail01";
                            var $template = slider.getTemplate($section);
                            $template.find("#MegaEventDetail01").html("");
                            $template.find("#MegaEventDetail02").html(msg);
                            $template.find("#MegaEventDetail03").html("");
                            slider.showElement($section, $template, {
                                position: $section.attr("direction"),
                                close: ".slideClose"
                            });
                        }
                    });
                }


                /*
                var $template = slider.getTemplate($section);
			
                slider.showElement($section, $template, {
                close : ".slideClose"
                });
                */
            });
            /*
            $section.find("p.mgb20 a").live("click", function () {
            var eventid = $(this).attr("href");
            var aeventid = eventid.split("#");
            eventid = aeventid[1];
            var pars = "EVENTID=" + eventid;

            var url = "/Event/ajaxEventDetail.aspx";          // URL
            $.ajax({
            type: "post",
            url: url,
            data: pars,
            success: function (msg) {
            document.getElementById('MegaEventDetail01').innerHTML = "";
            document.getElementById('MegaEventDetail02').innerHTML = msg;
            document.getElementById('MegaEventDetail03').innerHTML = "";
            currentid = "MegaEventDetail02";

            var $template = slider.getTemplate($section);
            slider.showElement($section, $template, {
            position: $section.attr("direction"),
            close: ".slideClose"
            });
            }
            });
            return false;
            });
            */
        }

        if ($section.is(".branch_event")) {
            $section.find(".num03").find(".eventExpand img").live("click", function () {
                var $template = slider.getTemplate($section);

                slider.showElement($section, $template, {
                    close: ".slideClose"
                });
            });
            $section.find(".num03").find(".descTit a").live("click", function () {
                //var eventid = $(this).parents("a").attr("href");
                var eventid = $(this).attr("href");
                var aeventid = eventid.split("#");
                eventid = aeventid[1];
                var pars = "EVENTID=" + eventid;
                /*레이러 팝업일경우 예외처리하는 부분*/
                if (eventid == "1274") {
                    Event2012MovieReplay();
                }
                else {
                    var url = "/Event/ajaxEventDetail.aspx";          // URL
                    $.ajax({
                        type: "post",
                        url: url,
                        data: pars,
                        success: function (msg) {
                            //document.getElementById('MegaEventDetail01').innerHTML = msg;
                            //currentid = "MegaEventDetail01";
                            var $template = slider.getTemplate($section);
                            $template.find("#MegaEventDetail01").html("");
                            $template.find("#MegaEventDetail02").html("");
                            $template.find("#MegaEventDetail03").html(msg);
                            slider.showElement($section, $template, {
                                position: $section.attr("direction"),
                                close: ".slideClose"
                            });
                        }
                    });
                }
            });
            /*
            $section.find(".descTit a").live("click", function () {
            var eventid = $(this).attr("href");
            var aeventid = eventid.split("#");
            eventid = aeventid[1];
            var pars = "EVENTID=" + eventid;
            var url = "/Event/ajaxEventDetail.aspx";          // URL
            $.ajax({
            type: "post",
            url: url,
            data: pars,
            success: function (msg) {
            document.getElementById('MegaEventDetail01').innerHTML = "";
            document.getElementById('MegaEventDetail02').innerHTML = "";
            document.getElementById('MegaEventDetail03').innerHTML = msg;
            currentid = "MegaEventDetail03";
            var $template = slider.getTemplate($section);
            slider.showElement($section, $template, {
            position: $section.attr("direction"),
            close: ".slideClose"
            });
            }
            });
            return false;
            });
            */
        }

        if ($section.is(".wd300")) {
            $section.find("ul.eventWinList a")
			.live("click", function () {
			    var eventid = $(this).attr("href");
			    aeventid = eventid.split("#");
			    eventid = aeventid[1];
			    var pars = "EVENTID=" + eventid;
			    var url = "/Event/ajaxEventPrizeDetail.aspx";          // URL
			    $.ajax({
			        type: "post",
			        url: url,
			        data: pars,
			        success: function (msg) {
			            document.getElementById('RepeaterEventsPrizeDetail').innerHTML = msg;
			            currentid = "RepeaterEventsPrizeDetail";
			            var $template = slider.getTemplate($section);
			            slider.showElement($section, $template, {
			                position: $section.attr("direction"),
			                close: ".slideClose"
			            });
			        }
			    });
			    /*				
			    var $template = slider.getTemplate($section);
			    // 이부분에서 ajax 요청등을 호출
			    slider.showElement($section, $template, {
			    close : ".slideClose"
			    });
			    */
			    return false;
			});
        }

        $section.find(".btn_prev_events").href().live("click", function () {
            var $template = slider.getTemplate($section, "2");
            /* 이부분에서 ajax 요청등을 호출 */

            slider.showElement($section, $template, {
                close: ".slideClose"
            });
            return false;
        });

    });

    // 목록 드롭다운 처리
    // ul.eventWinList 		= event/M3_event_expand.html
    // #mComunity1 ul.list 	= movie/M1_movie_detail.html 
    //	$("ul.eventWinList").pullDownList({
    //		identity:"eventWinList",
    //		buttonName:".moreBtWrap .pullDown",
    //		action:function(base){
    //			for(var i = base.find("li").length ; i < 10 ; i++){
    //				base.append(base.find("li").eq(0).clone(false));						
    //			}
    //			return true;
    //		}
    //	});

    $("#tab_movie_first").each(function () {
        var $item = $(this);
        $item.find(".movie-tab").find("img")
		    .click(function () {
		        $item.scrollFit();
		    });
    });

    $("#mComunity1 ul.list").pullDownList({
        identity: "list",
        buttonName: ".moreBtWrap .pullDown",
        action: function (base) {
            for (var i = base.find("li").length; i < 10; i++) {
                base.append(base.find("li").eq(0).clone(false));
            }
            return true;
        }
    });

    $("ul.liveTalk").pullDownList({
        identity: "liveTalk",
        buttonName: ".moreBtWrap .pullDown",
        action: function (base) {
            for (var i = base.find("li").length; i < 10; i++) {
                base.append(base.find("li").eq(0).clone(false));
            }
            return true;
        }
    });

    // M1_movie_detail.html
    slider.children(".fixed:visible").each(function (i) {
        var $item = $(this);
        $item.find(".subject span.num").live("click", function () {

            var $template = slider.getTemplate($item);

            slider.showElement($item, $template, {
                close: ".slideClose"
            });

            return false;
        });
    });

    $("div.btnMore a").href().live("click", function () {
        /*로그인체크 먼저*/
        var pars = "";
        var url = "/Member/Login/UserCertification.aspx";
        $.ajax({
            type: "post",
            url: url,
            data: pars,
            success: function (msg) {
                var serverData = msg;
                var evalData = eval("(" + serverData + ")");
                try {
                    if (evalData.result == "0000") {
                        /*로그인 성공*/
                        document.getElementById("moviecomment").style.display = "block";
                    }
                    else {
                        /*로그인 실패!!*/
                        alert("로그인을 먼저해주세요.");
                        slider.showLogin(this);
                    }
                } catch (err) { }
                finally {
                }
            }
        });

        //slider.showLogin(this);
    });


    $("#header .btn_login1 a").href().live("click", function () {
        try {
            var logtype = document.getElementById("LoginType").value;
            if (logtype == "Y") {
                window.location.href = "/MyPage/default.aspx";
            }
            else {
                /*로그인체크 먼저*/
                alert("로그인을 먼저해주세요.");
                slider.showLogin(this);
            }
        } catch (err) { }
        finally {
        }
        //slider.showLogin(this);
    });



    // M2_theater_detail.html

    slider.getMoveableList().each(function (i) {
        var $section = $(this);

        $section.find("div.theaterInfo a.btnStore").live("click", function () {
            var $template = slider.getTemplate($section);

            slider.showElement($section, $template, {
                close: ".slideClose"
            });
        });
    });

    // M0_customer.html
    $(document).delegate("dl.qnaList > dt", "click", function () {
        var $dt = $(this);
        var $tab = $("div.is_qna_list");
        var option = { delay: 420, scroll: "relative" };
        if ($dt.is(".is-opened")) {
            $dt.removeClass("is-opened").next().slideUp();
            $tab.scrollFit(option);
        } else {
            $dt.addClass("is-opened")
				.next().slideDown()
				.find("a.close").click(function () {
				    $dt.removeClass("is-opened").next().slideUp();
				    $tab.scrollFit(option);
				});

            $tab.scrollFit(option);

        }
    });

    slider.getMoveableList().each(function () {
        var $item = $(this);
        $item.find("#btn_membership_detail").href().live("click", function () {
            var $template = slider.getTemplate($item);
            /* 이부분에서 ajax 요청등을 호출 */
            slider.showElement($item, $template, {
                close: ".slideClose"
            });
        });

        $item.find("#btn_discount_detail").href().live("click", function () {
            var $template = slider.getTemplate($item);
            /* 이부분에서 ajax 요청등을 호출 */
            slider.showElement($item, $template, {
                close: ".slideClose"
            });

        });

        $item.find("#btn_qna").href().live("click", function () {
            var loginflag = document.getElementById("LoginType").value;
            if (loginflag == "N") {
                alert("로그인을 먼저해주세요.");
                slider.showLogin(this);
            }
            else {
                var username = document.getElementById("MegaBoxUserName").value;
                document.getElementById("customerqnatype").value = "1";
                document.getElementById("customerqnatitle").src = "/Images/customer/tit_qna.gif";
                var selectstring = "<select style='width:102px;' id='favTheaterGroup1' name='favTheaterGroup1' title='지역' onchange='selectedTheater1();'>";
                selectstring = selectstring + "	<option value=''>지역선택</option>";
                selectstring = selectstring + "	<option value='10'>서울</option>";
                selectstring = selectstring + "	<option value='35'>인천/경기</option>";
                selectstring = selectstring + "	<option value='45'>대전/충청</option>";
                selectstring = selectstring + "	<option value='55'>부산/대구/경상</option>";
                selectstring = selectstring + "	<option value='65'>광주/전라</option>";
                selectstring = selectstring + "	<option value='70'>강원</option>";
                selectstring = selectstring + "	<option value='80'>제주</option>";
                selectstring = selectstring + "</select>";
                selectstring = selectstring + "<select title='영화관' style='width:102px;' id='favTheater1' name='favTheater1'>";
                selectstring = selectstring + "	<option value=''>영화관선택</option>";
                selectstring = selectstring + "</select>";

                var strcustomerqna = "<table class='bbsWriteA'>";
                strcustomerqna = strcustomerqna + "	<caption>문의등록</caption>";
                strcustomerqna = strcustomerqna + "	<colgroup>";
                strcustomerqna = strcustomerqna + "		<col width='43' /><col />";
                strcustomerqna = strcustomerqna + "	</colgroup>";
                strcustomerqna = strcustomerqna + "	<tbody>";
                strcustomerqna = strcustomerqna + "	<tr>";
                strcustomerqna = strcustomerqna + "		<th scope='row'><img src='/Images/bbs/th_name02.gif' alt='성   명' /></th>";
                strcustomerqna = strcustomerqna + "		<td><input type='text' class='inputTxt' style='width:218px;' id='customerqnausername' name='customerqnausername' value='" + username + "'/></td>";
                strcustomerqna = strcustomerqna + "</tr> ";
                strcustomerqna = strcustomerqna + "	<tr>";
                strcustomerqna = strcustomerqna + "		<th scope='row'><img src='/Images/bbs/th_theater.gif' alt='영화관' /></th>";
                strcustomerqna = strcustomerqna + "		<td>";
                strcustomerqna = strcustomerqna + selectstring;
                strcustomerqna = strcustomerqna + "		</td>";
                strcustomerqna = strcustomerqna + "	</tr>";
                strcustomerqna = strcustomerqna + "	<tr>";
                strcustomerqna = strcustomerqna + "		<th scope='row'><img src='/Images/bbs/th_phone01.gif' alt='연락처' /></th>";
                strcustomerqna = strcustomerqna + "		<td>";
                strcustomerqna = strcustomerqna + "			<input type='text' class='inputTxt' style='width:218px;' id='customerqnausertel' name='customerqnausertel'/>";
                strcustomerqna = strcustomerqna + "		</td>";
                strcustomerqna = strcustomerqna + "	</tr>";
                strcustomerqna = strcustomerqna + "	<tr>";
                strcustomerqna = strcustomerqna + "		<th scope='row'><img src='/Images/bbs/th_email.gif' alt='이메일' /></th>";
                strcustomerqna = strcustomerqna + "		<td>	";
                strcustomerqna = strcustomerqna + "			<input type='text' class='inputTxt' style='width:218px;' id='customerqnauseremail' name='customerqnauseremail'/></td>";
                strcustomerqna = strcustomerqna + "	</tr>";
                strcustomerqna = strcustomerqna + "	<tr>";
                strcustomerqna = strcustomerqna + "		<th scope='row'><img src='/Images/bbs/th_subject01.gif' alt='제   목' /></th>";
                strcustomerqna = strcustomerqna + "		<td class='tit'><input type='text' class='inputTxt' style='width:218px;'  id='customerqnasubject' name='customerqnasubject'/></td>";
                strcustomerqna = strcustomerqna + "	</tr>";
                strcustomerqna = strcustomerqna + "	<tr>";
                strcustomerqna = strcustomerqna + "		<td colspan='2' class='edit'>";
                strcustomerqna = strcustomerqna + "			<textarea class='scroll' id='customerqnacontent' name='customerqnacontent' style='height:100px'></textarea>";
                strcustomerqna = strcustomerqna + "		</td>";
                strcustomerqna = strcustomerqna + "	</tr>";
                strcustomerqna = strcustomerqna + "	</tbody>";
                strcustomerqna = strcustomerqna + "	</table>";

                var $template = slider.getTemplate($item, 1);
                $template.find("#discustomerqna").html(strcustomerqna);

                slider.showElement($item, $template, {
                    close: ".slideClose"
                });
            }
            /*

            slider.showElement($item, $template, {
            close: ".slideClose",
            preprocess: function () {
            // 스크롤이 필요한 경우

            $(".scrollWrap", $template).each(function (i) {
            $(this).tinyscrollbar({
            sizethumb: 40,
            usedisable: true
            });
            });
            }
            });
            */
        });


        $item.find("#btn_qna2").href().live("click", function () {

            document.getElementById("customerqnatype").value = "2";
            document.getElementById("customerqnatitle").src = "/Images/customer/tit_group_qna.gif";
            var selectstring = "<select style='width:102px;' id='favTheaterGroup1' name='favTheaterGroup1' title='지역' onchange='selectedTheater1();'>";
            selectstring = selectstring + "	<option value=''>지역선택</option>";
            selectstring = selectstring + "	<option value='10'>서울</option>";
            selectstring = selectstring + "	<option value='35'>인천/경기</option>";
            selectstring = selectstring + "	<option value='45'>대전/충청</option>";
            selectstring = selectstring + "	<option value='55'>부산/대구/경상</option>";
            selectstring = selectstring + "	<option value='65'>광주/전라</option>";
            selectstring = selectstring + "	<option value='70'>강원</option>";
            selectstring = selectstring + "	<option value='80'>제주</option>";
            selectstring = selectstring + "</select>";
            selectstring = selectstring + "<select title='영화관' style='width:102px;' id='favTheater1' name='favTheater1'>";
            selectstring = selectstring + "	<option value=''>영화관선택</option>";
            selectstring = selectstring + "</select>";

            var strcustomerqna = "<table class='bbsWriteA'>";
            strcustomerqna = strcustomerqna + "	<caption>문의등록</caption>";
            strcustomerqna = strcustomerqna + "	<colgroup>";
            strcustomerqna = strcustomerqna + "		<col width='43' /><col />";
            strcustomerqna = strcustomerqna + "	</colgroup>";
            strcustomerqna = strcustomerqna + "	<tbody>";
            strcustomerqna = strcustomerqna + "	<tr>";
            strcustomerqna = strcustomerqna + "		<th scope='row'><img src='/Images/bbs/th_name02.gif' alt='성   명' /></th>";
            strcustomerqna = strcustomerqna + "		<td><input type='text' class='inputTxt' style='width:218px;' id='customerqnausername' name='customerqnausername'/></td>";
            strcustomerqna = strcustomerqna + "</tr> ";
            strcustomerqna = strcustomerqna + "	<tr>";
            strcustomerqna = strcustomerqna + "		<th scope='row'><img src='/Images/bbs/th_theater.gif' alt='영화관' /></th>";
            strcustomerqna = strcustomerqna + "		<td>";
            strcustomerqna = strcustomerqna + selectstring;
            strcustomerqna = strcustomerqna + "		</td>";
            strcustomerqna = strcustomerqna + "	</tr>";
            strcustomerqna = strcustomerqna + "	<tr>";
            strcustomerqna = strcustomerqna + "		<th scope='row'><img src='/Images/bbs/th_phone01.gif' alt='연락처' /></th>";
            strcustomerqna = strcustomerqna + "		<td>";
            strcustomerqna = strcustomerqna + "			<input type='text' class='inputTxt' style='width:218px;' id='customerqnausertel' name='customerqnausertel'/>";
            strcustomerqna = strcustomerqna + "		</td>";
            strcustomerqna = strcustomerqna + "	</tr>";
            strcustomerqna = strcustomerqna + "	<tr>";
            strcustomerqna = strcustomerqna + "		<th scope='row'><img src='/Images/bbs/th_email.gif' alt='이메일' /></th>";
            strcustomerqna = strcustomerqna + "		<td>	";
            strcustomerqna = strcustomerqna + "			<input type='text' class='inputTxt' style='width:218px;' id='customerqnauseremail' name='customerqnauseremail'/></td>";
            strcustomerqna = strcustomerqna + "	</tr>";
            strcustomerqna = strcustomerqna + "	<tr>";
            strcustomerqna = strcustomerqna + "		<th scope='row'><img src='/Images/bbs/th_subject01.gif' alt='제   목' /></th>";
            strcustomerqna = strcustomerqna + "		<td class='tit'><input type='text' class='inputTxt' style='width:218px;'  id='customerqnasubject' name='customerqnasubject'/></td>";
            strcustomerqna = strcustomerqna + "	</tr>";
            strcustomerqna = strcustomerqna + "	<tr>";
            strcustomerqna = strcustomerqna + "		<td colspan='2' class='edit'>";
            strcustomerqna = strcustomerqna + "			<textarea class='scroll' id='customerqnacontent' name='customerqnacontent' style='height:100px'></textarea>";
            strcustomerqna = strcustomerqna + "		</td>";
            strcustomerqna = strcustomerqna + "	</tr>";
            strcustomerqna = strcustomerqna + "	</tbody>";
            strcustomerqna = strcustomerqna + "	</table>";
            strcustomerqna = strcustomerqna + "		<fieldset class='customerScroll'>";
            strcustomerqna = strcustomerqna + "			<legend>이용약관 동의</legend>";
            strcustomerqna = strcustomerqna + "			<textarea style='width:260px;height:100px'>개인정보 수집에 대한 동의\n\n";
            strcustomerqna = strcustomerqna + "원활한 고객상담, 각종 서비스의 제공을 \n";
            strcustomerqna = strcustomerqna + "위해 아래와 같은 개인정보를 수집하고 \n";
            strcustomerqna = strcustomerqna + "있습니다.\n\n";
            strcustomerqna = strcustomerqna + "- 이름, 이메일주소, 연락처\n\n";
            strcustomerqna = strcustomerqna + "개인 정보의 보유, 이용기간, 파기절차\n";
            strcustomerqna = strcustomerqna + "원칙적으로 개인정보 수집 및 이용목적이 \n";
            strcustomerqna = strcustomerqna + "달성된 후에는 해당 정보를 지체없이\n";
            strcustomerqna = strcustomerqna + "파기합니다.\n\n";
            strcustomerqna = strcustomerqna + "다만, 전자상거래등에서의 소비자보호에\n";
            strcustomerqna = strcustomerqna + "관한 법률등 관계 법률에 의해 보존할 \n";
            strcustomerqna = strcustomerqna + "필요가 있는 경우에는 일정기간 보존한 후 \n";
            strcustomerqna = strcustomerqna + "파기합니다.\n</textarea>";
            strcustomerqna = strcustomerqna + "			<p class='mgb10'>개인정보 수집에 대해 동의하십니까?</p>";
            strcustomerqna = strcustomerqna + "			<p class='radio'>";
            strcustomerqna = strcustomerqna + "				<label for='agree' class='on mgr40'><input type='radio' id='agree' name='agreement' />동의합니다.</label>";
            strcustomerqna = strcustomerqna + "				<label for='notagree'><input type='radio' id='notagree' name='agreement' />동의하지 않습니다.</label>";
            strcustomerqna = strcustomerqna + "			</p>";
            strcustomerqna = strcustomerqna + "		</fieldset>";

            var $template = slider.getTemplate($item, 1);
            $template.find("#discustomerqna").html(strcustomerqna);

            slider.showElement($item, $template, {
                close: ".slideClose"
            });
        });

        $item.find("#btn_org_qna").href().live("click", function () {
            var $template = slider.getTemplate($item, 2);
            /* 이부분에서 ajax 요청등을 호출 */
            slider.showElement($item, $template, {
                close: ".slideClose",
                preprocess: function () {
                    // 스크롤이 필요한 경우
                    $(".scrollWrap", $template).each(function (i) {
                        $(this).tinyscrollbar({
                            sizethumb: 40,
                            usedisable: true
                        });
                    });
                }
            });

        });
        /*
        $item.find("dl.qnaList").children().each(function () {
        var $dt = $(this);
        if ($dt.is("dt")) {
        $dt.toggle(function () {
        $dt.next().slideDown("fast", function () {
        $item.scrollFit();
        })
        .find("a.close").live("click", function () {
        $dt.next().slideUp("fast", function () {
        $item.scrollFit();
        });
        });

        }, function () {
        $dt.next().slideUp("fast", function () {
        $item.scrollFit();
        });
        });
        }
        });
        */
        $item.find("ul.newsList li a").live("click", function () {
            document.getElementById('spanNoticeDetail').innerHTML = "";
            var noticeid = $(this).attr("href");
            var anoticeid = noticeid.split("#");
            noticeid = anoticeid[1];
            var pars = "NOTICEID=" + noticeid;
            var url = "/Customer/ajaxNoticeDetail.aspx";          // URL
            $.ajax({
                type: "post",
                url: url,
                data: pars,
                success: function (msg) {
                    var $template = slider.getTemplate($item);
                    $template.find("#spanNoticeDetail").html(msg);
                    slider.showElement($item, $template, {
                        close: ".slideClose"
                    });
                }
            });
        });
    });

    // 11-12 추가
    //	M0_customer_membership.html
    $("#btn_membership_tab a").live("click", function () {
        $(".membership-tab:visible").scrollFit();
    });


    // M0_mypage_all.html
    slider.getMoveableList().each(function (i) {
        var $item = $(this);

        // 우편 번호 찾기 내에 스크롤 처리 작업
        $item.find("#btn_zipcode").live("click", function () {
            var $template = slider.getTemplate($item, "2");
            slider.showElement($item, $template, {
                close: ".btClose"
            });
            setTimeout(function () {
                $item.triggerHandler("closeElement");
            }, 400);
        });


        // 회원가입팝업
        $item.find("#btn_apply").live("click", function () {
            //var $template = slider.getTemplate($item, "1");
            var $template = slider.getTemplate($item);
            var agrretype = document.getElementById("APPLYTYPE").value;
            if (agrretype == "1" || agrretype == "2") {
                $template.find(".pScrollWrap1").each(function (i) {
                    $(this).tinyscrollbar({
                        sizethumb: 40,
                        usedisable: true
                    });
                });
            }
            else {
                alert("실명인증을 먼저 해주세요.");
                return;
            }
            slider.showElement($item, $template, {
                close: ".btClose"
            });
        });


        $item.find("#btn_card_cashbag_regist").href().live("click", function () {
            var pars = "";
            var url = "/MyPage/ajaxMemberCardList.aspx";
            $.ajax({
                type: "post",
                url: url,
                data: pars,
                success: function (msg) {
                    var $template = slider.getTemplate($item);
                    $template.find("#membercardlist").html(msg);
                    slider.showElement($item, $template, {
                        //close: ".slideClose"
                        close: ".fr"
                    });
                }
            });
        });

        $item.find("#btn_movie_lib").href().live("click", function () {
            var $template = slider.getTemplate($item, "2");

            slider.showElement($item, $template, {
                close: ".memClose"
            });
        });



        $item.find("#btn_caution_detail").href().live("click", function () {
            var $template = slider.getTemplate($item, "1");

            slider.showElement($item, $template, {
                close: ".fr"
            });
        });

        if (i == 2) {
            $item.find(".bbsListB tr a").href()
			.live("click", function () {

			    var eventid = $(this).attr("href");
			    var aeventid = eventid.split("#");
			    eventid = aeventid[1];

			    /*2012 VIP 상세내용 보여주기*/
			    if (eventid.substring(0, 1) == "V") {

			        eventid = eventid.substring(1, eventid.length);
			        var pars = "RECNO=" + eventid;
			        var url = "/MyPage/ajaxVIPInquiryDetail.aspx";          // URL
			        $.ajax({
			            type: "post",
			            url: url,
			            data: pars,
			            success: function (msg) {
			                var $template = slider.getTemplate($item);
			                $template.find("#spanInquiryDetail").html(msg);
			                slider.showElement($item, $template, {
			                    close: ".fr"
			                });
			            }
			        });
			    }
			    else {
			        var pars = "INQUIRYID=" + eventid;

			        var url = "/MyPage/ajaxInquiryDetail.aspx";          // URL
			        $.ajax({
			            type: "post",
			            url: url,
			            data: pars,
			            success: function (msg) {
			                var $template = slider.getTemplate($item);
			                $template.find("#spanInquiryDetail").html(msg);
			                slider.showElement($item, $template, {
			                    close: ".fr"
			                });
			            }
			        });
			    }
			});
        }
    });

    // M0_megabox_02.html
    // 입사지원 접수 첨부파일 찾아보기 버튼 처리
    $("#btn_file").href()
	.live("click", function () {
	    var $btnParent = $(this).parent();
	    var $file = $btnParent.find(":file");

	    var nameBind = function (fileText) {
	        var fileName = fileText.substr(fileText.lastIndexOf("\\") + 1);
	        $btnParent.find("input:text").val(fileName);
	    };

	    $file.click();

	    if (!!$.browser.msie) {
	        nameBind($file.val());
	    } else {
	        $file.change(function () {
	            nameBind($file.val());
	        });
	    }
	});

    slider.getMoveableList().each(function (i) {
        var $item = $(this);

        $item.find("#btn_confirm").click(function () {
            var $template = slider.getTemplate($item, "1");

            slider.showElement($item, $template, {
                close: ".slideClose"
            });
        });

        $item.find("ul.recruitList").each(function () {
            $(this).find("li a").href().live("click", function () {
                var employmentnoticeid = $(this).attr("href");
                var aemploymentnoticeid = employmentnoticeid.split("#");
                employmentnoticeid = aemploymentnoticeid[1];
                var pars = "EMPLOYMENTNOTICEID=" + employmentnoticeid;
                var url = "/Company/ajaxEmployDetail.aspx";
                $.ajax({
                    type: "post",
                    url: url,
                    data: pars,
                    success: function (msg) {
                        var $template = slider.getTemplate($item);
                        $template.find("#sapnEmployDetailInfo").html(msg);
                        slider.showElement($item, $template, {
                            close: ".slideClose"
                        });
                    }
                });

            });
        });

        $item.find("#btn_partner").live("click", function () {
            var $template = slider.getTemplate($item, "3");

            slider.showElement($item, $template, {
                close: ".slideClose"
            });
        });

        $item.find("#btn_accept").href()
		.live("click", function () {

		    var loginflag = document.getElementById("LoginType").value;
		    if (loginflag == "N") {
		        alert("로그인을 먼저해주세요.");
		    }
		    else {
		        var $template = slider.getTemplate($item, "4");
		        var selectstring = "<select style='width:102px;' id='favTheaterGroup' name='favTheaterGroup' title='지역' onchange='selectedTheater();'>";
		        selectstring = selectstring + "	<option value=''>지역선택</option>";
		        selectstring = selectstring + "	<option value='10'>서울</option>";
		        selectstring = selectstring + "	<option value='35'>인천/경기</option>";
		        selectstring = selectstring + "	<option value='45'>대전/충청</option>";
		        selectstring = selectstring + "	<option value='55'>부산/대구/경상</option>";
		        selectstring = selectstring + "	<option value='65'>광주/전라</option>";
		        selectstring = selectstring + "	<option value='70'>강원</option>";
		        selectstring = selectstring + "	<option value='80'>제주</option>";
		        selectstring = selectstring + "</select>";
		        selectstring = selectstring + "<select title='영화관' style='width:102px;' id='favTheater' name='favTheater'>";
		        selectstring = selectstring + "	<option value=''>영화관선택</option>";
		        selectstring = selectstring + "</select>";
		        $template.find("#spanincruitselectboxinfo").html(selectstring);

		        slider.showElement($item, $template, {
		            close: ".slideClose"
		        });
		    }
		});

    });

    // main.html
    slider.children(".fixed:visible").each(function (i) {
        var $item = $(this);
        $item.find(".btn_movie_detail").each(function () {
            $(this).click(function () {
                document.getElementById('spanMovieIndexDetail').innerHTML = "";
                var moviecode = $(this).attr("href");
                var amoviecode = moviecode.split("#");
                moviecode = amoviecode[1];
                var pars = "MOVIECODE=" + moviecode;

                var url = "/Movie/ajaxMovieDetail.aspx";          // URL
                $.ajax({
                    type: "post",
                    url: url,
                    data: pars,
                    success: function (msg) {
                        var $template = slider.getTemplate($item);
                        $template.find("#spanMovieIndexDetail").html(msg);
                        slider.showElement($item, $template, {
                            close: ".memClose"
                        });
                    }
                });

                return false;
            });
        });
    });

    // layout_total.html
    $("#header .btn_full_banner")
	.href().live("click", function () {
	    $(".megaboxOpen").slideDown("fast", function () {
	        var $item = $(this);
	        $item.find("a.openClose").bind("click", function () {
	            $item.slideUp("fast");
	            $item.unbind("click");
	        });
	    });
	});

    $("#header #btn_ticket_reserve").href()
	.click(function () {
	    var $item = $(this);
	    var pars = "";
	    var url = "/Member/Login/ajaxLoginCheck.aspx";
	    $.ajax({
	        type: "post",
	        url: url,
	        data: pars,
	        success: function (msg) {
	            var serverData = msg;
	            var evalData = eval("(" + serverData + ")");
	            try {
	                if (evalData.result == "0000") {
	                    var rvalue = evalData.data[0].value;
	                    if (rvalue == "Y") {
	                        window.location.href = "/MyPage/default.aspx";
	                    }
	                    else if (rvalue == "A") {
	                        window.location.href = "/MyPage/ReservationList.aspx";
	                    }
	                    else {
	                        alert("로그인을 먼저해주세요.");
	                        slider.showLoginNonMember($item);
	                    }
	                }
	                else {
	                    /*로그인 실패!!*/
	                    alert("로그인을 먼저해주세요.");
	                    slider.showLoginNonMember($item);
	                }
	            } catch (err) {
	                alert("로그인을 먼저해주세요.");
	                slider.showLoginNonMember($item);

	            }
	            finally {
	            }

	        }
	    });

	});

    $("#header .btnGuide")
	.href().live("click", function () {
	    $("#userGuide").slideDown("500", function () {
	        var $item = $(this);
	        $item.find(".btnClose").bind("click", function () {
	            $item.slideUp("500");
	            $item.unbind("click");
	        });
	    });
	});

    $("#header #btn_reservation_check").href()
	.click(function () {
	    var $item = $(this);
	    slider.showLoginNonMember2($item);
	});


    // 좌석수 레이어
    $("dd.timeList").seatLayer({});


    // M0_join.html
    slider.getMoveableList().each(function (i, item) {
        var $item = $(item);

        $item.find("#btn_normal").click(function () {
            slider.slideSection($item, true);
            return false;
        });

        $item.find("#btn_junior").click(function () {
            slider.slideSection($item, true);
            return false;
        });

        $item.find("#btn_foreigner").click(function () {
            slider.slideSection($item, true);
            return false;
        });

        $item.find("#btn_agreement_ok").click(function () {
            slider.slideSection($item, true);
            return false;
        });

        $item.find("#btn_agreement_cancel").click(function () {
            slider.slideSection($item, false);
            return false;
        });

        $item.find("#btn_information_ok").click(function () {
            slider.slideSection($item, true);
            return false;
        });

        $item.find("#btn_information_cancel").click(function () {
            slider.slideSection($item, false);
            return false;
        });

        $item.find("#btn_edit_agreement_ok").click(function () {
            slider.slideSection($item, true);
            return false;
        });

        $item.find("#btn_edit_information_ok").click(function () {
            slider.slideSection($item, true);
            return false;
        });

        $item.find("#btn_edit_information_cancel").click(function () {
            slider.slideSection($item, false);
            return false;
        });

    });

    // theater/M2_theater.html
    // first Club
    slider.getMoveableList().each(function () {
        var $item = $(this);
        $item.find("#btn_first_club")
		.href().click(function () {
		    var $template = slider.getTemplate($item, 1);
		    slider.showElement($item, $template, {
		        close: ".slideClose"
		    });
		});
    });

    // Zam
    slider.getMoveableList().each(function () {
        var $item = $(this);
        $item.find("#btn_zam")
		.href().click(function () {
		    var $template = slider.getTemplate($item, 2);
		    slider.showElement($item, $template, {
		        close: ".slideClose"
		    });
		});
    });

    // sw_renewal
    slider.getMoveableList().each(function () {
        var $item = $(this);
        $item.find("#btn_sw_renewal")
		    .href().click(function () {
		        var $template = slider.getTemplate($item, 3);
		        slider.showElement($item, $template, {
		            close: ".slideClose"
		        });
		    });
    });

    // M1_megabox_nart.html
    //	$("ul.nartList li").each(function(){
    //		$(this).click(function(){
    //			var $item = $("div.moving-nart-owner:visible");
    //			var $template = slider.getTemplate($item);
    //			slider.showElement($item, $template, {});
    //		});
    //	});
    //	
    //	if($("div.moving-nart-owner:visible").length > 0){
    //		var $item = $("div.moving-nart-owner:visible");
    //		var $template = slider.getTemplate($item);
    //		slider.showElement($item, $template, {});		
    //	}

    // 확장시 보여짐 처리를 위해서 존재
    var currentLocation = location.href;
    var parameterName = "openedPage=";
    var eventid
    var openParameterIndex = currentLocation.indexOf(parameterName);
    if (openParameterIndex > -1) {
        var fromParameter = currentLocation.substr(openParameterIndex);
        var parameters = fromParameter.split("&");
        var value = "";
        for (var i = 0; i < parameters.length; i++) {
            if (parameters[i].indexOf(parameterName) > -1) {
                value = parameters[i].split("=")[1];
                break;
            }
        }


        if (value == ".is_event") {
            var aeventid = parameters[1].split("=");
            var eventid = aeventid[1];
            eventid = eventid.replace('#', '');
            var pars = "EVENTID=" + eventid;
            var url = "/Event/ajaxEventDetail.aspx";          // URL
            $.ajax({
                type: "post",
                url: url,
                data: pars,
                success: function (msg) {

                    currentid = "MegaEventDetail01";

                    setTimeout(function () {
                        slider.getMoveableList().each(function (i, item) {
                            var $item = $(item);
                            if ($item.is(value) || $item.find(value).length > 0) {
                                var $template = slider.getTemplate($item);
                                $template.find("#MegaEventDetail01").html(msg);
                                $template.find("#MegaEventDetail02").html("");
                                $template.find("#MegaEventDetail03").html("");
                                slider.showElement($item, $template, {
                                    close: ".slideClose"
                                });
                                return false;
                            }
                        });
                    }, 200);
                }
            });
        }
        else if (value == ".movie_event") {
            var aeventid = parameters[1].split("=");
            var eventid = aeventid[1];
            eventid = eventid.replace('#', '');
            var pars = "EVENTID=" + eventid;
            var url = "/Event/ajaxEventDetail.aspx";          // URL
            $.ajax({
                type: "post",
                url: url,
                data: pars,
                success: function (msg) {

                    currentid = "MegaEventDetail02";

                    setTimeout(function () {
                        slider.getMoveableList().each(function (i, item) {
                            var $item = $(item);
                            if ($item.is(value) || $item.find(value).length > 0) {
                                var $template = slider.getTemplate($item);
                                $template.find("#MegaEventDetail01").html("");
                                $template.find("#MegaEventDetail02").html(msg);
                                $template.find("#MegaEventDetail03").html("");
                                slider.showElement($item, $template, {
                                    close: ".slideClose"
                                });
                                return false;
                            }
                        });
                    }, 200);
                }
            });
        }
        else if (value == ".branch_event") {
            var aeventid = parameters[1].split("=");
            var eventid = aeventid[1];
            eventid = eventid.replace('#', '');
            var pars = "EVENTID=" + eventid;
            var url = "/Event/ajaxEventDetail.aspx";          // URL
            $.ajax({
                type: "post",
                url: url,
                data: pars,
                success: function (msg) {
                    currentid = "MegaEventDetail03";
                    setTimeout(function () {
                        slider.getMoveableList().each(function (i, item) {
                            var $item = $(item);
                            if ($item.is(value) || $item.find(value).length > 0) {
                                var $template = slider.getTemplate($item);
                                $template.find("#MegaEventDetail01").html("");
                                $template.find("#MegaEventDetail02").html("");
                                $template.find("#MegaEventDetail03").html(msg);
                                slider.showElement($item, $template, {
                                    close: ".slideClose"
                                });
                                return false;
                            }
                        });
                    }, 200);
                }
            });
        }
        else {
            setTimeout(function () {
                slider.getMoveableList().each(function (i, item) {
                    var $item = $(item);
                    if ($item.is(value) || $item.find(value).length > 0) {
                        var $template = slider.getTemplate($item);
                        slider.showElement($item, $template, {
                            close: ".slideClose"
                        });
                        return false;
                    }
                });
            }, 200);

        }
    }


    // 확장시 보여짐 처리를 위해서 존재
    var currentLocation1 = location.href;
    var parameterName1 = "openedPage1=";
    var openParameterIndex1 = currentLocation1.indexOf(parameterName1);
    if (openParameterIndex1 > -1) {
        var fromParameter = currentLocation1.substr(openParameterIndex1);
        var parameters = fromParameter.split("&");
        var value = "";
        for (var i = 0; i < parameters.length; i++) {
            if (parameters[i].indexOf(parameterName1) > -1) {
                value = parameters[i].split("=")[1];
                break;
            }
        }

        setTimeout(function () {
            slider.getMoveableList().each(function (i, item) {
                var $item = $(item);
                if ($item.is(value) || $item.find(value).length > 0) {
                    var $template = slider.getTemplate($item, 3);
                    slider.showElement($item, $template, {
                        close: ".slideClose"
                    });
                    return false;
                }
            });
        }, 200);
    }


    // M4_storybox_all.html
    // 스코어를 맞춰라 참여하기 버튼 클릭시 왼쪽 확장
    $("#target_first_tab").each(function () {
        var $item = $(this);

        $(".btnAdd").each(function () {
            $(this).click(function () {
                var $template = slider.getTemplate($item);
                slider.showElement($item, $template, { close: ".slideCloseA" });
            });
        });

        $(".btn_score_movie_title").live("click", function (event) {
            var $template = slider.getTemplate($item);
            slider.showElement($item, $template, { close: ".slideCloseA" });
        });
        /*
        $("#btn_first_subtab").find("a")
        .click(function () {
        $("#target_first_tab").scrollFit();
        });
        */
    });

    $("#target_second_tab").each(function () {
        var $item = $(this);
        // 사소한 궁금증 결과보기 눌렀을 경우 노출/close
        $("#btn_view_result")
		.click(function () {

		    $item.find("div.sCuriosity").hide();
		    $item.find("div.sResultView:eq(0)")
			.show().find(".slideClose").href().click(function () {
			    $item.find("div.sCuriosity").show();
			    $item.find("div.sResultView:eq(0)").hide();
			    $item.data("section_wheel").update();
			});

		    $item.data("section_wheel").update();

		});
        // 사소한 궁금증 지난목록더보기 클릭시 왼쪽 확장
        $("#btn_list_more").href()
		.click(function () {
		    var $template = slider.getTemplate($item);
		    slider.showElement($item, $template, { close: ".slideClose" });
		});
    });

    // 평점 포스터or영화제목 클릭시 왼쪽 확장
    $("#target_third_tab").each(function () {
        var $item = $(this);
        $(this).find(".btn_movie_poster , .btn_movie_title").href().click(function () {
            var $template = slider.getTemplate($item);
            slider.showElement($item, $template, { close: ".slideClose" });

            // 평점등록 textarea영역 클릭시 텍스트 사라지는 효과)
            $template.find(".txt_comment").click(function () {
                $(this).hide();
            });
        });
    });

    $("#theater-timelist ul.tab").find("a").click(function () {
        $("#theater-timelist").scrollFit();
    });



    /* 이미지 갤러리 */
    //	$(".pageScrollWrap a[rel=example_group]").fancybox();
    // 사용지 css , js 추가 해야함니다.

});

