
var options_array = new Array();
options_array[0] = 'vernation';
options_array[1] = 'ligule';
options_array[2] = 'auricle';
options_array[3] = 'hairs-leaf';
options_array[4] = 'hairs-sheath';
options_array[5] = 'leaf-tip';
options_array[6] = 'sheath';

var start_at = 1;

var vernation_options = new Array();
vernation_options[0] = 'folded';
vernation_options[1] = 'rolled';

var ligule_options = new Array();
ligule_options[0] = 'membranous';
ligule_options[1] = 'fringe-hairs';
ligule_options[2] = 'absent-ligule';

var auricle_options = new Array();
auricle_options[0] = 'absent-auricle';
auricle_options[1] = 'blunt-lobed';
auricle_options[2] = 'long-clasping';

var hairs_leaf_options = new Array();
hairs_leaf_options[0] = 'none-blade';
hairs_leaf_options[1] = 'sparse-blade';
hairs_leaf_options[2] = 'near-base';
hairs_leaf_options[3] = 'upper-lower';
hairs_leaf_options[4] = 'upper-surface';

var hairs_sheath_options = new Array();
hairs_sheath_options[0] = 'none-sheath';
hairs_sheath_options[1] = 'sparse-sheath';
hairs_sheath_options[2] = 'collars';
hairs_sheath_options[3] = 'hairy';
hairs_sheath_options[4] = 'margins';

var leaf_tip_options = new Array();
leaf_tip_options[0] = 'sword';
leaf_tip_options[1] = 'tapered';
leaf_tip_options[2] = 'boat';

var sheath_options = new Array();
sheath_options[0] = 'triangular';
sheath_options[1] = 'smooth';
sheath_options[2] = 'rough';
sheath_options[3] = 'swollen';
sheath_options[4] = 'compressed';

var selected_vernation = '';
var selected_ligule = '';
var selected_auricle = '';
var selected_hairs_leaf = '';
var selected_hairs_sheath = '';
var selected_leaf_tip = '';
var selected_sheath = '';

var temp_vernation = '';
var temp_ligule = '';
var temp_auricle = '';
var temp_hairs_leaf = '';
var temp_hairs_sheath = '';
var temp_leaf_tip = '';
var temp_sheath = '';

var current_popup = '';

function addEvent( obj, type, fn ) {
	searchString = 'n-a';
	if(typeof(obj)=='string') {
		searchString = obj;
		if(document.getElementById)
			obj = document.getElementById(obj);
		else
			obj = document.all[obj];
	}
	if(obj!=null)
	{
		if (obj.attachEvent) {
			obj['e'+type+fn] = fn;
			obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
			obj.attachEvent( 'on'+type, obj[type+fn] );
		} else if(obj.addEventListener) {
			obj.addEventListener( type, fn, false );
		}
	}
	else
	{
		alert('Could not find object '+searchString+' to attach event '+fn);
		// trace a message here?
	}
}

function removeEvent( obj, type, fn ) {
	if ( obj.detachEvent ) {
		obj.detachEvent( 'on'+type, obj[type+fn] );
		obj[type+fn] = null;
	} else {
		obj.removeEventListener( type, fn, false );
	}
}

