try { 
document.execCommand('BackgroundImageCache', false, true); 
} catch(e) {}

mg = {}

var Info = {
            isDebug : ( ( typeof __is_debug != 'undefined' ) ? __is_debug : false ) 
};

konsole = {
    log : function(){},
    info : function(){},
    warn : function(){},
    error : function(){},
    assert : function(){}
}
if( Info.isDebug ){
    try {
        console.log('start');
        konsole = {
            log : function(v){ if( Info.isDebug ){ console.log(v); } },
            info : function(v){ if( Info.isDebug ){ console.info(v); } },
            warn : function(v){ if( Info.isDebug ){ console.warn(v); } },
            error : function(v){ if( Info.isDebug ){ console.error(v); } },
            assert : function(v){ if( Info.isDebug ){ console.assert(v); } }
        }
    } catch(e) {
    }
}

if( Prototype.Browser.IE ){
    if (typeof document.documentElement.style.msInterpolationMode != "undefined") {
        Prototype.Browser.IE6 = false;
    } else {
        Prototype.Browser.IE6 = true;
    }
    var ua = navigator.userAgent.toLowerCase();
    if (ua.indexOf('msie 7') != -1){
      Prototype.Browser.IE7 = true;
    } else {
      Prototype.Browser.IE7 = false;
    }
} else {
    Prototype.Browser.IE6 = false;
    Prototype.Browser.IE7 = false;
}

mg.Element = {}
mg.Element.refresh = function( element_id ){
    var element = $(element_id);
    if( Prototype.Browser.IE ){
        element.hide();
        element.show();
    }
}

mg.preTrackPageview = location.pathname;
mg.trackPageview = function( url ){
    if( typeof pageTracker == 'object' && mg.preTrackPageview != url ){
        mg.preTrackPageview = url;
        pageTracker._trackPageview( url );
    }
}

