/**
 * HTML Object
 * Flash(swf) 출력을 위한 object 코드를 반환한다.
 * 필수 스크립트
 *      - openntv.js
 *      - jquery.js
 *      - /exjs/hosts/
 *
 * @Author  himinseop
 */

script_include('hosts');

var htmlObject = function(movie, id, width, height) {
    this.id = id;
    this.width = width;
    this.height = height;
    this.params = new Array();

    // 플레이어의 경우 플레이어 리다이렉션 메소드가 WWW에 있음.
    var ret = movie.match('^http://');
    if (ret == null) {
        movie = HOST_IMAGE + movie;
    }
    this.movie = movie;

};
htmlObject.prototype = {

    movie:'',
    id:'',
    width:'',
    height:'',
    params:new Array(),
    isDynamic:true, // 브라우져 특성에 따른 코드 반환여부. (true이면, object와 embed를 브라우져에 따라 구분하여 반환한다.)

    // 스크랩과 같이 정적인 코드를 반환할 때 이용
    setStatic : function() {
        this.isDynamic = false;
    },

    setParam : function(name, value) {
        this.params.push([name, value]);
    },

    toHtml : function() {
        // PARAM, EMBED 코드 생성
        var param_code = '<param name="movie" value="' + this.movie + "\" />\n";
        var embed_code = '<embed '
        + 'src="' + this.movie + '" '
        + 'pluginspage="http://www.macromedia.com/go/getflashplayer" '
        + 'type="application/x-shockwave-flash" '
        + 'classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '
        + 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,16,0" '
        + 'id="' + this.id + '" width="' + this.width + '" height="' + this.height + '" ';

        if (this.params.length > 0) {
            for (var property in this.params) {
                param_code += '<param name="' + this.params[property][0] + '" value="' + this.params[property][1] + "\" />\n";
                embed_code += this.params[property][0] + '="' + this.params[property][1] + '" ';
            }
        }
        embed_code += " />\n";

        if (this.isDynamic == true) {
            if ("\v"=='v') { // if IE
                var html = '<object '
                    + 'classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '
                    + 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,16,0" '
                    + 'width="' + this.width + '" height="' + this.height + '" id="' + this.id + "\" >\n"
                + param_code
                + '</object>';
            } else {
                var html = embed_code;
            }
        } else {
            var html = '<object '
                + 'classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '
                + 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,16,0" '
                + 'width="' + this.width + '" height="' + this.height + '" id="' + this.id + "\" >\n"
            + param_code
            + embed_code
            + '</object>';
        }
        return html;
    },

    write : function(container) {
        var html = this.toHtml();

        if (typeof container != 'undefined' && (container !== null && container != '')) {
            $('#' + container).html(html);
        } else {
            document.write(html);
        }
    }
}