function addFormEvents() {
	// loop through all the document elements and add events to input elements
	var inputs, i, labels;
	inputs = document.getElementsByTagName('input');
	for(i in inputs) {
		if(inputs[i].className!='submit' && inputs[i].className!='readonly')
		{
			addEvent(inputs[i], 'focus', inputIn);
			addEvent(inputs[i], 'blur', inputOut);
		}
	}
	
	// also, let's create id's for all the labels
	labels = document.getElementsByTagName('label');
	for(i in labels) {
		if(typeof(labels[i])=='object') {
			tmp_s = labels[i].getAttribute("for");
			if(tmp_s==null) tmp_s = labels[i].getAttribute("htmlfor");
			labels[i].id = tmp_s+'Label';
		}
	}
	
	if(typeof(foundErrors)=='string' && foundErrors=='true')
		throwFormErrors();
	
	// add events for the buttons
	addEvent('vernation-button', 'click', vernationButtonClick);
	addEvent('ligule-button', 'click', liguleButtonClick);
	addEvent('auricle-button', 'click', auricleButtonClick);
	addEvent('hairs-leaf-button', 'click', hairsLeafButtonClick);
	addEvent('hairs-sheath-button', 'click', hairsSheathButtonClick);
	addEvent('leaf-tip-button', 'click', leafTipButtonClick);
	addEvent('sheath-button', 'click', sheathButtonClick);
	
	// add events to the vernation selections
	for(x in vernation_options)
	{
		if(typeof(vernation_options[x])=='string')
			addEvent('vernation-'+vernation_options[x], 'click', shapeSelect);
	}

	// add events to the ligule selections
	for(x in ligule_options)
	{
		if(typeof(ligule_options[x])=='string')
			addEvent('ligule-'+ligule_options[x], 'click', shapeSelect);
	}

	// add events to the auricle selections
	for(x in auricle_options)
	{
		if(typeof(auricle_options[x])=='string')
			addEvent('auricle-'+auricle_options[x], 'click', shapeSelect);
	}

	// add events to the hairs-leaf selections
	for(x in hairs_leaf_options)
	{
		if(typeof(hairs_leaf_options[x])=='string')
			addEvent('hairs-leaf-'+hairs_leaf_options[x], 'click', shapeSelect);
	}

	// add events to the hairs-sheath selections
	for(x in hairs_sheath_options)
	{
		if(typeof(hairs_sheath_options[x])=='string')
			addEvent('hairs-sheath-'+hairs_sheath_options[x], 'click', shapeSelect);
	}

	// add events to the leaf-tip selections
	for(x in leaf_tip_options)
	{
		if(typeof(leaf_tip_options[x])=='string')
			addEvent('leaf-tip-'+leaf_tip_options[x], 'click', shapeSelect);
	}

	// add events to the sheath selections
	for(x in sheath_options)
	{
		if(typeof(sheath_options[x])=='string')
			addEvent('sheath-'+sheath_options[x], 'click', shapeSelect);
	}


	var pics = new Array();
	// load the large images
	for(x in allWeedsGalleryName)
	{
		if(typeof(allWeedsGalleryName[x])=='string')
		{
			//pics[x]= new Image(120,90); 
			//pics[x].src = 'http://www.msuturfweeds.net/images/galleries/'+allWeedsGalleryName[x]+'/1.jpg';
			//alert(pics[x].src);
			tmp_y = 'hpic'+allWeeds[x];
			if(document.getElementById)
				obj = document.getElementById(tmp_y);
			else
				obj = document.all[tmp_y];
				
			obj.src = 'http://www.msuturfweeds.net/images/galleries/'+allWeedsGalleryName[x]+'/1.jpg';
		}
	}
	
}	// end function addFormEvents

function vernationButtonClick(i) {
	toggleFader('vernationThumbs');
}

function liguleButtonClick(i) {
	toggleFader('liguleThumbs');
}

function auricleButtonClick(i) {
	toggleFader('auricleThumbs');
}

function hairsLeafButtonClick(i) {
	toggleFader('hairs-leafThumbs');
}

function hairsSheathButtonClick(i) {
	toggleFader('hairs-sheathThumbs');
}

function leafTipButtonClick(i) {
	toggleFader('leaf-tipThumbs');
}

function sheathButtonClick(i) {
	toggleFader('sheathThumbs');
}

function resetShapeSelect(inc) {
	resetAllShapeSelects();

	if(document.getElementById)
		obj = document.getElementById(inc);
	else
		obj = document.all[inc];

	obj.className = 'cthumb-selected';

}

function shapeSelect(i) {
	resetAllShapeSelects();
	this.className = 'cthumb-selected';

	if(current_popup=='vernation')
		temp_vernation = this.id;
	else if(current_popup=='ligule')
		temp_ligule = this.id;
	else if(current_popup=='auricle')
		temp_auricle = this.id;
	else if(current_popup=='hairs-leaf')
		temp_hairs_leaf = this.id;
	else if(current_popup=='hairs-sheath')
		temp_hairs_sheath = this.id;
	else if(current_popup=='leaf-tip')
		temp_leaf_tip = this.id;
	else if(current_popup=='sheath')
		temp_sheath = this.id;
}

