Event.observe(window,'load', initProteome, false);

function initProteome() {
/*
	$$("tr.p_line").each(function(element) {
		element.observe('mouseover', function(event) {
			bg_line(element, true);
		}.bindAsEventListener(element))

		element.observe('mouseout', function(event) {
			bg_line(element, false);
		}.bindAsEventListener(element))
	});

	$$("tr.comp__l").each(function(element) {
		element.observe('mouseover', function(event) {
			bg_cline(element, true);
		}.bindAsEventListener(element))

		element.observe('mouseout', function(event) {
			bg_cline(element, false);
		}.bindAsEventListener(element))
	});
*/
	if ($('submit_b') && $('submit_w')) {
		Element.addClassName($('submit_b'), 'dn');
		Element.removeClassName($('submit_w'), 'dn');
	}

	if ($('img_otherswitch')) {
		otherMethodView();
	}

	$$('.btLIP').each(function(element) {
		if (element.tagName.match(/SPAN/i)) {
			Element.removeClassName(element, 'dn');
		} else {
			Element.addClassName(element, 'dn');
		}
	});
}

function otherMethodView() {
	var url = $('img_otherswitch').src;
	var message = $('img_otherswitch').title;

/*	if (Element.visible($('otherswitch'))) {
		url = url.replace(/close/, 'open');
		message = message.replace(/open/, 'close');
	} else {
		url = url.replace(/open/, 'close');
		message = message.replace(/close/, 'open');
	} 
*/
	if (Element.visible($('otherswitch'))) {
		url = url.replace(/close/, 'open');
		message = message.replace(/close/, 'open');
	} else {
		url = url.replace(/open/, 'close');
		message = message.replace(/open/, 'close');
	}
	$('img_otherswitch').src = url;
	$('img_otherswitch').alt = message;
	$('img_otherswitch').title = message;

	Element.toggle($('otherswitch'));
	$$("td.other_method").each(function(element) {
		Element.toggle(element);
	});
}

function compOtherMethodView() {
	var url = $('img_compother').src;
	var message = $('img_compother').title;

/*	if (url.match(/close/i)) {
		url = url.replace(/close/, 'open');
		message = message.replace(/open/, 'close');
	} else {
		url = url.replace(/open/, 'close');
		message = message.replace(/close/, 'open');
	}
*/
	if (url.match(/close/i)) {
		url = url.replace(/close/, 'open');
		message = message.replace(/close/, 'open');
	} else {
		url = url.replace(/open/, 'close');
		message = message.replace(/open/, 'close');
	}
	$('img_compother').src = url;
	$('img_compother').alt = message;
	$('img_compother').title = message;

	$$("div.pdef").each(function(element) {
		Element.toggle(element);
	});
}

function compLine(o) {
	var name = o.id.replace(/^ex_/ , "");
	if (!Element.hasClassName(o, 'd' + name)) {
		$$("tr.comp__l").each(function(element) {
			if (Element.hasClassName(element, name)) {
				Element.show(element);
			} else {
				Element.hide(element);
			}
		});
		removeClass();
		Element.addClassName(o, 'd' + name);
	} else {
		removeClass();
		$$("tr.comp__l").each(function(element) {
			Element.show(element);
		});
	}
}

function removeClass() {
	var name = $('pcomp').getElementsBySelector('a');
	for (var i=0; i<name.length; i++) {
		switch (true) {
			case (Element.hasClassName(name[i], 'dhigher')):
				Element.removeClassName(name[i], 'dhigher');
				break;
			case (Element.hasClassName(name[i], 'dlower')):
				Element.removeClassName(name[i], 'dlower');
				break;
		}
	}
			
}

function bg_line(obj, mode) {
	var tds = obj.getElementsBySelector('td');
	for (var i=0; i<tds.length; i++) {
		if (mode) {
			Element.addClassName(tds[i], 'selectedTD');
		} else {
			Element.removeClassName(tds[i], 'selectedTD');
		}
	};
}

function bg_cline(obj, mode) {
	var tds = obj.getElementsBySelector('td');
	var ov_class = "";
	for (var i=0; i<tds.length; i++) {
		switch (true) {
			case (Element.hasClassName(tds[i], 'higher')):
				ov_class = "higher_ov";
				break;
			case (Element.hasClassName(tds[i], 'lower')):
				ov_class = "lower_ov";
				break;
			default:
				ov_class = "normal_ov";
		}
		if (mode) {
			Element.addClassName(tds[i], ov_class);
		} else {
			Element.removeClassName(tds[i], ov_class);
		}
	};
}


function submitProteomeList(p, m, c, k, a) {
	if ($('ProteomeList')) $('ProteomeList').parentNode.removeChild($('ProteomeList'));
	var obj = document.createElement("form");
	obj.setAttribute("action",baseUrl + "/proteome/ProteomeGeneList/" + p);
	obj.setAttribute("method","post");
	obj.setAttribute("id","ProteomeList");
	obj.setAttribute("target","_blank");

	obj.appendChild(inputItem('data[method]', m));
	obj.appendChild(inputItem('data[condition]', c));
	obj.appendChild(inputItem('data[key]', k));
	obj.appendChild(inputItem('data[area_id]', a));
	
	document.getElementsByTagName("body")[0].appendChild(obj);
	obj.submit();
}

function inputItem(n, v) {
	var obj = document.createElement("input");
	obj.setAttribute("type", "hidden");
	obj.setAttribute("name", n);
	obj.setAttribute("value", v);
	
	return obj;
}


