var HOST_STATISTICS = 'http://upload.shoplive.jp/';

if (typeof HOST_STREAM == 'undefined') {
    var HOST_STREAM = 'http://stream.shoplive.jp/';
}

if (HOST_STREAM.slice(-1) != '/') {
    HOST_STREAM += '/';
}

if (typeof MTBPlayer != 'function') {
    var MTBPlayer = function(video_id, options) {
        this.options = {
          loc      : 'static',
          autoplay : false,   // or true
          skin     : 'default',
          size     : {width: 410, height: 342},
          volume   : 70,
          container: ''
        }

        // simulate Object.extend() in prototype.js
        options = options || {};
        for (var property in options) {
          this.options[property] = options[property];
        }

        if (video_id.toString().indexOf('!') != -1) {
            this.video_id = video_id.toString().substr(1);
            var url = HOST_STREAM + "tmp/" + this.video_id + "/";
        } else {
            this.video_id = video_id.toString();
            var url = HOST_STREAM + "data" + parseInt(this.video_id.slice(-2)) + '/' + ('00000' + this.video_id).slice(-5, -2) + '/' + this.video_id.slice(0, -2) + '/';
        }

        this.pid = 'mtb_v' + this.video_id;
        // for shop main player. old version.
        if (this.options.skin.indexOf('main_') >= 0) {
            var url = 'http://img.shoplive.jp/player/' + this.options.skin + '.swf' + '?r=' + Math.random()
                    + '&url=' + url
                    + '&upload=' + HOST_STATISTICS
                    + '&uid=' + this.video_id
                    + '&autoPlay=' + this.options.autoplay.toString()
                    + '&volume=' + this.options.volume.toString();
            var wmode = ['<param name="wmode" value="transparent" />', ' wmode="transparent" '];
        }
        // for brand new players.
        else {
         var url = 'http://img.shoplive.jp/player/' + this.options.skin + '.swf' + '?r=' + Math.random()
                    + '&url=' + url
                    + '&upload=' + HOST_STATISTICS
                    + '&uid=' + this.video_id
                    + '&autoPlay=' + this.options.autoplay.toString()
                    + '&volume=' + this.options.volume.toString();
            var wmode = ['<param name="wmode" value="transparent" />', ' wmode="transparent" '];
        }

        switch (this.options.skin) {
        case 'bbong':
        case 'bbong2':
        case 'pdove':
        case 'pdove2':
            this.options.size = {width: 420, height: 458};
            break;
        case 'shopdetail':
        case 'shopdetail2':
            this.options.size = {width: 410, height: 375};
            break;
        case 'default':
        case 'default2':
        case 'malltb':
        case 'malltb2':
        case 'malltb_black':
        case 'malltb_black2':
            this.options.size = {width: 410, height: 342};
            break;
        case 'detailimage':
            this.options.size = {width: 290, height: 285};
            break;
        }

        var html = 
            '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab"'
          + ' width="' + this.options.size.width + '" height="' + this.options.size.height + '"'
          + ' id="' + this.pid + '">'
          + ' <param name="allowScriptAccess" value="always" />'
          + ' <param name="allowFullScreen" value="true" />'
          + ' <param name="movie" value="' + url + '" />'
          + ' <param name="quality" value="high" />'
          + wmode[0]
          + ' <embed src="' + url + '" allowFullScreen="true" allowScriptAccess="always" type="application/x-shockwave-flash"'
          + ' width="' + this.options.size.width + '" height="' + this.options.size.height + '"'
          + ' name="' + this.pid + '" id="' + this.pid + '"'
          + wmode[1]
          + ' pluginspage="http://www.macromedia.com/go/getflashplayer"></embed></object>';

        if (this.options.container.length) {
            document.getElementById(this.options.container).innerHTML = html;
        } else {
            document.write(html);
        }

        if (navigator.appName.indexOf("Microsoft") != -1) {
            return window[this.pid]
        }
        else {
            return document[this.pid]
        }
    }

    var MTBPlayerPopup = function(video_id) {
        window.open('http://img.shoplive.jp/player/popup.html?video_id=' + video_id, '', 'width=408,height=342');
    }
}
var openURL = function(url, width, height, scrollbars) {
    window.open(url, "", "width=" + width + ", height=" + height + ", scrollbars=" + scrollbars + "");
}


