if(typeof Cmizer == "undefined"){
var Cmizer = {
  Domain : "http://cmizer.jp",
  Init : function() {
    var scripts = document.getElementsByTagName('script');
    for(var i=0, len = scripts.length ; i < len ; i++) {
      var src = scripts[i].src;
      if(src.indexOf("cmizer") != -1 && src.indexOf("http://") != -1) this.Domain = src.match(/http:\/\/[^\/]+/)[0];
    }
  },
  
  GetSize : function() {
    var size = {};
    
    size.winWidth = document.documentElement.clientWidth || document.body.clientWidth || window.innerWidth;
    size.winHeight = document.documentElement.clientHeight || document.body.clientHeight || window.innerHeight;
    size.scrollY = document.body.scrollTop  || document.documentElement.scrollTop;
    if (document.compatMode == 'CSS1Compat') {
      size.pageWidth = (document.documentElement.scrollWidth > size.winWidth)?  document.documentElement.scrollWidth : size.winWidth;
      size.pageHeight = (document.documentElement.scrollHeight > size.winHeight)?  document.documentElement.scrollHeight : size.winHeight;
    } else {
      size.pageWidth = (document.body.scrollWidth > size.winWidth)?  document.body.scrollWidth : size.winWidth;
      size.pageHeight = (document.body.scrollHeight > size.winHeight)?  document.body.scrollHeight : size.winHeight;
    }
    
    return size;
  },

  EditorPopup : function(url) {
    var size = Cmizer.GetSize();
    
    Cmizer.VisibleSwfs(false);
    var el = document.body.appendChild(document.createElement('div'));
    el.id = "cm-editor";
  
    el.innerHTML = '<div style="background-color:#000000;filter:Alpha(opacity=80);opacity:0.8;position:absolute;left:0px;top:0px;width:'+size.winWidth+'px;height:' + size.pageHeight +'px;z-index:1000;cursor:pointer;" onclick="Cmizer.ClosePopup(' + "'cm-editor'" + ');"></div><div id="indicator" style="color:#ffffff;text-align:center;margin:-50px 0 0 -100px; padding: 5px width: 201px;height:101px;position: absolute;top: ' + (size.scrollY + size.winHeight/2) + 'px;left: 50%;z-index:1001;" onclick="Cmizer.ClosePopup(' + "'cm-editor'" + ');"><p style="margin-top:10px">CMエディタを表示中です。<br/>クリックすると元に戻ります<p></div>';
    var open = function() {
      if(!window.open(url,'_blank','toolbar=no,location=no,resizable=yes,scrollbars=yes,status=no,width=858,height=720')) window.open(url,'_blank');
    }
    
    // escape popup block
    if(/Firefox/.test(navigator.userAgent)) setTimeout(open, 0);
    else open();
  },

  ClosePopup : function(id) {
    var el = document.getElementById(id);
    if(el) {
      document.body.removeChild(el);
      Cmizer.VisibleSwfs(true);
    }
  },

  VisibleSwfs : function(state) {
    var swfs = document.getElementsByTagName('embed');
    if(swfs.length == 0) swfs = document.getElementsByTagName('object');
    if(swfs.length > 0) for(var i=0, len=swfs.length ; i < len ; i++) swfs[i].style.visibility = state ? 'visible' : 'hidden';
  }
};

Cmizer.Init();

function SetPlayer(f, w, h, url, id, options) {
  options = options || {};
  var name = options.div_name || "cmizer-movie-"+id;
  var el = document.getElementById(name);
  var logo = document.getElementById("cmizer-logo-"+id);
  if(el) {
    w = Math.max(64, Math.min(w, 2880));
    h = Math.max(24, Math.min(h, 2880));
    options["no_scale"] = true;

    // without no_scale
    if (w < 320 || h < 120) {
      var aspect = 340 / 416;
      var tempSize = {
          width  : w
        , height : h
      }
      if (w < 320 && h >= 120) {
        tempSize.height = parseInt(tempSize.width * aspect);
      } else if (w >= 320 && h < 120) {
        tempSize.width = parseInt(tempSize.height / aspect);
      } else {
        tempSize.width = parseInt(tempSize.height / aspect);
        if (tempSize.width > w) {
          tempSize.width  = w;
          tempSize.height = parseInt(tempSize.width * aspect);
        }
      }
      if (tempSize.width < 64) {
        tempSize.width = 64;
        tempSize.height = parseInt(tempSize.width * aspect);
      }
      w = tempSize.width;
      h = tempSize.height;
      options["no_scale"] = false;
    }

    el.style.background = "";
    el.style.width = w + 'px';
    if(logo) logo.style.width = w + 'px';
    el.style.height = h + 'px';
    var aswfo = new SWFObject("http://"+f, "cmizer-"+id+"-swf", w, h, "9", el.parentNode.style.bgColor);
    aswfo.addParam('allowScriptAccess', 'always');
    aswfo.addParam('wmode', 'transparent');
    aswfo.addVariable("movie_url", "http://"+url);
    if(id){
      aswfo.addVariable("meta_data_id", id);
    }
    aswfo.addVariable("embedded_url", location.href);
    var keys = [
      "auto_play",
      "repeat_play",
      "interval",
      "mute",
      "volume",
      "jump_action",
      "initial_display",
      "loading_display",
      "volume_display",
      "controller_display",
      "border_display",
      "border_color",
      "player_height",
      "player_width",
      "arrangement",
      "no_scale",
      "ignore_music"
    ];
    for(var i=0; i < keys.length; i++) {
      var key = keys[i];
      if (typeof options[key] != "undefined") {
        if(key == "border_color") {
          aswfo.addVariable(key, "0x" + options[key]);
        } else {
          aswfo.addVariable(key, options[key]);
        }
      }
      if(key == "volume" && options.volume == 0) aswfo.addVariable("mute", true);
    }
    aswfo.write(el.id);
  }
}
}