function resetAllShapeSelects() {

	for(x in vernation_options)
	{
		if(typeof(vernation_options[x])=='string')
		{
			tmp_name = 'vernation-'+vernation_options[x];
			tmp_obj = getObjRef(tmp_name);
			
			if(tmp_obj.className == 'cthumb-selected')
				tmp_obj.className = 'cthumb';
		}
	}

	for(x in ligule_options)
	{
		if(typeof(ligule_options[x])=='string')
		{
			tmp_name = 'ligule-'+ligule_options[x];
			tmp_obj = getObjRef(tmp_name);
			
			if(tmp_obj.className == 'cthumb-selected')
				tmp_obj.className = 'cthumb';
		}
	}

	for(x in auricle_options)
	{
		if(typeof(auricle_options[x])=='string')
		{
			tmp_name = 'auricle-'+auricle_options[x];
			tmp_obj = getObjRef(tmp_name);
			
			if(tmp_obj.className == 'cthumb-selected')
				tmp_obj.className = 'cthumb';
		}
	}

	for(x in hairs_leaf_options)
	{
		if(typeof(hairs_leaf_options[x])=='string')
		{
			tmp_name = 'hairs-leaf-'+hairs_leaf_options[x];
			tmp_obj = getObjRef(tmp_name);
			
			if(tmp_obj.className == 'cthumb-selected')
				tmp_obj.className = 'cthumb';
		}
	}

	for(x in hairs_sheath_options)
	{
		if(typeof(hairs_sheath_options[x])=='string')
		{
			tmp_name = 'hairs-sheath-'+hairs_sheath_options[x];
			tmp_obj = getObjRef(tmp_name);
			
			if(tmp_obj.className == 'cthumb-selected')
				tmp_obj.className = 'cthumb';
		}
	}

	for(x in leaf_tip_options)
	{
		if(typeof(leaf_tip_options[x])=='string')
		{
			tmp_name = 'leaf-tip-'+leaf_tip_options[x];
			tmp_obj = getObjRef(tmp_name);
			
			if(tmp_obj.className == 'cthumb-selected')
				tmp_obj.className = 'cthumb';
		}
	}

	for(x in sheath_options)
	{
		if(typeof(sheath_options[x])=='string')
		{
			tmp_name = 'sheath-'+sheath_options[x];
			tmp_obj = getObjRef(tmp_name);
			
			if(tmp_obj.className == 'cthumb-selected')
				tmp_obj.className = 'cthumb';
		}
	}


} // end function resetAllShapeSelects



function inputIn(i) {
	this.className = 'in';
}

function inputOut(i) {
	this.className = '';
}

function toggleFader(showSubName) {

	if(document.getElementById) {
		aobj = document.getElementById('all');
		fobj = document.getElementById('fader');
		pobj = document.getElementById('popup');
		s1obj = document.getElementById('vernationThumbs');
		s2obj = document.getElementById('liguleThumbs');
		s3obj = document.getElementById('auricleThumbs');
		s4obj = document.getElementById('hairs-leafThumbs');
		s5obj = document.getElementById('hairs-sheathThumbs');
		s6obj = document.getElementById('leaf-tipThumbs');
		s7obj = document.getElementById('sheathThumbs');
	}
	else {
		aobj = document.all['all'];
		fobj = document.all['fader'];
		pobj = document.all['popup'];
		s1obj = document.all['vernationThumbs'];
		s2obj = document.all['liguleThumbs'];
		s3obj = document.all['auricleThumbs'];
		s4obj = document.all['hairs-leafThumbs'];
		s5obj = document.all['hairs-sheathThumbs'];
		s6obj = document.all['leaf-tipThumbs'];
		s7obj = document.all['sheathThumbs'];
	}
	
	s1obj.style.display = 'none';
	s2obj.style.display = 'none';
	s3obj.style.display = 'none';
	s4obj.style.display = 'none';
	s5obj.style.display = 'none';
	s6obj.style.display = 'none';
	s7obj.style.display = 'none';
	current_popup = '';

	if(pobj.style.display=='none' || pobj.style.display=='unknown' || pobj.style.display=='')
	{
		pobj.style.display = 'block';
		fobj.style.display = 'block';
		fobj.style.width = aobj.clientWidth;
		fobj.style.height = aobj.clientHeight+150;
		
		//alert(aobj.clientHeight);
		
		if(showSubName=='vernationThumbs')
		{
			s1obj.style.display = 'block';
			current_popup = 'vernation';
			if(selected_vernation!='')
				resetShapeSelect('vernation-'+selected_vernation);
		}
		else if(showSubName=='liguleThumbs')
		{
			s2obj.style.display = 'block';
			current_popup = 'ligule';
			if(selected_ligule!='')
				resetShapeSelect('ligule-'+selected_ligule);
		}
		else if(showSubName=='auricleThumbs')
		{
			s3obj.style.display = 'block';
			current_popup = 'auricle';
			if(selected_auricle!='')
				resetShapeSelect('auricle-'+selected_auricle);
		}
		else if(showSubName=='hairs-leafThumbs')
		{
			s4obj.style.display = 'block';
			current_popup = 'hairs-leaf';
			if(selected_hairs_leaf!='')
				resetShapeSelect('hairs-leaf-'+selected_hairs_leaf);
		}
		else if(showSubName=='hairs-sheathThumbs')
		{
			s5obj.style.display = 'block';
			current_popup = 'hairs-sheath';
			if(selected_hairs_sheath!='')
				resetShapeSelect('hairs-sheath-'+selected_hairs_sheath);
		}
		else if(showSubName=='leaf-tipThumbs')
		{
			s6obj.style.display = 'block';
			current_popup = 'leaf-tip';
			if(selected_leaf_tip!='')
				resetShapeSelect('leaf-tip-'+selected_leaf_tip);
		}
		else if(showSubName=='sheathThumbs')
		{
			s7obj.style.display = 'block';
			current_popup = 'sheath';
			if(selected_sheath!='')
				resetShapeSelect('sheath-'+selected_sheath);
		}
	}
	else {
		pobj.style.display = 'none';
		fobj.style.display = 'none';
		s1obj.style.display = 'none';
		s2obj.style.display = 'none';
		s3obj.style.display = 'none';
		s4obj.style.display = 'none';
		s5obj.style.display = 'none';
		s6obj.style.display = 'none';
		s7obj.style.display = 'none';
	}
}

