
var options_array = new Array();
options_array[0] = 'habit';
options_array[1] = 'shape';
options_array[2] = 'margin';
options_array[3] = 'arrangement';
options_array[4] = 'color';

var start_at = 1;

var habit_options = new Array();
habit_options[0] = 'spreading';
habit_options[1] = 'upright';
habit_options[2] = 'clump';

var shape_options = new Array();
shape_options[0] = 'linear';
shape_options[1] = 'lanceolate';
shape_options[2] = 'oval';
shape_options[3] = 'ovate';
shape_options[4] = 'round';
shape_options[5] = 'elongated';
shape_options[6] = 'heartspade';

var margin_options = new Array();
margin_options[0] = 'entire';
margin_options[1] = 'lobed';
margin_options[2] = 'notches';
margin_options[3] = 'pinnatifid';
margin_options[4] = 'serrate';
margin_options[5] = 'wavy';

var arrangement_options = new Array();
arrangement_options[0] = 'opposite';
arrangement_options[1] = 'alternate';
arrangement_options[2] = 'whorled';
arrangement_options[3] = 'trifoliate';

var color_options = new Array();
color_options[0] = 'red';
color_options[1] = 'yellow';
color_options[2] = 'orange';
color_options[3] = 'white';
color_options[4] = 'blue';
color_options[5] = 'purple';
color_options[6] = 'brown';
color_options[7] = 'pink';
color_options[8] = 'green';
color_options[9] = 'gray';

var selected_habit = '';
var selected_shape = '';
var selected_margin = '';
var selected_arrangement = '';
var selected_color = '';

var temp_habit = '';
var temp_shape = '';
var temp_margin = '';
var temp_arrangement = '';
var temp_color = '';

var current_popup = '';

function addEvent( obj, type, fn ) {
	if(typeof(obj)=='string') {
		if(document.getElementById)
			obj = document.getElementById(obj);
		else
			obj = document.all[obj];
	}
	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 );
	}
}

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('habit-button', 'click', habitButtonClick);
	addEvent('shape-button', 'click', shapeButtonClick);
	addEvent('margin-button', 'click', marginButtonClick);
	addEvent('arrangement-button', 'click', arrangementButtonClick);
	addEvent('color-button', 'click', colorButtonClick);
	
	// add events to the habit selections
	for(x in habit_options)
	{
		if(typeof(habit_options[x])=='string')
			addEvent('habit-'+habit_options[x], 'click', shapeSelect);
	}

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

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

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

	// add events to the color selections
	for(x in color_options)
	{
		if(typeof(color_options[x])=='string')
			addEvent('color-'+color_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 habitButtonClick(i) {
	toggleFader('habitThumbs');
}

function shapeButtonClick(i) {
	toggleFader('shapeThumbs');
}

function marginButtonClick(i) {
	toggleFader('marginThumbs');
}

function arrangementButtonClick(i) {
	toggleFader('arrangementThumbs');
}

function colorButtonClick(i) {
	toggleFader('colorThumbs');
}


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=='shape')
		temp_shape = this.id;
	else if(current_popup=='margin')
		temp_margin = this.id;
	else if(current_popup=='arrangement')
		temp_arrangement = this.id;
	else if(current_popup=='habit')
		temp_habit = this.id;
	else if(current_popup=='color')
		temp_color = this.id;
}

function resetAllShapeSelects() {

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

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

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

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

	for(x in color_options)
	{
		if(typeof(color_options[x])=='string')
		{
			tmp_name = 'color-'+color_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('shapeThumbs');
		s2obj = document.getElementById('marginThumbs');
		s3obj = document.getElementById('arrangementThumbs');
		s4obj = document.getElementById('habitThumbs');
		s5obj = document.getElementById('colorThumbs');
	}
	else {
		aobj = document.all['all'];
		fobj = document.all['fader'];
		pobj = document.all['popup'];
		s1obj = document.all['shapeThumbs'];
		s2obj = document.all['marginThumbs'];
		s3obj = document.all['arrangementThumbs'];
		s4obj = document.all['habitThumbs'];
		s5obj = document.all['colorThumbs'];
	}
	
	s1obj.style.display = 'none';
	s2obj.style.display = 'none';
	s3obj.style.display = 'none';
	s4obj.style.display = 'none';
	s5obj.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=='shapeThumbs')
		{
			s1obj.style.display = 'block';
			current_popup = 'shape';
			if(selected_shape!='')
				resetShapeSelect('shape-'+selected_shape);
		}
		else if(showSubName=='marginThumbs')
		{
			s2obj.style.display = 'block';
			current_popup = 'margin';
			if(selected_margin!='')
				resetShapeSelect('margin-'+selected_margin);
		}
		else if(showSubName=='arrangementThumbs')
		{
			s3obj.style.display = 'block';
			current_popup = 'arrangement';
			if(selected_arrangement!='')
				resetShapeSelect('arrangement-'+selected_arrangement);
		}
		else if(showSubName=='habitThumbs')
		{
			s4obj.style.display = 'block';
			current_popup = 'habit';
			if(selected_habit!='')
				resetShapeSelect('habit-'+selected_habit);
		}
		else if(showSubName=='colorThumbs')
		{
			s5obj.style.display = 'block';
			current_popup = 'color';
			if(selected_color!='')
			{
				resetShapeSelect('color-'+selected_color);
			}
		}
	}
	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';
	}
}

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_habit = '';
	temp_shape = '';
	temp_margin = '';
	temp_arrangement = '';
	temp_color = '';

	if(selected_habit!='')
		resetShapeSelect('habit-'+selected_habit);

	if(selected_shape!='')
		resetShapeSelect('shape-'+selected_shape);

	if(selected_margin!='')
		resetShapeSelect('margin-'+selected_margin);
	
	if(selected_arrangement!='')
		resetShapeSelect('arrangement-'+selected_arrangement);

	if(selected_color!='')
		resetShapeSelect('color-'+selected_color);

	toggleFader('');
}

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

