// JavaScript Document

/*
 * Initializing collection preview
 *
 */

var overview, i, j, a, trs, tds;


// get the 2 column list
overview = getObj('productslist');

/*** main routine ***/

if (overview) {
	if (a = overview.getElementsByTagName('A')) {
		for(i=0; i < a.length; i++) {
			if (!a.item(i).label) a.item(i).label = findAdjacentLabel(a.item(i));
			/*a.item(i).would_b_height = a.item(i).offsetParent.offsetHeight;
			a.item(i).real_height = a.item(i).offsetHeight;
			if (a.item(i).would_b_height > (a.item(i).real_height + 22)) {
				a.item(i).style.paddingTop = (a.item(i).would_b_height - 22 - a.item(i).real_height + 15) + 'px';
			}*/
			a.item(i).onclick = function() {
				this.blur();
				if (this.label) {
					this.label.pick();
				}
			}
		}
	}
	/*trs = overview.rows;
	for(i=0; i < trs.length; i++) {
		tds = trs.item(i).cells;
		for(j=0; j < tds.length; j++) {
			bdr = tds.item(j).getAttribute('bdr');
			//tds.item(j).className = 'item' + ((bdr!='y')? ' ' + bdr : '');
			tds.item(j).removeAttributeNode(tds.item(j).getAttributeNode('bdr'));
		}
	}*/
}


/*** sub functions ***/

// find each table 'class=label' containing the product name and attributes
// when found, start initializing it

function findAdjacentLabel(linkObj) {
	sb = linkObj.parentNode;
	while (sb.nextSibling) {
		sb = sb.nextSibling;
		if (sb.nodeName == 'TABLE') break;
	}
	if (sb.className && sb.className.match(/label/)) {
		initAdjacentLabel(sb,linkObj);
		return sb;
	}
	return null;
}

// initialization: making links from text content

function initAdjacentLabel(label,linkObj) {
	ths = {};
	tds = {};
	if (label.className.match(/\ssel/)) overview.Picked = label;
	label.pick = function() {
		if (overview.Picked && (this!=overview.Picked)) {
			overview.Picked = overview.Picked.unpick();
		}
		if (!this.className.match(/\ssel/)) this.className += ' sel';
		this.is_picked = 1;
		overview.Picked = this;
	}
	label.unpick = function() {
		this.className = this.className.replace(/\ssel/g,'');
		this.is_picked = 0;
		return null;
	}
	if (ths = label.getElementsByTagName('TH')) for(j=0; j < ths.length; j++) {
		if (ths.item(j).hasChildNodes && ths.item(j).firstChild) {
			tmp = document.createElement('A');
			tmp.href = linkObj.href;
			tmp.innerHTML = ths.item(j).firstChild.nodeValue;
			l = ths.item(j).appendChild(tmp);
			l.label = label;
			ths.item(j).removeChild(ths.item(j).firstChild);
		}
	}
	if (tds = label.getElementsByTagName('TD')) for(j=0; j < tds.length; j++) {
		if (tds.item(j).hasChildNodes && tds.item(j).firstChild) {
			tmp = document.createElement('A');
			tmp.href = linkObj.href;
			tmp.innerHTML = tds.item(j).innerHTML;
			tds.item(j).innerHTML = '';
			l = tds.item(j).appendChild(tmp);
			l.label = label;
			//tds.item(j).removeChild(tds.item(j).firstChild);
		}
	}
}

function closeSearchbox(action) {
	var s;
	if (s = getObj('section_search')) s.innerHTML = '';
	if (action) eval(action);
}