function shrinkIt(str_id) {
	new Effect.Opacity(str_id,
    { from: 1,
      to: 0,
      duration: 2,
      afterFinish: removeIt});
}

function removeIt(i) {
	if(typeof(i)=='string') {
		if(document.getElementById)
			obj = document.getElementById(i);
		else
			obj = document.all[i];
	}
	else if(typeof(i)=='object')
		obj = i.element;

	obj.style.display = 'none';
}

function growIt(str_id) {
	if(start_at==1) {
		new Effect.Morph(str_id,
    	{ style:'width:143px;height:107px',
      	duration: 2});
    }
    else if(start_at==2) {
		new Effect.Morph(str_id,
    	{ style:'width:200px;height:150px',
      	duration: 2});
    }
}

function cancelClick() {

	resetAllShapeSelects();
	
	temp_vernation = '';
	temp_ligule = '';
	temp_auricle = '';
	temp_hairs_leaf = '';
	temp_hairs_sheath = '';
	temp_leaf_tip = '';
	temp_sheath = '';

	if(selected_vernation!='')
		resetShapeSelect('vernation-'+selected_vernation);

	if(selected_ligule!='')
		resetShapeSelect('ligule-'+selected_ligule);

	if(selected_auricle!='')
		resetShapeSelect('auricle-'+selected_auricle);

	if(selected_hairs_leaf!='')
		resetShapeSelect('hairs-leaf-'+selected_hairs_leaf);

	if(selected_hairs_sheath!='')
		resetShapeSelect('hairs-sheath-'+selected_hairs_sheath);

	if(selected_leaf_tip!='')
		resetShapeSelect('leaf-tip-'+selected_leaf_tip);

	if(selected_sheath!='')
		resetShapeSelect('sheath-'+selected_sheath);

	toggleFader('');
}

function doNothing(e) {
	// wow that was exciting
}

