// Require function.js


var LayerDialog = Class.create();

LayerDialog.prototype = {

	initialize : function(id) {
		this.id = id;
		this.shadow = this.create(id + "_shadow", 'black', 5);
		this.dialog = this.create(id, 'white', 6);
		this.posmode = 0;	// center:0 / x center:1
		this.visibleFlag = false;
	},

	// - - - - - - - - - - - - - - - - - - - - -

	create : function(id, color, zidx) {

		var ua = navigator.userAgent
		var o6 = ua.indexOf("Opera 6")!=-1 || ua.indexOf("Opera/6")!=-1 
		if( o6 ) return null    //Opera6は無視

		if (document.getElementById) { //e5,e6,n6,n7,m1用
  
			var layoj = document.createElement('div');
			layoj.setAttribute('id', id);
			layoj.innerHTML = '';
			layoj.style.position = 'absolute';
			layoj.style.left = '0px';
			layoj.style.top = '0px';
			layoj.style.width = '0px';
			layoj.style.height = '0px';
			layoj.style.zIndex = '' + zidx;
			layoj.style.visibility = 'hidden';
			layoj.style.backgroundColor = color;
  
			document.body.appendChild(layoj);
			return layoj;

		} else if (document.all) {          //e4用
  
			var divstr  = '<div id=' + id + ' style="'
							+ ' position: absolute;'
							+ ' left    : 0px; '
							+ ' top     : 0px; '
							+ ' width   : 0px; '
							+ ' height  : 0px; '
							+ ' zIndex  : ' + zidx + '; '
							+ ' visibility : hidden; '
							+ ' background-color : ' + color + '; '
							+ '">'
							+ '<\/div>';

			document.body.insertAdjacentHTML('BeforeEnd', divstr);

			return document.all(id);

		} else  if(document.layers) {      //n4用

			var layoj = new Layer(0);
			layoj.name = id;
			layoj.left = 0;
			layoj.top = 0;
			layoj.height = 0;
			layoj.visibility = 'hidden';
			layoj.zIndex = '' + zidx;
			if (color == 'transparent')	color = null;
			layoj.bgColor = color;

			return layoj;
		}

		return null;
	},

	// - - - - - - - - - - - - - - - - - - - - -

	getLeft : function() {

		if(document.all) {                     //e4,e5,e6,o6用
			return this.dialog.style.pixelLeft;
		}
		else if(document.getElementById) {     //n6,m1用
			if (this.dialog.style.left)	return parseInt(this.dialog.style.left);
		}
		else if(document.layers) {      //n4用
			return this.dialog.left;
		}

		return 0;
	},

	// - - - - - - - - - - - - - - - - - - - - -

	getTop : function() {

		if(document.all) {                     //e4,e5,e6,o6用
			return this.dialog.style.pixelTop;
		}
		else if(document.getElementById) {     //n6,m1用
			if (this.dialog.style.top)	return parseInt(this.dialog.style.top);
		}
		else if(document.layers) {      //n4用
			return this.dialog.top;
		}

		return 0;
	},


	// - - - - - - - - - - - - - - - - - - - - -

	getWidth : function() {

		if(document.all) {                     //e4,e5,e6,o6用
			return this.dialog.style.pixelWidth;
		}
		else if(document.getElementById) {     //n6,m1用
			if (this.dialog.style.width)	return parseInt(this.dialog.style.width);
		}
		else if(document.layers) {      //n4用
			return this.dialog.clip.right;
		}

		return 0;
	},

	// - - - - - - - - - - - - - - - - - - - - -

	getHeight : function() {

		if(document.all) {                     //e4,e5,e6,o6用
			return this.dialog.style.pixelHeight;
		}
		else if(document.getElementById) {     //n6,m1用
			if (this.dialog.style.height)	return parseInt(this.dialog.style.height);
		}
		else if(document.layers) {      //n4用
			return this.dialog.clip.height;
		}

		return 0;
	},

	// - - - - - - - - - - - - - - - - - - - - -

	setPosition : function(x, y) {

		if(document.all) {                     //e4,e5,e6,o6用

			if (typeof this.dialog.style.pixelLeft != "undefined" && typeof this.dialog.style.pixelLeft == "string") {
				this.dialog.style.pixelLeft = x + 'px';
				this.dialog.style.pixelTop = y + 'px';
			} else {
				this.dialog.style.pixelLeft = x;
				this.dialog.style.pixelTop = y;
			}

		}
		else if(document.getElementById) {     //n6,m1用

			if (typeof this.dialog.style.left != "undefined" && typeof this.dialog.style.left == "string") {
				this.dialog.style.left = x + 'px';
				this.dialog.style.top = y + 'px';
			} else {
				this.dialog.style.left = x;
				this.dialog.style.top = y;
			}

		}
		else if(document.layers) {      //n4用
			this.dialog.moveTo(x,y);
		}

	},

	// - - - - - - - - - - - - - - - - - - - - -

	setLayerSize : function(obj, w, h) {

		if(document.all) {                     //e4,e5,e6,o6用

			if (typeof obj.style.pixelWidth != "undefined" && typeof obj.style.pixelWidth == "string") {
				obj.style.pixelWidth = w + 'px';
				obj.style.pixelHeight = h + 'px';
			} else {
				obj.style.pixelWidth = w;
				obj.style.pixelHeight = h;
			}

		}
		else if(document.getElementById) {     //n6,m1用

			if (typeof obj.style.width != "undefined" && typeof obj.style.width == "string") {
				obj.style.width = w + 'px';
				obj.style.height = h + 'px';
			} else {
				obj.style.width = w;
				obj.style.height = h;
			}

		}
		else if(document.layers) {      //n4用
			obj.resizeTo(w, h);
		}
	},

	setSize : function(w, h) {
		this.setLayerSize(this.dialog, w, h);
	},

	setShadowSize : function(w, h) {
		this.setLayerSize(this.shadow, w, h);
	},

	// - - - - - - - - - - - - - - - - - - - - -

	setShadowOpacity : function(rate) {

		var ua = navigator.userAgent;

		if( document.layers ) {   //n4とMac版e4,e5は0の時hidden
			if (arg > 0) {
				this.shadow.visibility='visible';
			} else if (arg == 0) {
				this.shadow.visibility='hidden';
			}
		}

		else if ((ua.indexOf('Mac_PowerPC') !=-1) && (document.all)) {
			if (arg > 0) {
				this.shadow.style.visibility = 'visible';
			} else if (arg == 0) {
				this.shadow.style.visibility = 'hidden';
			}
		}

		else if(document.all) {  //Win版e5,e6
			//this.shadow.style.filter = "alpha(opacity=" + (arg * 100) + ")";
			this.shadow.style.filter = "alpha(opacity=0)";
			this.shadow.filters.alpha.Opacity  = (rate * 100);
		}

		else if(ua.indexOf('Gecko') != -1) {  //n6,m1
			this.shadow.style.MozOpacity = rate;
		}

	},

	// - - - - - - - - - - - - - - - - - - - - -

	setBGColor : function(color) {

		if (color == '') (!!window.opera)?color='white':color='transparent';

		if(document.getElementById) {      //n6,m1,e5,e6,o6用
			this.dialog.style.backgroundColor = color;
		}

		else if(document.all) {             //e4用
			this.dialog.style.backgroundColor = color;
		}

		else if(document.layers) {         //n4用
			if (color == 'transparent')	color = null;
			this.dialog.bgColor = color;
		}

    },

	// - - - - - - - - - - - - - - - - - - - - -

	setHTML : function(html) {

		if(document.getElementById) {        //e5,e6,n6,n7,m1,o7,s1用
			this.dialog.innerHTML = html;
		}
		else if(document.all) {            //e4用
			this.dialog.innerHTML = html;
		}
		else if(document.layers) {        //n4用
			with(this.dialog.document) {
				open()
				write(html)
				close()
			}
		}
	},

	appendChild : function(child) {
		this.dialog.appendChild(child);
	},

	// - - - - - - - - - - - - - - - - - - - - -

	setupCenter : function(width, height) {

		var top = 0;
		var left = 0;

		var winwidth = 0;
		if (document.body.clientWidth) {
			winwidth = document.body.clientWidth;
		} else if (window.innerWidth) {
			winwidth = window.innerWidth;
		}

		var scrx = 0;
		if (document.documentElement.scrollLeft) {
			scrx = document.documentElement.scrollLeft;
		} else if (document.body.scrollLeft) {
			scrx = document.body.scrollLeft;
		}

		var winheight = 0;
		if (document.documentElement.clientHeight) {
			winheight = document.documentElement.clientHeight;
		} else if (document.body.clientHeight) {
			winheight = document.body.clientHeight;
		} else if (window.innerHeight) {
			winheight = window.innerHeight;
		}

		var scry = 0;
		if (document.documentElement.scrollTop) {
			scry = document.documentElement.scrollTop;
		} else if (document.body.scrollTop) {
			scry = document.body.scrollTop;
		}

		if (winwidth > width) {
			left = (winwidth - width) / 2;
		} else {
			width = winwidth;
		}

		if (winheight > height) {
			top = (winheight - height) / 2;
		} else {
			height = winheight;
		}

		this.setSize(width, height);
		this.setPosition(left + scrx, top + scry);
		this.setShadowSize(winwidth + scrx, winheight + scry);
	},

	setupXCenter : function(width, height, top) {

		var left = 0;

		var winwidth = 0;
		if (document.body.clientWidth) {
			winwidth = document.body.clientWidth;
		} else if (window.innerWidth) {
			winwidth = window.innerWidth;
		}
		var winheight = 0;
		if (document.body.clientHeight) {
			winheight = document.body.clientHeight;
		} else if (window.innerHeight) {
			winheight = window.innerHeight;
		}

		if (winwidth > width) {
			left = (winwidth - width) / 2;
		} else {
			width = winwidth;
		}

		this.setSize(width, height);
		this.setPosition(left, top);
		this.setShadowSize(winwidth, winheight);
	},

	// - - - - - - - - - - - - - - - - - - - - -


	show : function(width, height) {

		this.posmode = 0;

		this.setupCenter(width, height);

		this.visible();
	},

	showXCenter : function(width, height, top) {

		this.posmode = 1;

		this.setupXCenter(width, height, top);

		this.visible();
	},

	visible : function() {

		if(document.getElementById) { //NN6,Mozilla,IE5用
			this.shadow.style.visibility = "visible";
			this.dialog.style.visibility = 'visible';
		}
		else if(document.all) {       //IE4用
			this.shadow.style.visibility = "visible";
			this.dialog.style.visibility = 'visible';
		}
		else if(document.layers) {    //NN4用
			this.shadow.visibility = "show";
			this.dialog.visibility = 'show';
		}

		this.visibleFlag = true;
	},


	hide : function() {

		if(document.getElementById) { //NN6,Mozilla,IE5用
			this.shadow.style.visibility = "hidden";
			this.dialog.style.visibility = 'hidden';
		}
		else if(document.all) {       //IE4用
			this.shadow.style.visibility = "hidden";
			this.dialog.style.visibility = 'hidden';
		}
		else if(document.layers) {    //NN4用
			this.shadow.visibility = "hidden";
			this.dialog.visibility = 'hidden';
		}

		this.visibleFlag = false;
	},

	isVisible : function() {
		return this.visibleFlag;
	},


	// - - - - - - - - - - - - - - - - - - - - -

	resize : function() {

		if (this.isVisible()) {
			if (this.posmode == 0) {
				this.setupCenter(this.getWidth(), this.getHeight());
			}
			else {
				this.showXCenter(this.getWidth(), this.getHeight(), this.getTop());
			}
		}
	}


};


