/*______________________________________

  contentSizeMon #061124 (#002b)

  Copyright (C) 2006 Mizuyari All rights reserved.
  Script written by Mahiro Komura.
  http://mizuyari.jp/
______________________________________*/

function contentSizeMon(id, minW, minH, autoStart) { // contentSizeMon #061124
 var self = arguments.callee;
 this._timer;
 this._tempFlag;
 this.id = new String(id);
 this.minWidth  = minW;
 this.minHeight = minH;
 this.autoStart = (typeof autoStart === "undefined") ? true : new Boolean(autoStart);
 if (this.autoStart || mizuyari.ua.isMacIE5) {
  mizuyari.addOnLoadEvent( function() { return contentSizeMon.start(); } );
 }
 if (self._instance == null) self._instance = this;
 return self._instance;
}

contentSizeMon.prototype = {
 start : function () { // contentSizeMon.start #061124
  if (!document.getElementById || this._tempFlag || (!mizuyari.ua.isWinIE && mizuyari.getFlashVersion() == -1) ) return;
  this._tempFlag = 1;
  this.main();
 },

 main : function () { // contentSizeMon.main #061122
  this._clearTimeout();
  var contentElmt = document.getElementById(this.id);
  var currentWidth = getWindowInnerWidth();
  var currentHeight = getWindowInnerHeight();
  if (!isNaN(parseInt(this.minWidth,10))) 
  contentElmt.style.width  = (currentWidth <= this.minWidth) ? this.minWidth + "px" : "100%";
  if (!isNaN(parseInt(this.minHeight,10)))
  contentElmt.style.height = (currentHeight <= this.minHeight) ? this.minHeight  + "px" : "100%";
  this._timer = setTimeout("contentSizeMon.main()",500);
 },

 _clearTimeout : function () {
  if (this._timer) clearTimeout(this._timer);
 }

}

function getWindowInnerWidth() { // getWindowInnerWidth #061107
 if(window.innerWidth) {
  return window.innerWidth;
 } else if(document.compatMode == "CSS1Compat") {
  return document.body.parentNode.clientWidth;
 } else if (document.body.clientWidth) {
  return document.body.clientWidth;
 } else {
  return 0;
 }
}

function getWindowInnerHeight() { // getWindowInnerHeight #060524
 if(window.innerHeight) {
  return window.innerHeight;
 } else if(document.compatMode == "CSS1Compat") {
  return document.body.parentNode.clientHeight;
 } else if (document.body.clientHeight) {
  return document.body.clientHeight;
 } else {
  return 0;
 }
}

function MizuyariObject() { // MizuyariObject #061101
 var self = arguments.callee;
 var d  = document;
 var ua = navigator.userAgent;
 this.ua = {};
 this.ua.isMac     = ua.match(/Mac/);
 this.ua.isWin     = ua.match(/Win/);
 this.ua.isSafari  = ua.match(/AppleWebKit/);
 this.ua.isGecko   = ua.match(/Gecko\//);
 this.ua.isOpera   = window.opera;
 this.ua.isNN4     = d.layers;
 this.ua.isWinIE   = (this.ua.isWin && ua.match(/MSIE /) && !this.ua.isOpera);
 this.ua.isWinIE70 = (this.ua.isWinIE && ua.match(/MSIE 7\.0/));
 this.ua.isWinIE60 = (this.ua.isWinIE && ua.match(/MSIE 6\.0/));
 this.ua.isWinIE55 = (this.ua.isWinIE && ua.match(/MSIE 5\.5/));
 this.ua.isWinIE50 = (this.ua.isWinIE && ua.match(/MSIE 5\.0/));
 this.ua.isWinIE40 = (this.ua.isWinIE && ua.match(/MSIE 4\.0/));
 this.ua.isMacIE   = (this.ua.isMac && ua.match(/MSIE /) && !this.ua.isOpera);
 this.ua.isMacIE5  = (this.ua.isMacIE && ua.match(/MSIE 5\./));
 this.ua.isMacIE4  = (this.ua.isMacIE && ua.match(/MSIE 4\./));
 this.mizInitFlag  = false;
 if (self._instance == null) self._instance = this;
 return self._instance;
}

MizuyariObject.prototype = {
getFlashVersion : function () {
 var mimeType = "application/x-shockwave-flash";
 var hasPlugin = (navigator.mimeTypes && navigator.mimeTypes[mimeType]) ? navigator.mimeTypes[mimeType].enabledPlugin : 0;
 var pluginVersion = -1;
 if (hasPlugin) {
  var words = navigator.plugins["Shockwave Flash"].description.split(" ");
  for (var i = 0; i < words.length; ++i) {
   if (isNaN(parseInt(words[i]))) continue;
   pluginVersion = words[i]; 
  }
 } else if (this.ua.isWinIE) {
  document.open();
  document.write('<script type="text/vbscript">\n');
  document.write('function getActiveXFlashVersion()\n');
  document.write(' on error resume next\n');
  document.write(' getActiveXFlashVersion = Left(Hex(Int(CreateObject("ShockwaveFlash.ShockwaveFlash").FlashVersion)),1)\n');
  document.write('end function\n');
  document.write('<\/script>\n');
  document.close();
  pluginVersion = +getActiveXFlashVersion();
 }
 return pluginVersion;
},

addEvent : function (obj, type, event) {
 if(obj.addEventListener) {
  obj.addEventListener(type, event, false);
 } else if(obj.attachEvent) {
  obj.attachEvent('on'+type, event);
 } else {
  obj['on'+type] = event;
 }
},

addOnLoadEvent : function (event) {
 this.addEvent(window, "load", event);
}

};

if (typeof autoStart === "undefined") var mizuyari = new MizuyariObject();

// We are going to be doing "mizuyari" today again.

