/**
 * OpenNTV 플레이어 태그 생성 스크립트.
 * 필수 스크립트
 *      - html_object.js
 *      - /exjs/hosts/
 *
 * @author  himinseop
 * @date    2009-07-29
 */
var NTV = function() {};
NTV.prototype = {
     video_id : '',
        width : '640',
       height : '480',
         skin : 'default',
     autoplay : 'true', // flashVars 에 포함된다.
        ratio : 'Y', // 화면비율 유지 = Y | 화면채우기 = N
       volume : '70',
    container : '',
       serial : '',

    setOption : function(video_id, options) {
        options = options || {};
        for (var property in options) {
            this[property] = options[property];
        }
        this.video_id = video_id;
    },

    printObject : function() {
        var obj = new htmlObject(HOST_WWW + '/video/player/' + this.video_id + '/' + this.skin + '/' + this.serial, this.video_id, this.width, this.height);
            obj.setParam('wmode', 'transparent');
            obj.setParam('quality', 'high');
            obj.setParam('allowScriptAccess', 'always');
            obj.setParam('allowNetworking', 'all');
            obj.setParam('allowFullScreen', 'true');
            obj.setParam('flashVars', 'ratio=' + this.ratio + '&volume=' + this.volume + '&autoplay=' + this.autoplay);
            obj.write(this.container);
    }
};

var NTVPlayer = function(video_id, options) {
    var n = new NTV();
        n.setOption(video_id, options);
        // set Window size for Skin
        if (n.skin == 'default') {
            n.height = Number(n.height) + 31;
            n.printObject();
        } else if (n.skin == 'custom') {
            var play_host_options = {
                url:'/member/get_custom_player_type/',
                type:'POST',
                data:'jsondata=' + $.toJSON({video_id:video_id}),
                complete:function(res) {
                    var r = $.parseJSON(res.responseText, true);
                    if (r.TYPE != 'nude') {
                        n.height = Number(n.height) + 33;
                    }
                    n.printObject();
                }
            }
            $.ajax(play_host_options);
        } else {
            n.printObject();
        }
};

var NTVPlayerPopup = function(video_id, options) {
    
    // set Window size for Skin
    if (options.skin == 'default') {
        options.height = Number(options.height) + 31;
        NTVPlayerPopupOpenWindow(video_id, options);
    } else if (options.skin == 'custom') {
        var play_host_options = {
            url:'/member/get_custom_player_type/',
            type:'POST',
            data:'jsondata=' + $.toJSON({video_id:video_id}),
            complete:function(res) {
                var r = $.parseJSON(res.responseText, true);
                if (r.TYPE != 'nude') {
                    options.height = Number(options.height) + 33;
                }
                NTVPlayerPopupOpenWindow(video_id, options);
            }
        }
        $.ajax(play_host_options);
    } else {
        NTVPlayerPopupOpenWindow(video_id, options);
    }
}

var NTVPlayerPopupOpenWindow = function(video_id, options) {
    var n = new NTV();
        n.setOption(video_id, options);
	if (n.insite == 'Y') {
		window.open(HOST_WWW + '/video/preview?video_id=' + video_id + '&skin=' + n.skin, 'ID', 'width=' + n.width + ',outerwidth=' + n.width + ',outerheight=' + n.height + ',height=' + n.height);
	} else {
	    window.open(HOST_WWW + '/video/custom_view?video_id=' + video_id + '&skin=' + n.skin, 'ID', 'width=' + n.width + ',outerwidth=' + n.width + ',outerheight=' + n.height + ',height=' + n.height);
	}
};

var NTVEncodeState = function(video_id) {
    var obj = new htmlObject('/flash/Encode_state.swf', 'EncodeState' + video_id, '98', '73');
        obj.setParam('wmode', 'transparent');
        obj.setParam('quality', 'high');
        obj.setParam('allowScriptAccess', 'always');
        obj.setParam('flashVars', 'host=' + HOST_ID + '&video_id=' + video_id);
        obj.write();
}

var NTVPlayerPopupAdmin = function(video_id, options) {
    
	options.height = Number(options.height) + 31;

	var n = new NTV();
	n.setOption(video_id, options);
	window.open('/video/preview?video_id=' + video_id + '&skin=' + n.skin, 'ID', 'width=' + n.width + ',outerwidth=' + n.width + ',outerheight=' + n.height + ',height=' + n.height);
 }
