a_url = new Array();

resept = new Image();
resept.src = "/image/resept.gif";
clr = new Image();
clr.src = "/image/clr.gif";

flock = 1;
var FD;
sp = 100;

function init() {
	an = document.getElementsByTagName("a");
	for(i = 0; i < an.length; i ++) {
		if(String(an[i].href).match(/\/image\/item/))
			an[i].onclick = function() { im_open(this.href); return false; }
	}

	document.getElementById("overlay").onclick = im_close;
	document.getElementById("imtbl").onclick = im_close;
	agt = navigator.userAgent;
	cmd = (agt.match(/firefox/i)) ? 'MozOpacity'
	 : (agt.match(/safari/i)) ? 'Opacity'
	 : (document.all && ! window.opera) ? 'filter'
	 : '';
	sel = document.getElementsByTagName("select");
	sm();
	flock = 0;
	document.getElementById("overlay").style.width = "100%";
}

function print_status_td() {
	window.status = this.id.replace(/^\d+-/, '');
	return true;
}

function reset_status_td() {
	window.status = self.defaultStatus;
}

function jump() {
	location.href = this.getElementsByTagName("a")[0].href;
}

function print_status_a() {
	window.status = a_url[this.href];
	return true;
}

function reset_status_a() {
	window.status = self.defaultStatus;
}

function sm() {
	if(!document.forms['sf'].elements['c']) return false;
	f = document.forms['sf'].elements['c'];
	v = f.options[f.selectedIndex].value;
	if(!v) {
		document.forms['sf'].i[0].disabled = false;
		document.getElementById('lb1').style.color = "#333333"
		document.forms['sf'].i[1].disabled = false;
		document.getElementById('lb2').style.color = "#333333"
	}
	else if(v.match(/^item/)) {
		document.forms['sf'].i[0].disabled = true;
		document.getElementById('lb1').style.color = "#cccccc"
		document.forms['sf'].i[1].disabled = false;
		document.getElementById('lb2').style.color = "#333333"
		document.forms['sf'].i[1].checked = true;
	}
	else {
		document.forms['sf'].i[1].disabled = true;
		document.getElementById('lb2').style.color = "#cccccc"
		document.forms['sf'].i[0].disabled = false;
		document.getElementById('lb1').style.color = "#333333"
		document.forms['sf'].i[0].checked = true;
	}
}

function get_scroll_max() {

	if(self.innerHeight && self.scrollMaxY) {	
		maxX = document.body.scrollWidth;
		maxY = self.innerHeight + self.scrollMaxY;
	}
	else if(document.body.scrollHeight > document.body.offsetHeight){
		maxX = document.body.scrollWidth;
		maxY = document.body.scrollHeight;
	}
	else {
		maxX = document.body.offsetWidth;
		maxY = document.body.offsetHeight;
	}
}

function im_open(im) {

	if(flock) return;

	display = document.getElementById("disp");
	display.style.border = "0px";
	display.src = resept.src;
	get_scroll_max();

	if(self.innerHeight) {
		selfW = self.innerWidth;
		selfH = self.innerHeight;
	}
	else if(document.documentElement && document.documentElement.clientHeight) {
		selfW = document.documentElement.clientWidth;
		selfH = document.documentElement.clientHeight;
	}
	else if(document.body) {
		selfW = document.body.clientWidth;
		selfH = document.body.clientHeight;
	}

	scroll_top = (document.all) ? document.body.scrollTop : self.pageYOffset;
	obj = document.getElementById("overlay");

	with(obj.style) {
//		width = maxX;
		height = maxY;
		left = 0
		top = 0;
	}

	outer = document.getElementById("imtbl");

	with(outer.style) {
		width = "100%";
		height = selfH;
		left = 0;
		top = scroll_top;
	}

	if(document.all)
		for(i = 0; i < sel.length; i ++)
			sel[i].style.visibility = 'hidden';

	im_obj = document.createElement("img");
	im_obj.onload = im_load;
	im_obj.setAttribute("src", im);
}

function im_load() {

	if(im_obj.width > maxX)
		obj.style.width = im_obj.width;

	outer.style.zIndex = 20;
	display.style[cmd] = (cmd == 'filter') ? "alpha(opacity=0)" : 0;
	setTimeout("im_set()", 0);
}

function im_set() {
	display.src = im_obj.src;
	display.style.border = "1px solid #999999";
	fn = 0;
	layfade();
}

function layfade() {

	clearTimeout(FD);
	fn ++;
	op = (cmd == 'filter') ? "alpha(opacity=" + (fn * 10) + ")" : fn / 10;
	display.style[cmd] = op;
	if(fn <= 9)
		FD = setTimeout("layfade()", sp);
}

function im_close() {

	clearTimeout(FD);
	get_scroll_max();

	display.src = clr.src;
	outer.style.top = -1000;
	outer.style.zIndex = 0;
	obj.style.width = 10;
	obj.style.top = maxY * -1.5;

	if(document.all)
		for(i = 0; i < sel.length; i ++)
			sel[i].style.visibility = 'visible';
}

