///////////////////////////////////////////////////////////////////////////////
//	MagButton.js
//		拡大ボタン描画
//			Copyright (c) 2008 mochiZ.
//
//	author: mochiZ.
//	create: 2009/03/09
//	update: 2009/03/31	このオブジェクトのクラス名を設定できるように変更
///////////////////////////////////////////////////////////////////////////////

//=============================================================================
// class MagButton
//=============================================================================

//**************************************************
// コンストラクタ
//		className: このオブジェクトのクラス名
//		dispID   : 表示用の親のタグID名
//		magID    : 拡大する親のタグID名
//**************************************************
function MagButton(className, dispID, magID)
{
	var div;
	var button;
	var zoom;
	
	this.zoom = new ZoomString(magID, 10);
	this.visible = !eval(this.zoom.getCookie("mag_btn_hidden"));

	var pObj = document.getElementById(dispID);
	var base = document.createElement("div");
	var div = document.createElement("div");
	this.button = document.createElement("div");

	var up = document.createElement("div");
	var down = document.createElement("div");
	var normal = document.createElement("div");
	
	var btn = this.button;
	var zm = this.zoom;
	var opa = (this.visible) ? 20 : 0;

	btn.style.opacity = opa/100;
	btn.style.filter = "alpha(opacity="+opa+")"; 

	btn.style.background = (MagButton.isIE()) ? "url(/_img/sizeButton.gif) no-repeat 0 0" : "url(/_img/sizeButton.png) no-repeat 0 0";
	btn.style.width = "34px";
	btn.style.height = "83px";
	btn.style.cursor = "pointer";
	
	up.style.position = down.style.position =  normal.style.position = "absolute";
	
	up.style.top = "2px";
	down.style.bottom = "2px";
	normal.style.top = "31px";
	
	up.style.left = down.style.left = normal.style.left = "2px";
	up.style.width = down.style.width = normal.style.width = "30px";
	up.style.height = down.style.height = "30px";
	normal.style.height = "20px";
	
	btn.appendChild(up);
	btn.appendChild(down);
	btn.appendChild(normal);
	
	if(MagButton.isIE6()){
		div.style.position = "absolute";
		div.style.top = "10px";
		div.style.right = "-40px";
		div.appendChild(btn);
	}else{
		base.style.position = "absolute";
		base.style.top = "0px";
		base.style.right = "-5px";
		div.style.position = "fixed";
		div.style.top = "10px";
		div.appendChild(btn);
		base.appendChild(div);
		div = base;
	}
	
	div.className = className;
	pObj.appendChild(div);

	div.onmouseover = function()
	{
		btn.style.opacity = "1";
		btn.style.filter = "alpha(opacity=100)";
	}
	
	div.onmouseout = function()
	{
		btn.style.opacity = opa/100;
		btn.style.filter = "alpha(opacity="+opa+")"; 

		btn.style.backgroundPosition = "0 0";
	}
	
	//*****************************************************
	// [+]ボタン
	//*****************************************************
	up.onmousedown = function()
	{
		zm.zoomIn();
		btn.style.backgroundPosition = "-68px 0";
	}

	//*****************************************************
	// [size]ボタン
	//*****************************************************
	normal.onmousedown = function()
	{
		zm.normal();
		btn.style.backgroundPosition = "-34px 0";
	}
	
	//*****************************************************
	// [-]ボタン
	//*****************************************************
	down.onmousedown = function()
	{
		zm.zoomOut();
		btn.style.backgroundPosition = "-102px 0";
	}

	//*****************************************************
	// ボタンリリース
	//*****************************************************
	up.onmouseup = down.onmouseup = normal.onmouseup = function()
	{
		btn.style.backgroundPosition = "0 0";
	}
}

MagButton.isIE6 = function()
{
	return(navigator.appVersion.indexOf("MSIE 6") > 0);
}

MagButton.isIE = function()
{
	return(navigator.appVersion.indexOf("MSIE") > 0);
}


MagButton.prototype.visibleCheckButton = function(visibleID)
{
	var visible = document.getElementById(visibleID);
	
	if(!visible) return;

	visible.checked = eval(this.zoom.getCookie("mag_btn_hidden"));;
	
	var button = this.button;
	var zoom = this.zoom;
	
	visible.onclick = function()
	{
		var opa = (visible.checked) ? 0 : 20;
		
		button.style.opacity = opa/100;
		button.style.filter = "alpha(opacity="+opa+")"; 
		zoom.setCookie("mag_btn_hidden", visible.checked);
	}
	
}

