﻿//---------------------------------------------------------------
// ImageSizeAdjuster.js
// 
// ＜概要＞
// 画像サイズを調整するクラスとその内容をcssにして書き出す関数。
//---------------------------------------------------------------

//---------------------------------------------------------------
// ImageSizeAdjuster
// 
// ＜引数＞
// width:
// 	画像の幅
// height:
// 	画像の高さ
// 
// ＜概要＞
// コンストラクタ。
//---------------------------------------------------------------
function ImageSizeAdjuster(width, height)
{
	this.width = width;
	this.height = height;
}

//---------------------------------------------------------------
// resize(prototype)
// 
// ＜引数＞
// scaleValue:
// 	画像サイズにかける値
// 
// ＜概要＞
// 画像サイズ変更。
//---------------------------------------------------------------
ImageSizeAdjuster.prototype.resize = function(scaleValue)
{
	this.width = this.width * scaleValue;
	this.height = this.height * scaleValue;
}


//---------------------------------------------------------------
// resizeAppointedWidth(prototype)
// 
// ＜引数＞
// maxWidth:
// 	この値以下の幅になるようリサイズ
// 
// ＜概要＞
// 引数に貰った幅以下になるようにリサイズする。
//---------------------------------------------------------------
ImageSizeAdjuster.prototype.resizeAppointedWidth = function(maxWidth)
{
	// ゼロで割れない
	if(maxWidth == 0)
	{
		return;
	}
	
	var scaleValue = this.width / maxWidth;
	this.width = this.width / scaleValue;
	this.height = this.height / scaleValue;
}


//---------------------------------------------------------------
// resizeAppointedHeight(prototype)
// 
// ＜引数＞
// maxHeight:
// 	この値以下の高さになるようリサイズ
// 
// ＜概要＞
// 引数に貰った高さ以下になるようにリサイズする。
//---------------------------------------------------------------
ImageSizeAdjuster.prototype.resizeAppointedHeight = function(maxHeight)
{
	// ゼロで割れない
	if(maxHeight == 0)
	{
		return;
	}
	
	var scaleValue = this.height / maxHeight;
	this.width = this.width / scaleValue;
	this.height = this.height / scaleValue;
}


//---------------------------------------------------------------
// writePrintRule
// 
// ＜引数＞
// ruleName:
// 	cssファイル内のルール名
// ruleValue:
// 	ルールの内容
// 
// ＜概要＞
// 印刷時のみ有効なcssをこの位置にdocument.write()で書き込む。
//---------------------------------------------------------------
function writePrintRule(ruleName, ruleValue)
{
	document.write("<style type='text/css'>");
	document.write("@media print {");
	document.write(ruleName + "{" + ruleValue + "}");
	document.write("}");
	document.write("</style>");
}