function enable(name) {
	tM = document.getElementById(name).style;
	tM.display = 'block';
	//tM.visibility = 'visible';
  //tM.heigth = '';
}
function disable(name) {
	tM = document.getElementById(name).style;
	tM.display = 'none';
	//tM.visibility = 'hidden';
	//tM.height = '0px';
}
function hide(name) {
	tM = document.getElementById(name).style;
	tM.display = 'none';
	tM.visibility = 'hidden';
	tM.height = '0px';
}
function show_toggle(name) {
	tM = document.getElementById(name).style;
  if( tM.visibility == "hidden" || tM.display == "none" ){
	  //tM.visibility = "visible";
	  tM.display = 'block';
  } else {
	  //tM.visibility = "hidden";
	  tM.display = 'none';
  }
}
function encodeURL(str) {
  var character = '';
  var unicode   = '';
  var string    = '';
  var i         = 0;

  for (i = 0; i < str.length; i++) {
    character = str.charAt(i);
    unicode   = str.charCodeAt(i);

    if (character == ' ') {
      string += '+';
    } else {
      if ( character == ')' || character == '(' || unicode == 0x2a || unicode == 0x2d || unicode == 0x2e || unicode == 0x5f || ((unicode >= 0x30) && (unicode <= 0x39)) || ((unicode >= 0x41) && (unicode <= 0x5a)) || ((unicode >= 0x61) && (unicode <= 0x7a))) {
        string = string + character;
      } else {
        if ((unicode >= 0x0) && (unicode <= 0x7f)) {
          character   = '0' + unicode.toString(16);
          string += '%' + character.substr(character.length - 2);
        } else if (unicode > 0x1fffff) {
          string += '%' + (oxf0 + ((unicode & 0x1c0000) >> 18)).toString(16);
          string += '%' + (0x80 + ((unicode & 0x3f000) >> 12)).toString(16);
          string += '%' + (0x80 + ((unicode & 0xfc0) >> 6)).toString(16);
          string += '%' + (0x80 + (unicode & 0x3f)).toString(16);
        } else if (unicode > 0x7ff) {
          string += '%' + (0xe0 + ((unicode & 0xf000) >> 12)).toString(16);
          string += '%' + (0x80 + ((unicode & 0xfc0) >> 6)).toString(16);
          string += '%' + (0x80 + (unicode & 0x3f)).toString(16);
        } else {
          string += '%' + (0xc0 + ((unicode & 0x7c0) >> 6)).toString(16);
          string += '%' + (0x80 + (unicode & 0x3f)).toString(16);
        }
      }
    }
  }

  return string;
}
function IEOnlyEncodeURL( url ){
  if( Prototype.Browser.IE ){
    if( url.match(/%[a-fA-F0-9]/) ){
      return url;
    } else {
      return encodeURL( url );
    }
  } else {
    return url;
  }
}
function bin2hex(str) {
  var character = '';
  var unicode   = '';
  var string    = '';
  var i         = 0;

  for (i = 0; i < str.length; i++) {
    character = str.charAt(i);
    unicode   = str.charCodeAt(i);

        if ((unicode >= 0x0) && (unicode <= 0x7f)) {
          character   = '0' + unicode.toString(16);
          string += character.substr(character.length - 2);
        } else if (unicode > 0x1fffff) {
          string += (oxf0 + ((unicode & 0x1c0000) >> 18)).toString(16);
          string += (0x80 + ((unicode & 0x3f000) >> 12)).toString(16);
          string += (0x80 + ((unicode & 0xfc0) >> 6)).toString(16);
          string += (0x80 + (unicode & 0x3f)).toString(16);
        } else if (unicode > 0x7ff) {
          string += (0xe0 + ((unicode & 0xf000) >> 12)).toString(16);
          string += (0x80 + ((unicode & 0xfc0) >> 6)).toString(16);
          string += (0x80 + (unicode & 0x3f)).toString(16);
        } else {
          string += (0xc0 + ((unicode & 0x7c0) >> 6)).toString(16);
          string += (0x80 + (unicode & 0x3f)).toString(16);
        }
  }

  return string;
}
/*
function printStackTrace() {
  var callstack = [];
  var isCallstackPopulated = false;
  try {
    i.dont.exist+=0; //doesn't exist- that's the point
  } catch(e) {
    if (e.stack) { //Firefox
      var lines = e.stack.split("\n");
      for (var i=0, len=lines.length; i<len; i++) {
        if (lines[i].match(/^\s*[A-Za-z0-9\-_\$]+\(/)) {
          callstack.push(lines[i]);
        }
      }
      //Remove call to printStackTrace()
      callstack.shift();
      isCallstackPopulated = true;
    }
    else if (window.opera && e.message) { //Opera
      var lines = e.message.split("\n");
      for (var i=0, len=lines.length; i<len; i++) {
        if (lines[i].match(/^\s*[A-Za-z0-9\-_\$]+\(/)) {
          var entry = lines[i];
          //Append next line also since it has the file info
          if (lines[i+1]) {
            entry += " at " + lines[i+1];
            i++;
          }
          callstack.push(entry);
        }
      }
      //Remove call to printStackTrace()
      callstack.shift();
      isCallstackPopulated = true;
    }
  }
  if (!isCallstackPopulated) { //IE and Safari
    var currentFunction = arguments.callee.caller;
    while (currentFunction) {
      var fn = currentFunction.toString();
      //var fname = fn.substring(fn.indexOf("function") + 8, fn.indexOf("(")) || "anonymous";
      var fname = fn.substring(0,50) || "anonymous";
      callstack.push(fname);
      currentFunction = currentFunction.caller;
    }
  }
  output(callstack);
}
function output(arr) {
  //Optput however you want
  alert(arr.join("\n\n\n\n"));
}
*/

mg.Window = {
  getInnerWidth: function(){
    if (self.innerWidth){
      return self.innerWidth;
    } else if (document.documentElement && document.documentElement.clientWidth){
      return document.documentElement.clientWidth;
    } else if (document.body){
      return document.body.clientWidth;
    }  
  },
  getInnerHeight: function(){
    if (self.innerHeight){
      return self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight){
      return document.documentElement.clientHeight;
    } else if (document.body){
      return document.body.clientHeight;
    }  
  }
};

function getFlashPlayerVersion(){
  //初期設定
  var flashplayer_ver = 0;
  //IE以外の場合
  if(navigator.plugins && navigator.mimeTypes['application/x-shockwave-flash']){
    var plugin = navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin;
    //Flash Playerがインストールされている場合
    if(plugin){flashplayer_ver = parseInt(plugin.description.match(/\d+\.\d+/));}
  }
  //IEの場合、もしくはFlash Playerがインストールされていない場合
  else{
    //IEでFlash Playerがインストールされている場合
    try{
      var flashOCX = new ActiveXObject("ShockwaveFlash.ShockwaveFlash").GetVariable("$version").match(/([0-9]+)/);
      if(flashOCX){flashplayer_ver = parseInt(flashOCX[0]);}
    }catch(e){}
  }
  //Flash Playerがインストールされていない、もしくはバージョンが6以下の場合
  if(flashplayer_ver <= 6){flashplayer_ver = 0;}
  return flashplayer_ver;
} 
