//ページ読み込み完了後の動作（0=自動でフィットしない、1=自動でフィット）  
var auto = 1;  
//メイン関数  
function fitIfr() {  
if( !arguments[0] || arguments[0].type == 'load' ) {   
var ifrObjs = document.getElementsByTagName( 'iframe' );  
for( var i=0; i<ifrObjs.length; i++) {  
var ifrObj = ifrObjs.item(i);  
try {  
var mt = getStyle( ifrObj.contentWindow.document.body, 'margin-top' );  
var mb = getStyle( ifrObj.contentWindow.document.body, 'margin-bottom' );  
ifrObj.height = ifrObj.contentWindow.document.body.scrollHeight + Number( mt.match( /[0-9]+/g ) ) + Number( mb.match( /[0-9]+/g ) );  
} catch( e ) {  
/* skip process */  
}  
}  
} else if( arguments[0].charAt(0) == '-' ) {  
var ifrObjs = document.getElementsByTagName( 'iframe' );  
var chkFlg;  
for( var i=0; i<ifrObjs.length; i++) {  
var ifrObj = ifrObjs.item(i);  
chkFlg = false;  
for( var k=0; k<arguments.length; k++ ) {  
if( ifrObj.id == arguments[k].substring( 1, arguments[k].length ) ) {  
if ( arguments[k].charAt( 0 ) == '-' ) chkFlg = true;  
}  
}  
 
if ( !chkFlg ) {  
try {  
var mt = getStyle( ifrObj.contentWindow.document.body, 'margin-top' );  
var mb = getStyle( ifrObj.contentWindow.document.body, 'margin-bottom' );  
ifrObj.height = ifrObj.contentWindow.document.body.scrollHeight + Number( mt.match( /[0-9]+/g ) ) + Number( mb.match( /[0-9]+/g ) );  
} catch( e ) {  
/* skip process */  
}  
}  
}  
} else {  
for( var i=0; i<arguments.length; i++ ) {  
var ifrObj = document.getElementById( arguments[i] ) ? document.getElementById( arguments[i] ) : false;  
if( !ifrObj ) continue;  
try {  
var mt = getStyle( ifrObj.contentWindow.document.body, 'margin-top' );  
var mb = getStyle( ifrObj.contentWindow.document.body, 'margin-bottom' );  
ifrObj.height = ifrObj.contentWindow.document.body.scrollHeight + Number( mt.match( /[0-9]+/g ) ) + Number( mb.match( /[0-9]+/g ) );  
} catch( e ) {  
/* skip process */  
}  
}  
}  
}  
 
//キャメライズ（z-indexなどをzIndexなどに）  
String.prototype.camelize = function() {  
return this.replace( /-([a-z])/g, function( $0, $1 ) { return $1.toUpperCase() } );  
}  
  
//デキャメライズ（zIndexなどをz-indexなどに）  
String.prototype.deCamelize = function() {  
return this.replace( /[A-Z]/g, function( $0 ) { return "-" + $0.toLowerCase() } );  
}  
 
function getStyle( ele, property, pseudo ) {  
if( ele.currentStyle ) { //IE or Opera  
if( property.indexOf( '-' ) != -1 ) property = property.camelize();  
return ele.currentStyle[ property ];  
} else if ( getComputedStyle ) { //Mozilla or Opera  
if( property.indexOf( '-' ) == -1 ) property = property.deCamelize();  
return document.defaultView.getComputedStyle( ele, pseudo ).getPropertyValue( property );  
}  
return '';  
}  
 
if( auto ) {  
if( window.addEventListener ) window.addEventListener( 'load', fitIfr, false );  
else window.attachEvent( 'onload', fitIfr );  
}