function processSelection() {

	var something_changed = false;
	var popup_was = current_popup;
	
	toggleFader('');
	
	temp_habit = temp_habit.substring(temp_habit.indexOf('-')+1);
	temp_shape = temp_shape.substring(temp_shape.indexOf('-')+1);
	temp_margin = temp_margin.substring(temp_margin.indexOf('-')+1);
	temp_arrangement = temp_arrangement.substring(temp_arrangement.indexOf('-')+1);
	temp_color = temp_color.substring(temp_color.indexOf('-')+1);
	
	if(selected_shape!=temp_shape && temp_shape!='') {
		something_changed = true;
		newsrc = '/images/leaf-shape/small-' + temp_shape + '.gif';
		imgSwapSrc('shape-button', newsrc);
		//alert('has something changed? '+something_changed);
		//alert('temp_shape: '+temp_shape);
	}
		
	if(selected_margin!=temp_margin && temp_margin!='') {
		something_changed = true;
		newsrc = '/images/leaf-margin/small-' + temp_margin + '.gif';
		imgSwapSrc('margin-button', newsrc);
	}
		
	if(selected_arrangement!=temp_arrangement && temp_arrangement!='') {
		something_changed = true;
		newsrc = '/images/leaf-arrangement/small-' + temp_arrangement + '.gif';
		imgSwapSrc('arrangement-button', newsrc);
	}

	if(selected_habit!=temp_habit && temp_habit!='') {
		something_changed = true;
		newsrc = '/images/habit/small-' + temp_habit + '.gif';
		imgSwapSrc('habit-button', newsrc);
	}

	if(selected_color!=temp_color && temp_color!='') {
		something_changed = true;
		newsrc = '/images/flower	-color/small-' + temp_color + '.gif';
		imgSwapSrc('color-button', newsrc);
	}

	if(something_changed) {
		
		if(temp_habit!='')
			selected_habit = temp_habit;
		if(temp_shape!='')
			selected_shape = temp_shape;
		if(temp_margin!='')
			selected_margin = temp_margin;
		if(temp_arrangement!='')
			selected_arrangement = temp_arrangement;
		if(temp_color!='')
			selected_color = temp_color;
			
		//alert('selected_shape: '+selected_shape);

		selected_habit_index = searchArray(weedIndex, selected_habit);
		selected_shape_index = searchArray(weedIndex, selected_shape);
		selected_margin_index = searchArray(weedIndex, selected_margin);
		selected_arrangement_index = searchArray(weedIndex, selected_arrangement);
		selected_color_index = searchArray(weedIndex, selected_color);

		//alert('selected_shape_selection, _index: '+selected_shape+', '+selected_shape_index);

		/*
		alert('selected_habit_selection, _index: '+selected_habit+', '+selected_habit_index);
		alert('selected_shape_selection, _index: '+selected_shape+', '+selected_shape_index);
		alert('selected_margin_selection, _index: '+selected_margin+', '+selected_margin_index);
		alert('selected_arrangement_selection, _index: '+selected_arrangement+', '+selected_arrangement_index);
		alert('selected_color_selection, _index: '+selected_color+', '+selected_color_index);
		*/
			
		var weedsToRemove = new Array();
		var weedsToKeep = new Array();
		var newKeyCount = new Array();

		var z = 0;
		if(selected_habit_index!=-1 || selected_shape_index!=-1 || selected_margin_index!=-1 || selected_arrangement_index!=-1 || selected_color_index!=-1) {
			for(x in allWeeds) {
				if(typeof(allWeeds[x])=='number') {

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

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

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

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

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

					if( (tmp_habit_found_x!=-1 || tmp_habit_found_x==9999) && (tmp_shape_found_x!=-1 || tmp_shape_found_x==9999) && (tmp_margin_found_x!=-1 || tmp_margin_found_x==9999) && (tmp_arrangement_found_x!=-1 || tmp_arrangement_found_x==9999) && (tmp_color_found_x!=-1 || tmp_color_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>';
		
		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;';
				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_habit_index==-1 && options_array[i]=='habit') ||  (selected_shape_index==-1 && options_array[i]=='shape') ||  (selected_margin_index==-1 && options_array[i]=='margin') ||  (selected_arrangement_index==-1 && options_array[i]=='arrangement'))
							{
							
								if(typeof(newKeyCount[jtmp_key_name])=='undefined')
								{
									addEvent(jtmp_obj, 'mouseover', function(){Tip("No matches found...")});
									jtmp_obj.className = 'cthumb-fade';
								}
								else
								{
									eval('addEvent(jtmp_obj, \'mouseover\', function(){Tip("Narrows to '+newKeyCount[jtmp_key_name]+'...")});');
									jtmp_obj.className = 'cthumb';
								}
							}
							else if(selected_color_index==-1 && options_array[i]=='color')
							{
								tmpColorName = tmp_arry[j].toProperCase();
								if(typeof(newKeyCount[jtmp_key_name])=='undefined')
								{
									eval('addEvent(jtmp_obj, \'mouseover\', function(){Tip("'+tmpColorName+'; No matches found...")});');
									jtmp_obj.className = 'cthumb-fade';
								}
								else
								{
									eval('addEvent(jtmp_obj, \'mouseover\', function(){Tip("'+tmpColorName+'; Narrows to '+newKeyCount[jtmp_key_name]+'...")});');
									jtmp_obj.className = 'cthumb';
								}
							}
							else
							{
								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;
}