function processSelection() {

	var something_changed = false;
	var popup_was = current_popup;
	
	toggleFader('');
	

	/*
	temp_vernation = temp_vernation.substring(temp_vernation.indexOf('-')+1);
	temp_ligule = temp_ligule.substring(temp_ligule.indexOf('-')+1);
	temp_auricle = temp_auricle.substring(temp_auricle.indexOf('-')+1);
	temp_hairs_leaf = temp_hairs_leaf.substring(temp_hairs_leaf.indexOf('-')+1);
	temp_hairs_sheath = temp_hairs_sheath.substring(temp_hairs_sheath.indexOf('-')+1);
	temp_leaf_tip = temp_leaf_tip.substring(temp_leaf_tip.indexOf('-')+1);
	temp_sheath = temp_sheath.substring(temp_sheath.indexOf('-')+1);
	*/

	temp_vernation = temp_vernation.replace("vernation-", "");
	temp_ligule = temp_ligule.replace("ligule-", "");
	temp_auricle = temp_auricle.replace("auricle-", "");
	temp_hairs_leaf = temp_hairs_leaf.replace("hairs-leaf-", "");
	temp_hairs_sheath = temp_hairs_sheath.replace("hairs-sheath-", "");
	temp_leaf_tip = temp_leaf_tip.replace("leaf-tip-", "");
	temp_sheath = temp_sheath.replace("sheath-", "");

	if(selected_vernation!=temp_vernation && temp_vernation!='') {
		something_changed = true;
		newsrc = '/images/vernation/small-' + temp_vernation + '.gif';
		imgSwapSrc('vernation-button', newsrc);
		//alert('has something changed? '+something_changed);
		//alert('temp_vernation: '+temp_vernation);
	}

	if(selected_ligule!=temp_ligule && temp_ligule!='') {
		something_changed = true;
		newsrc = '/images/ligule/small-' + temp_ligule + '.gif';
		imgSwapSrc('ligule-button', newsrc);
	}

	if(selected_auricle!=temp_auricle && temp_auricle!='') {
		something_changed = true;
		newsrc = '/images/auricle/small-' + temp_auricle + '.gif';
		imgSwapSrc('auricle-button', newsrc);
	}

	if(selected_hairs_leaf!=temp_hairs_leaf && temp_hairs_leaf!='') {
		something_changed = true;
		newsrc = '/images/hairs-leaf/small-' + temp_hairs_leaf + '.gif';
		imgSwapSrc('hairs-leaf-button', newsrc);
	}

	if(selected_hairs_sheath!=temp_hairs_sheath && temp_hairs_sheath!='') {
		something_changed = true;
		newsrc = '/images/hairs-sheath/small-' + temp_hairs_sheath + '.gif';
		imgSwapSrc('hairs-sheath-button', newsrc);
	}

	if(selected_leaf_tip!=temp_leaf_tip && temp_leaf_tip!='') {
		something_changed = true;
		newsrc = '/images/leaf-tip/small-' + temp_leaf_tip + '.gif';
		imgSwapSrc('leaf-tip-button', newsrc);
	}

	if(selected_sheath!=temp_sheath && temp_sheath!='') {
		something_changed = true;
		newsrc = '/images/sheath/small-' + temp_sheath + '.gif';
		imgSwapSrc('sheath-button', newsrc);
	}

	if(something_changed) {
		
		if(temp_vernation!='')
			selected_vernation = temp_vernation;
		selected_vernation_index = searchArray(weedIndex, selected_vernation);

		if(temp_ligule!='')
			selected_ligule = temp_ligule;
		selected_ligule_index = searchArray(weedIndex, selected_ligule);
		//alert(selected_ligule); alert(selected_ligule_index);
		
		if(temp_auricle!='')
			selected_auricle = temp_auricle;
		selected_auricle_index = searchArray(weedIndex, selected_auricle);
		
		if(temp_hairs_leaf!='')
			selected_hairs_leaf = temp_hairs_leaf;
		selected_hairs_leaf_index = searchArray(weedIndex, selected_hairs_leaf);

		if(temp_hairs_sheath!='')
			selected_hairs_sheath = temp_hairs_sheath;
		selected_hairs_sheath_index = searchArray(weedIndex, selected_hairs_sheath);

		if(temp_leaf_tip!='')
			selected_leaf_tip = temp_leaf_tip;
		selected_leaf_tip_index = searchArray(weedIndex, selected_leaf_tip);

		if(temp_sheath!='')
			selected_sheath = temp_sheath;
		selected_sheath_index = searchArray(weedIndex, selected_sheath);

			
		var weedsToRemove = new Array();
		var weedsToKeep = new Array();
		var newKeyCount = new Array();

		var z = 0;
		if(selected_vernation_index!=-1 || selected_ligule_index!=-1 || selected_auricle_index!=-1 || selected_hairs_leaf_index!=-1 || selected_hairs_sheath_index!=-1 || selected_leaf_tip_index!=-1 || selected_sheath_index!=-1) {
			for(x in allWeeds) {
				if(typeof(allWeeds[x])=='number') {

					if(selected_vernation_index!=-1)
						tmp_vernation_found_x = searchArray(weedKeys[selected_vernation_index], allWeeds[x]);
					else
						tmp_vernation_found_x = 9999;

					if(selected_ligule_index!=-1)
						tmp_ligule_found_x = searchArray(weedKeys[selected_ligule_index], allWeeds[x]);
					else
						tmp_ligule_found_x = 9999;

					if(selected_auricle_index!=-1)
						tmp_auricle_found_x = searchArray(weedKeys[selected_auricle_index], allWeeds[x]);
					else
						tmp_auricle_found_x = 9999;

					if(selected_hairs_leaf_index!=-1)
						tmp_hairs_leaf_found_x = searchArray(weedKeys[selected_hairs_leaf_index], allWeeds[x]);
					else
						tmp_hairs_leaf_found_x = 9999;

					if(selected_hairs_sheath_index!=-1)
						tmp_hairs_sheath_found_x = searchArray(weedKeys[selected_hairs_sheath_index], allWeeds[x]);
					else
						tmp_hairs_sheath_found_x = 9999;

					if(selected_leaf_tip_index!=-1)
						tmp_leaf_tip_found_x = searchArray(weedKeys[selected_leaf_tip_index], allWeeds[x]);
					else
						tmp_leaf_tip_found_x = 9999;

					if(selected_sheath_index!=-1)
						tmp_sheath_found_x = searchArray(weedKeys[selected_sheath_index], allWeeds[x]);
					else
						tmp_sheath_found_x = 9999;


					if( (tmp_vernation_found_x!=-1 || tmp_vernation_found_x==9999) && (tmp_ligule_found_x!=-1 || tmp_ligule_found_x==9999) && (tmp_auricle_found_x!=-1 || tmp_auricle_found_x==9999) && (tmp_hairs_leaf_found_x!=-1 || tmp_hairs_leaf_found_x==9999) && (tmp_hairs_sheath_found_x!=-1 || tmp_hairs_sheath_found_x==9999) && (tmp_leaf_tip_found_x!=-1 || tmp_leaf_tip_found_x==9999) && (tmp_sheath_found_x!=-1 || tmp_sheath_found_x==9999) ) {
						tmp_weed_id = allWeeds[x];
						weedsToKeep[z] = x;
						z++;
					}
					//else alert('could not find '+allWeeds[x]+' in: '+weedKeys[selected_shape_index]);
				}
			}
		}

				
		var useThumbs = true;
		
		// decide on the size of thumbnails
		if(weedsToKeep.length >= 30) {
			thumbWidth = 100;
			thumbHeight = 75;
			paddNum = 0;
		} else if(weedsToKeep.length >= 10) {
			thumbWidth = 186;
			thumbHeight = 140;
			useThumbs = false;
			paddNum = 1;
		} else {
			thumbWidth = 250;
			thumbHeight = 188;
			useThumbs = false;
			paddNum = 2;
		}
		
		// now create the new html table
		var newhtml = '<div>';
		for(x in weedsToKeep) {
			if(typeof(weedsToKeep[x])=='string' || typeof(weedsToKeep[x])=='number') {
				
				tmp_index = weedsToKeep[x];
				newhtml += '<a href="/details/_/'+allWeedsLinkName[tmp_index]+'_'+allWeeds[tmp_index]+'/'+'" onmouseover="Tip(\''+allWeedsTipName[tmp_index]+'\')"><img src="/images/galleries/'+allWeedsGalleryName[tmp_index]+'/'+allWeedsGalleryID[tmp_index];
				if(useThumbs) newhtml += '.thumb';
				newhtml += '.jpg" width="'+thumbWidth+'" height="'+thumbHeight+'" class="weed-flex-thumb';
				if(paddNum==1 || paddNum==2) newhtml += paddNum;
				newhtml += '" border="0"></a>';

				for(wk in weedKeys) {
					ww = allWeeds[(weedsToKeep[x])];
					//alert('search for: '+ww+' in '+weedIndex[wk]);
					tmp_zz_index = searchArray(weedKeys[wk], ww);
					if(tmp_zz_index!=-1) {
						
						if(typeof(newKeyCount[wk])=='undefined')
							newKeyCount[wk] = 1;
						else
							newKeyCount[wk] = newKeyCount[wk] + 1;
						
						//alert('we are keeping '+ww+' and we found it in '+weedIndex[wk]);
						//alert('new count: '+newKeyCount[wk]);
					}
				}
			}
		}
		newhtml += '</div>';
		
		/* comment out on 9/1/08 -- not sure what this would be for??
		spreadingBB = getObjRef('habit-spreading');
		spreadingKey = searchArray(weedIndex, 'spreading');
		uprightBB = getObjRef('habit-upright');
		uprightKey = searchArray(weedIndex, 'upright');
		clumpBB = getObjRef('habit-clump');
		clumpKey = searchArray(weedIndex, 'clump');
		*/
		
		/*
		if(selected_habit_index==-1)
		{	// no habit selected, so keep the tooltips
			if(typeof(newKeyCount[spreadingKey])=='undefined')
				addEvent(spreadingBB, 'mouseover', function te(t){Tip("No matches found...")});
			else
				addEvent(spreadingBB, 'mouseover', function te(t){Tip("Narrows to "+newKeyCount[spreadingKey]+"...")});
			
			if(typeof(newKeyCount[uprightKey])=='undefined')
				addEvent(uprightBB, 'mouseover', function te(t){Tip("No matches found...")});
			else
				addEvent(uprightBB, 'mouseover', function te(t){Tip("Narrows to "+newKeyCount[uprightKey]+"...")});
			
			if(typeof(newKeyCount[clumpKey])=='undefined')
				addEvent(clumpBB, 'mouseover', function te(t){Tip("No matches found...")});
			else
				addEvent(clumpBB, 'mouseover', function te(t){Tip("Narrows to "+newKeyCount[clumpKey]+"...")});
		}
		else
		{	// habit IS selected, so clear the tooltips
			addEvent(spreadingBB, 'mouseover', function ze(t){} );
			//removeEvent(spreadingBB, 'mouseover');
			spreadingBB.onmouseover = '';
			
			addEvent(uprightBB, 'mouseover', function ze(t){} );
			//removeEvent(uprightBB, 'mouseover');
			uprightBB.onmouseover = '';
			
			addEvent(clumpBB, 'mouseover', function ze(t){} );
			//removeEvent(clumpBB, 'mouseover');
			clumpBB.onmouseover = '';
		}*/
		
		for(i in options_array)
		{
			if(typeof(options_array[i])=='string')
			{
				tmp_str = 'tmp_arry = '+options_array[i]+'_options;';
				tmp_str = tmp_str.replace('-', '_');
				//alert(tmp_str);
				eval(tmp_str);

				if(typeof(tmp_arry)=='object')
				{

					for(j in tmp_arry)
					{
						if(typeof(tmp_arry[j])=='string')
						{
							jtmp_key_name = searchArray(weedIndex, tmp_arry[j]);
							
							jtmp_obj = getObjRef(options_array[i]+'-'+tmp_arry[j]);
						
							if( (selected_vernation_index==-1 && options_array[i]=='vernation') || (selected_ligule_index==-1 && options_array[i]=='ligule') || (selected_auricle_index==-1 && options_array[i]=='auricle') || (selected_hairs_leaf_index==-1 && options_array[i]=='hairs-leaf') || (selected_hairs_sheath_index==-1 && options_array[i]=='hairs-sheath') || (selected_leaf_tip_index==-1 && options_array[i]=='leaf-tip') || (selected_sheath_index==-1 && options_array[i]=='sheath') )
							{
							
								if(typeof(newKeyCount[jtmp_key_name])=='undefined')
								{
									addEvent(jtmp_obj, 'mouseover', function(){Tip("No matches found...")});
									jtmp_obj.className = 'cthumb-fade';
									//alert('FADE OUT for '+jtmp_key_name+': '+options_array[i]);
								}
								else
								{
									eval('addEvent(jtmp_obj, \'mouseover\', function(){Tip("Narrows to '+newKeyCount[jtmp_key_name]+'...")});');
									jtmp_obj.className = 'cthumb';
									//alert('new count for '+jtmp_key_name+': '+newKeyCount[jtmp_key_name]+' ... '+options_array[i]);
								}
							}
							else
							{
							  //alert('skipping? '+options_array[i]);
								addEvent(jtmp_obj, 'mouseover', function(){} );
								eval('addEvent(jtmp_obj, \'mouseover\', function(){Tip("")})');
								jtmp_obj.onmouseover = '';
								//jtmp_obj.style.border = '1px solid red';
								jtmp_obj.className = 'cthumb';
							}
							//break;
						}
					}
				}
			}
		}
		
		// selected_shape_index!=-1 || selected_margin_index!=-1 || selected_arrangement_index!=-1 || selected_color_index!=-1) {

		if(document.getElementById) {
			oldobj = document.getElementById('visibleweeds');
			newobj = document.getElementById('invisibleweeds');
			startoverobj = document.getElementById('startover');
		} else {
			oldobj = document.all['visibleweeds'];
			newobj = document.all['invisibleweeds'];
			startoverobj = document.all['startover'];
		}

		newobj.innerHTML = newhtml;
		
		Effect.DropOut('visibleweeds');
		//newobj.style.display = 'block';
		Effect.Appear('invisibleweeds');
		
		startoverobj.style.display = 'block';
		//Effect.Appear('startoverobj');
		
		// switch the id's
		newobj.id = 'tmpvisibleweeds';
		oldobj.id = 'invisibleweeds';
		newobj.id = 'visibleweeds';
		
		//alert('newobj.id: '+newobj.id);
		//alert('oldobj.id: '+oldobj.id);
		
	}	// end if something changed
}

