﻿/*
*    말과 나의 이야기, 앨리샤
*    캐릭터 생성 레이어 제어 Script
*    Script by pRix, at 20091210
*/

var ACCreator =
{
    template : [
        '<table style="width:730px;height:820px;" cellspacing="0" cellpadding="0">',
        '        <tr>',
        '            <td class="character-frame-btn" colspan="3"><p onclick="ACCreator.close()"><span>닫기</span></p></td>',
        '        </tr>',
        '        <tr>',
        '            <td class="character-frame-top png24" colspan="3"></td>',
        '        </tr><tr>',
        '            <td class="character-frame-left png24"></td>',
        '            <td>',
        '                <iframe src="#src" width="630" height="715" frameborder="0" scrolling="no"></iframe>',
        '            </td>',
        '            <td class="character-frame-right png24"></td>',
        '        </tr><tr>',
        '            <td class="character-frame-btm png24" colspan="3"></td>',
        '        </tr>',
        '</table>'
    ].join(''),

    open : function(url) {
        if (window.nPopup) nPopup.close(); // nPopup 이 사용중일경우 모두 닫기
        this.append();   // html 생성
        this.contentDiv.innerHTML = this.template.replace("#src", url + "?" + Math.random());
    },

    close : function() {
        this.contentDiv.parentNode.removeChild(this.contentDiv);
		this.contentDiv = null;
        this.cloudDiv.parentNode.removeChild(this.cloudDiv);
		this.cloudDiv = null;
		Ns.Event.remove(window, 'resize', this.remove);
    },

	remove : function() {
		ACCreator.append();
	},

    append : function(is) {
        if (!this.cloudDiv) {
            this.cloudDiv = document.createElement('div');
            this.cloudDiv.className = 'character-cloud';
            document.body.appendChild(this.cloudDiv);
            this.contentDiv = document.createElement('div');
            this.contentDiv.className = 'character-field';
            document.body.appendChild(this.contentDiv);
            Ns.Event.add(window, 'resize', this.remove);
        }
        this.cloudDiv.style.width = Ns.root().scrollWidth + "px";
        this.cloudDiv.style.height = Ns.root().scrollHeight + "px";
        this.contentDiv.style.top = Math.max(50, Ns.root().scrollTop + Ns.root().clientHeight/2 - 410) + "px";
    }
};