<!--//

/*
----------------------------------------------------------------------------------------
	pushImages( id名, 表示width, 表示height );

		サイズを変更するデータを登録します。
		MainImageSizeChange() が呼び出されたとき、登録したデータでサイズ変更をします。

----------------------------------------------------------------------------------------
	MainImageSizeChange();
	
		pushImagesで登録されたイメージデータのサイズ変更を行います。
		内部で、sizechangeを読んでいます。
		また、スタイルシートが使用可能なブラウザのみの対応となります。

----------------------------------------------------------------------------------------
	sizechange( object, width, height );

		読み込んだ後、サイズを指定して表示します。縦横比は変更しません。
		なので、長方形の場合、どちらか長いほうの比率を使うので、余白が発生します。

		object : Image オブジェクト
		width  : 表示する幅。未定義のときは100
		height : 表示する高さ。未定義のときは100
	
		onLoadイベントを利用して、読み込んだ後に、表示変更します。
		sizechange( object );
		としても呼び出せますが、そのときは100*100をMAXに表示します。
	
----------------------------------------------------------------------------------------
	ImagePopupWindow( imageurl );
	
	指定した画像を別ウィンドウで表示します。
	
		url : 表示したい画像のURL
	
		onClickイベントを利用して、クリック時に、別ウィンドウで表示します。

----------------------------------------------------------------------------------------
	ClosePopup();
	
	ページが切り替わったときやウィンドウを閉じたとき、
	ImagepopUpWindowで生成されたウィンドウを自動で閉じます。
	
		引数：なし
	
	    bodyタグ内の onUnloadイベントを利用します。
	    ページが変更される、もしくはブラウザを閉じるときに、
	    ImagepopUpWindowで生成されたウィンドウが残っていた場合、そのウィンドウを
	    閉じます。

*/

MainImages = new Array();
function pushImages( name, w, h )
{
	var data = new Array( name, w, h );
	MainImages.push( data );
}

function MainImageSizeChange()
{
	var Img;
	var i;

	for( i = 0; i < MainImages.length; i++ ){
		Img = document.getElementById( MainImages[i][0] );
		
		sizechange( Img, MainImages[i][1], MainImages[i][2] )
	}
}

function sizechange( object, x, y )
{

	if( !object ){
		return;
	}
	
	var wsize = 1;
	var hsize = 1;
	var maxwidth;
	var maxheight;

	if( x == 0 ){
		//表示する大きさの指定がなかったとき
		maxwidth = 100;
		maxheight = 100;
	}else{
		maxwidth = x;
		maxheight = y;
	}

	var orgwidth = object.width;
	var orgheight= object.height;

	if( orgwidth != maxwidth ){
		wsize = maxwidth/orgwidth;
		hsize = wsize;
	}

	if( orgheight*hsize > maxheight ){
		hsize = hsize * maxheight/(orgheight*hsize);
		wsize = hsize;
	}
	
	object.width  = orgwidth*wsize;
	object.height = orgheight*hsize;

	return;
}

var popUpWin=0;
var MAXWIDTH = 550;
var MAXHEIGHT = 550;

function ImagePopupWindow( URLStr )
{
  var Img = new Image();
  Img.src = URLStr;

  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  var w, h;
  //以下は自動調整する場合
//  w = ( Img ) ? Img.width + 50: 100;
//  h = ( Img ) ? Img.height + 100 : 200;
  
//  if( w > 350 ) w = 350;
//  if( h > 350 ) h = 350;

	w = MAXWIDTH;
	h = MAXHEIGHT;

//  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width='+w+',height='+h );
  popUpWin = open( "", 'popUpWin', 'scrollbars=yes,resizable=yes,width='+w+',height='+h );
  popUpWin.document.open("text/html");
  popUpWin.document.write("<html><body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>");
  popUpWin.document.write("<img src='"+URLStr+"'>");
  popUpWin.document.write("</body></html>");
  popUpWin.document.close();

  return;
}

function ClosePopup()
{
	if( popUpWin ){
	    if(!popUpWin.closed) popUpWin.close();
	}
	return;
}
//-->