String.prototype.toProperCase = function(){
     return this.toLowerCase().replace(/\w+/g,function(s){
          return s.charAt(0).toUpperCase() + s.substr(1);
     })
}

function getObjRef(ostr)
{
	if(document.getElementById)
		return document.getElementById(ostr);
	else
		return document.all[ostr];
}

function exampleF(i) {

            
	if(start_at==1) {
	    shrinkIt('w1');
	    shrinkIt('w3');
	    shrinkIt('w5');
	    shrinkIt('w6');
	    shrinkIt('w7');
	    shrinkIt('w8');
	    shrinkIt('w9');
	    shrinkIt('w11');
	    shrinkIt('w14');
	    shrinkIt('w15');
	    shrinkIt('w16');
	    shrinkIt('w17');
	    shrinkIt('w18');
	    shrinkIt('w19');
	    shrinkIt('w20');
	    shrinkIt('w21');
	    shrinkIt('w22');
	    shrinkIt('w23');
	    shrinkIt('w25');
	    shrinkIt('w26');
	    shrinkIt('w27');
	    shrinkIt('w28');
	    shrinkIt('w29');
	    shrinkIt('w30');
	    shrinkIt('w31');
	    shrinkIt('w32');
	    shrinkIt('w33');
	    shrinkIt('w36');
	    shrinkIt('w37');
	    shrinkIt('w38');
    
	   	new Effect.Opacity('w39',
	    { from: 1,
      	to: 0,
      	duration: 2,
      	afterFinish: exampleF2 });
	}
	
	else if(start_at==2) {
	    shrinkIt('w12');
	    shrinkIt('w13');
	    shrinkIt('w35');
	    
	   	new Effect.Opacity('w34',
	    { from: 1,
      	to: 0,
      	duration: 2,
      	afterFinish: exampleF2 });
	}
	
}

function exampleF2(i) {

	if(start_at==1) {
		removeIt('w1');
		growIt('w2');
		growIt('w4');
    	growIt('w10');
    	growIt('w24');
    	growIt('w13');
	    growIt('w34');
    	growIt('w35');
    	growIt('w12');
	}
	else if(start_at==2) {
		removeIt('w34');
		growIt('w2');
		growIt('w4');
    	growIt('w10');
    	growIt('w24');
	}
	
	start_at++;

	if(document.getElementById)
		tobj = document.getElementById('test');
	else
		tobj = document.all['test'];
		
	tobj.innerHTML = '<p><b>Click here again to test the next level...</b></p>';

}

function labelAddClass(l, append) {
	
	if(typeof(l)=='string')
	{
		if(document.getElementById)
			obj = document.getElementById(l);
		else
			obj = document.all[l];
	}
	else if(typeof(l)=='object')
		obj = l;
		
	if(typeof(obj)=='object')
	{
		obj.className = obj.className + ' ' + append;
	}
}


function imgSwapSrc(i, newsrc) {
	if(document.getElementById)
		obj = document.getElementById(i);
	else
		obj = document.all[i];

	obj.src = newsrc;
}

function searchArray(arr, toFind) {
	if(arr.constructor != Array)
		return -1;

	for(var i = 0, len = arr.length; i < len; i++)
	{
		if(arr[i].constructor == Array)
		{
			if(searchArray(arr[i], toFind)!=-1)
				return i;
		}
		else if(arr[i] == toFind)
		{
			return i;
		}
	}
	return -1;
}