window.addEvent('domready', function() {

	$$('#myForm select').addEvent('change', function(e) {
		e.stop();
		var log = $('log_res').empty().addClass('ajax-loading');
		
		$('searchType2').setProperty('checked','checked');
		$('searchType1').removeProperty('checked');
		$('wordSearch').setProperty('value','');
		
		//paginationInfoRequest();
		//$('myForm').set('send', {onComplete: function(response) { 
		//	//alert(response);
		//	var myObject = JSON.decode(response); //returns: {apple: 'red', lemon: 'yellow'}
		//	var HOPE=response;
		//	log.removeClass('ajax-loading');
		//	listPlantsAccord(myObject);
		//	//clearAccordPre();
		//}});
		//$('myForm').send();
		clearAccordPre();
		getDataNotForm();
		
	});
	
	
	$('logoImage').addEvent('mouseover', function(e) {
		$('logoImage').set('src','_images/logo-back-r.gif');			
	});
	
	$('logoImage').addEvent('mouseout', function(e) {
		$('logoImage').set('src','_images/logo-back.gif');			
	});
	
	
	var paginationInfoRequest = function() {
		//var headline = new Element('h3', {'class': 'toggler', 'html': HOPE}).inject(log1);
		//alert('_ajax/ajax.asp?submitBy=pagination&region=' + $('regionField').get('value')  + '&zone=' + $('zoneField').get('value') + '&category=' + $('categoryField').get('value') + '&persistence=' + $('persistenceField').get('value') + '&size=' + $('sizeField').get('value') + '&wordSearch=' + $('wordSearch').get('value'));
		var request = new Request.JSON({
			url: '_ajax/ajax.asp?submitBy=pagination&region=' + $('regionField').get('value')  + '&zone=' + $('zoneField').get('value') + '&category=' + $('categoryField').get('value') + '&persistence=' + $('persistenceField').get('value') + '&size=' + $('sizeField').get('value') + '&wordSearch=' + $('wordSearch').get('value'),
			onComplete: function(jsonObj) {
				//alert('_ajax/ajax.asp?submitBy=pagination&region=' + $('regionField').get('value')  + '&zone=' + $('zoneField').get('value') + '&category=' + $('categoryField').get('value') + '&persistence=' + $('persistenceField').get('value') + '&size=' + $('sizeField').get('value') + '&wordSearch=' + $('wordSearch').get('value'));
				//log.empty();
				//log.removeClass('ajax-loading');
				paginationBuildMenu(jsonObj);
				//clearAccordPre();
			}
			}).send();
	};
	
	var paginationBuildMenu = function(paginationInfo) {
		var paginationTop = $('paginationTop');
		var paginationBottom = $('paginationBottom');
		//var headline = new Element('h3', {'class': 'toggler', 'html': HOPE}).inject(log1);
		paginationTop.empty();
		paginationBottom.empty();
		paginationInfo.each(function(paginationInfo, index) {
		var paginationTotal = paginationInfo.totalPages;
		//alert(paginationTotal);
			//var menu = new Element('table', {'width': '540', 'class': 'notToggler', 'html': paginationInfo.totalRecords + ' ' + paginationInfo.totalPages}).inject(pagination);
		if (paginationInfo.totalRecords == '0'){
		
			var str='';
			str+='<table width="560" border="0" cellspacing="0" cellpadding="0" CLASS="expanded">';
			str+='	<tr>';
			str+='		<td align="center"><b>Your search did not return any results, please try adjusting your search terms.</b><\/td>';
			str+='	<\/tr>';
			str+='<\/table>';
			
			var strBottom='';
			
		}else{
			
			
			var str='';
			str+='<TABLE CLASS="expanded" CELLPADDING="0" CELLSPACING="0" BORDER="0">';
			str+='<TR VALIGN="top">';
			str+='<TD CLASS="results-number">';
			str+= paginationInfo.totalRecords + ' results, ' + paginationInfo.totalPages + ' pages';
			str+='<\/TD>';
			str+='<TD CLASS="results-pages" align="right">';
			if (parseInt($('pageNumber').get('value')) != 1){
				str+='<A CLASS="quiet" HREF="#" id="previousButton"><IMG id="backArrow" NAME="arrow-back" CLASS="arrow" SRC="_images\/arrow-back.gif" WIDTH="20" HEIGHT="15" BORDER="0"><\/A>';
			}
			str+=' ';
			if (paginationInfo.totalPages != parseInt($('pageNumber').get('value'))){
				str+='<A CLASS="quiet" HREF="#" id="nextButton"><IMG id="nextArrow" NAME="arrow-forward" CLASS="arrow" SRC="_images\/arrow-forward.gif" WIDTH="20" HEIGHT="15" BORDER="0"><\/A>';
			}
			str+='<\/TD>';
			str+='<\/TR>';
			str+='<\/TABLE>';
			
			var strBottom='';
			strBottom+='<TABLE CLASS="expanded" CELLPADDING="0" CELLSPACING="0" BORDER="0">';
			strBottom+='<TR VALIGN="top">';
			strBottom+='<TD CLASS="results-number">';
			strBottom+= paginationInfo.totalRecords + ' results, ' + paginationInfo.totalPages + ' pages';
			strBottom+='<\/TD>';
			strBottom+='<TD CLASS="results-pages" align="right">';
			if (parseInt($('pageNumber').get('value')) != 1){
				strBottom+='<A CLASS="quiet" HREF="#" id="previousButtonBottom"><IMG id="backArrowBottom" NAME="arrow-back" CLASS="arrow" SRC="_images\/arrow-back.gif" WIDTH="20" HEIGHT="15" BORDER="0"><\/A>';
			}
			strBottom+=' ';
			if (paginationInfo.totalPages != parseInt($('pageNumber').get('value'))){
				strBottom+='<A CLASS="quiet" HREF="#" id="nextButtonBottom"><IMG id="nextArrowBottom" NAME="arrow-forward" CLASS="arrow" SRC="_images\/arrow-forward.gif" WIDTH="20" HEIGHT="15" BORDER="0"><\/A>';
			}
			strBottom+='<\/TD>';
			strBottom+='<\/TR>';
			strBottom+='<\/TABLE>';
			
		}
		
		
		
		paginationTop.set('html', str);
		paginationBottom.set('html', strBottom);
		//alert(paginationTotal);
		if (paginationTotal != parseInt($('pageNumber').get('value')) && paginationInfo.totalRecords != '0'){
		//alert("yes");
			$('nextButton').addEvent('click', function(e) {
			e.stop();
			nextPage = parseInt($('pageNumber').get('value')) + 1;
			//alert(nextPage);
			$('pageNumber').set('value', nextPage);
			//alert($('pageNumber').get('value'));
			getDataNotForm();
		
			});
			$('nextButton').addEvent('mouseover', function(e) {
				$('nextArrow').set('src','_images/arrow-forward-r.gif');
			});
			$('nextButton').addEvent('mouseout', function(e) {
				$('nextArrow').set('src','_images/arrow-forward.gif');
			});
		}
		
		if (parseInt($('pageNumber').get('value')) != 1 && paginationInfo.totalRecords != '0'){
			$('previousButton').addEvent('click', function(e) {
			e.stop();
			previousPage = parseInt($('pageNumber').get('value')) - 1;
			//alert(previousPage);
			$('pageNumber').set('value', previousPage);
			//alert($('pageNumber').get('value'));
			getDataNotForm();
	
			});
			
			$('previousButton').addEvent('mouseover', function(e) {
				$('backArrow').set('src','_images/arrow-back-r.gif');
			});
			$('previousButton').addEvent('mouseout', function(e) {
				$('backArrow').set('src','_images/arrow-back.gif');
			});
		}
		
		if (paginationTotal != parseInt($('pageNumber').get('value')) && paginationInfo.totalRecords != '0'){
		//alert("yes");
			$('nextButtonBottom').addEvent('click', function(e) {
			e.stop();
			nextPage = parseInt($('pageNumber').get('value')) + 1;
			//alert(nextPage);
			$('pageNumber').set('value', nextPage);
			//alert($('pageNumber').get('value'));
			getDataNotForm();
		
			});
			$('nextButtonBottom').addEvent('mouseover', function(e) {
				$('nextArrowBottom').set('src','_images/arrow-forward-r.gif');
			});
			$('nextButtonBottom').addEvent('mouseout', function(e) {
				$('nextArrowBottom').set('src','_images/arrow-forward.gif');
			});
		}
		
		if (parseInt($('pageNumber').get('value')) != 1 && paginationInfo.totalRecords != '0'){
			$('previousButtonBottom').addEvent('click', function(e) {
			e.stop();
			previousPage = parseInt($('pageNumber').get('value')) - 1;
			//alert(previousPage);
			$('pageNumber').set('value', previousPage);
			//alert($('pageNumber').get('value'));
			getDataNotForm();
	
			});
			
			$('previousButtonBottom').addEvent('mouseover', function(e) {
				$('backArrowBottom').set('src','_images/arrow-back-r.gif');
			});
			$('previousButtonBottom').addEvent('mouseout', function(e) {
				$('backArrowBottom').set('src','_images/arrow-back.gif');
			});
		}
		});
		
	};
	
	
	var sortSetRequest = function() {
		//var headline = new Element('h3', {'class': 'toggler', 'html': HOPE}).inject(log1);
		var sortDiv = $('sort');
		
		if ($('sortVar').get('value') == 'common'){
			var currentSort = 'Botanical Name';
			var currentSortHref = 'latin';
		}else{
			var currentSort = 'Common Name';
			var currentSortHref = 'common';
		}
		
		$('sortLinkText').set('html',currentSort);
		$('changeSort').set('href',currentSortHref);
							
		var	latinLink = '<a href="latin" id="changeSortLatin">Botanical Name</a>';
		var	commonLink = '<a href="common" id="changeSortCommon">Common Name</a>';
	
		
	};
	
	$('changeSort').addEvent('click', function(e) {
			e.stop();
			if (($('searchType1').get('checked') == true && $('wordSearch').get('value').length > 3) || ($('searchType2').get('checked') == true && ($('regionField').get('value') != '' || $('zoneField').get('value') != '' || $('categoryField').get('value') != '' || $('persistenceField').get('value') != '' || $('sizeField').get('value') != '' || $('wordSearch').get('value').length > 0))){
			if ($('sortVar').get('value') == 'latin'){
				
				$('sortVar').set('value', 'common');
				
				 $('sortLinkText').set('html','Common Name');
				 $('changeSort').set('href', 'common');
				 
			 }else{
			 
			 
				 $('sortVar').set('value', 'latin');
				 $('sortLinkText').set('html','Latin Name');
				 $('changeSort').set('href', 'latin');
				 
			 }
			
				getDataNotForm();
			}
			
			});
	
	
	var getDataNotForm = function() {
		//$('welcomeContent').set('html', '');
		//$('welcomeToggle').set('html', "Colapse All");
		
		
		var log = $('log_res').empty();
		log.addClass('ajax-loading');
		sortSetRequest();
		paginationInfoRequest();
		//alert($('searchType2').get('checked'));
		if ($('searchType2').get('checked') == true){
			//alert('_ajax/ajax.asp?submitBy=wordSearch&pageNumber=' + $('pageNumber').get('value') + '&region=' + $('regionField').get('value')  + '&zone=' + $('zoneField').get('value') + '&category=' + $('categoryField').get('value') + '&persistence=' + $('persistenceField').get('value') + '&size=' + $('sizeField').get('value') + '&wordSearch=' + $('wordSearch').get('value') + '&sortVar=' + $('sortVar').get('value'))		
			var request = new Request.JSON({
			url: '_ajax/ajax.asp?submitBy=wordSearch&pageNumber=' + $('pageNumber').get('value') + '&region=' + $('regionField').get('value')  + '&zone=' + $('zoneField').get('value') + '&category=' + $('categoryField').get('value') + '&persistence=' + $('persistenceField').get('value') + '&size=' + $('sizeField').get('value') + '&wordSearch=' + $('wordSearch').get('value') + '&sortVar=' + $('sortVar').get('value'),
			
			onComplete: function(jsonObj) {
				log.empty();
				log.removeClass('ajax-loading');
				listPlantsAccord(jsonObj);
				//clearAccordPre();
			}
			}).send();
		}
	
		if ($('searchType1').get('checked') == true){
			
			//alert('_ajax/ajax.asp?submitBy=wordSearchFull&wordSearch=' + $('wordSearch').get('value') + '&pageNumber=' + $('pageNumber').get('value') + '&sortVar=' + $('sortVar').get('value'))
			var request = new Request.JSON({
			url: '_ajax/ajax.asp?submitBy=wordSearchFull&wordSearch=' + $('wordSearch').get('value') + '&pageNumber=' + $('pageNumber').get('value') + '&sortVar=' + $('sortVar').get('value'),
			onComplete: function(jsonObj) {
				log.empty();
				log.removeClass('ajax-loading');
				listPlantsAccord(jsonObj);
				//clearAccordPre();
			}
			}).send();
		}
		//req.send();
	};
	
	
	
	
	
	
	
	$('wordSearch').addEvent('keyup', function(e) {
		//alert(e.key);
		if (e.key == 'enter'){
			e.stop();
		}
		if (e.key.length == 1 || e.key == 'backspace' || e.key == 'delete'){
			if ($('wordSearch').get('value').length == 0){
				clearForm(false);
			}
			if ($('searchType1').get('checked')){
			
					if($('wordSearch').get('value').length > 0){
						clearAccordPre();
						getDataNotForm();
					}
					if($('wordSearch').get('value').length == 0){
						clearForm(true);
					}
					
				
			}else{
					clearAccordPre();
					getDataNotForm();	
			}
		}
	});
	
	
	
	
	
	
	
	
	
	 
	
	
	
	$('searchType1').addEvent('click', function(e) {
		//e.stop();
		clearForm(true);
		
	});
	
	$('reset').addEvent('click', function(e) {
		e.stop();
		clearForm(true);
		
	});
	
	var clearForm = function(clearSelects) {
		$('wordSearch').setProperty('value','');
		
		$('log_res').empty()
		
		if (clearSelects == true){
			$$('#myForm select').setProperty('value','');
			clearAccordWipe();
			$('paginationTop').empty()
			$('paginationBottom').empty()
		}else{
			$('myForm').send();
		}
	};
	
	
	
	
	
	
	
	var clearAccordPre = function() {
		$('welcomeContent').addClass('element');
		$('welcomeContent').empty();
		$('welcomeToggle').removeClass('collap');
		$('welcomeToggle').addClass('collapsed');
		$('welcomeToggle').set('html', 'Collapse All');
		$('pageNumber').set('value', 1);
		$('sortDiv').setStyle('display', 'block');
		//alert($('pageNumber').value)
		
	};
	
	var clearAccordShowPag = function() {
		$('welcomeContent').removeClass('element');
		$('welcomeContent').empty();
		$('welcomeToggle').empty();
		$('welcomeToggle').removeClass('collapsed');
		$('pageNumber').set('value', 1);
		$('sortDiv').setStyle('display', 'none');
		//alert($('pageNumber').value)
	};
	
	
	var clearAccordWipe = function() {
		$('sortDiv').setStyle('display', 'none');
		$('welcomeToggle').removeClass('collapsed');
		$('welcomeToggle').addClass('collap');
		//$('welcomeContent').removeClass('element');
		$('welcomeContent').addClass('element');
		$('welcomeContent').setStyle('height', '430px');
		//var str='HELLO!';
		var str='';
		str+='<br \/><img src="_images\/mapSelectMain.png" \/><br \/><br \/><span align="justified">The United States Department of Agriculture (USDA) Hardiness Zone Map (above) defines areas in which specific categories of plant life are capable of growing, as defined by climatic conditions, including withstanding zone minimum temperatures. The map shows the eleven hardiness zones, where Zone 1 is the area with harshest conditions for plant growth. The six regions used in the NatureGrounds on-line, searchable plant selection database are also identified.<\/span>';
		$('welcomeContent').set('html', str);
		$('welcomeToggle').set('html', 'Plant Search');
		//$('welcomeToggle').addClass('notToggler');
		$('pageNumber').set('value', 1);
		//alert($('pageNumber').value)
		$('searchType1').setProperty('checked','checked');
		$('searchType2').removeProperty('checked');
		
	};
	
	
	

	
	
	
	
	
	
	
	var listPlantsAccord = function(plants) {
		
		var myAccordion = new Accordion($('accordion'), 'a.collapsed', 'div.element', { 
			opacity: false
		});
		var log1 = $('log_res');
		
		var i = 0;
		//var acDiv = new Element('div', {'id': 'accordion'});
		//var listLength = '';
		//var howManyPages = '';
		//var tenBlockCount = 0;
		//var tenBlockNumber = 1;
		//listLength = plants.length;
		//howManyPages = Math.ceil(listLength/10);
		var strNA = "n/a";
		plants.each(function(plants, index) {
		i=i+1;
		//for (i=0;i<= (plants.length / 2);i++){
				
			
			if (plants.category == null){
				pCat = strNA;
			}else{
				pCat = plants.category;
			}
			
			if (plants.hardinessZone == null){
				pHZ = strNA;
			}else{
				pHZ = plants.hardinessZone;
			}
			
			if (plants.growthRate == null){
				pGrowR = strNA;
			}else{
				pGrowR = plants.growthRate;
			}
			
			if (plants.exposureReqs == null){
				pExpos = strNA;
			}else{
				pExpos = plants.exposureReqs;
			}
			
			if (plants.treeShape == null){
				pShape = strNA;
			}else{
				pShape = plants.treeShape;
			}
			
			if (plants.leafTex == null){
				pleafTex = strNA;
			}else{
				pleafTex = plants.leafTex;
			}
			
			if (plants.category == null){
				pCat = strNA;
			}else{
				pCat = plants.category;
			}
			
			if (plants.shadeQuality == null){
				pSQ = strNA;
			}else{
				pSQ = plants.shadeQuality;
			}
			
			if (plants.exfolBark == null){
				pEBark = strNA;
			}else{
				pEBark = plants.exfolBark;
			}
			
			if (plants.fallColor == null){
				pfColor = strNA;
			}else{
				pfColor = plants.fallColor;
			}
			
			if (plants.edibleFruit == null){
				pEFruit = 'No';
			}else{
				pEFruit = 'Yes';
			}
			
			if (plants.fruitColor == null){
				pFColor = '';
			}else{
				pFColor = plants.fruitColor + ' ,';
			}
			
			if (plants.fruitSeason == null){
				pFSeason = '';
			}else{
				pFSeason = plants.fruitSeason;
			}
			
			if (plants.plantSeed == null){
				pSeed = strNA;
			}else{
				pSeed = plants.plantSeed;
			}
			
			if (plants.bloomColor == null){
				pBColor = 'Non-Blooming ,';
			}else{
				pBColor = plants.bloomColor + ' ,';
			}
			
			if (plants.plantFragrance == null){
				pBFrag = 'None';
			}else{
				if (plants.plantFragrance == 'x'){
					pBFrag = 'Yes';
				}else{
					pBFrag = plants.plantFragrance;
				}
			}
			
			if (plants.bloomSeason == null){
				pBSeason = '';
			}else{
				pBSeason = plants.bloomSeason;
			}
			
			if (plants.plantNotes == null){
				pNotes = strNA;
			}else{
				pNotes = plants.plantNotes;
			}
			
			if (plants.vineAttachment == null){
				pVineAttach = strNA;
			}else{
				pVineAttach = plants.vineAttachment;
			}
			
					var str='';
str+='<TABLE CELLPADDING="0" CELLSPACING="0" BORDER="0" CLASS="expanded">';
str+='	<TR VALIGN="top">';
str+='		<TD CLASS="species"><P CLASS="common-head">'+plants.commonName+'<\/P>';
str+='			<P CLASS="latin-sub">'+plants.botanicalName+'<\/P>';
str+='			<P>';
if (plants.minHeight != null || plants.maxHeight != null){
	str+='		'+plants.minHeight+'-'+plants.maxHeight+' height;';
}
if (plants.minWidth != null || plants.maxWidth != null){
	str+='			'+plants.minWidth+'-'+plants.maxWidth+' width';
}
str+='			<\/P>';
if (plants.usdaPlantCode != null && plants.usdaPlantCode != '' ){
str+='			<P><A HREF="'+plants.usdaPlantCode+'" target="_new">USDA plant profile<\/A><\/P>';
}
str+='			<P CLASS="variable"><A HREF="printPage.asp?id='+ plants.id +'&botName='+ plants.botanicalName +'" target="_new">Printable brief<\/A><\/P><\/TD>';
str+='		<TD CLASS="thumbs"><div id="slimboxHolder'+ plants.id +'">';


//str+=' <a href="_images\/Acer_rubrum.jpg" rel="lightbox-'+ plants.id +'" class="quiet"><IMG CLASS="thumb" SRC="_images\" WIDTH="69" HEIGHT="96" BORDER="0"></a><a href="_images\/Fagus_grandifolia.jpg" rel="lightbox-'+ plants.id +'" class="quiet"><IMG CLASS="thumb" SRC="_images\/Fagus_grandifolia.jpg" WIDTH="124" HEIGHT="80" BORDER="0"></a>';





str+='</div><\/TD>';


str+='	<\/TR>';
str+='	<TR VALIGN="top">';
	var regionCount = 0;
	var regionVar = '';
	if (plants.northWestRegion != null){
		regionCount = regionCount + 1;
		regionVar = "Northwest";
	}
	if (plants.rockyMountainRegion != null){
		regionCount = regionCount + 1;
		if (regionCount > 1){
			regionVar = regionVar + "; Rocky Mountains";
		}else{
			regionVar = "Rocky Mountains";
		}
	}
	if (plants.southWestRegion != null){
		regionCount = regionCount + 1;
		if (regionCount > 1){
			regionVar = regionVar + "; Southwest";
		}else{
			regionVar = "Southwest";
		}
	}
	if (plants.southEastRegion != null){
		regionCount = regionCount + 1;
		if (regionCount > 1){
			regionVar = regionVar + "; Southeast";
		}else{
			regionVar = "Southeast";
		}
	}
	if (plants.northEastRegion != null){
		regionCount = regionCount + 1;
		if (regionCount > 1){
			regionVar = regionVar + "; Northeast";
		}else{
			regionVar = "Northeast";
		}
	}
str+='		<TD CLASS="data-left"><P CLASS="variable"><SPAN CLASS="variable">Type:<\/SPAN> '+plants.categoryGrouped+'<\/P>';
str+='			<P CLASS="variable"><SPAN CLASS="variable">Region(s):<\/SPAN> '+regionVar+'<\/P>';
if (plants.hardinessZonesMin != null || plants.hardinessZonesMax != null){
	str+='			<P CLASS="variable"><SPAN CLASS="variable">Hardiness Zone(s):<\/SPAN>  '+plants.hardinessZonesMin+'- '+plants.hardinessZonesMax+'<\/P>';
}

str+='			<P CLASS="variable"><SPAN CLASS="variable">Growth Rate:<\/SPAN> '+pGrowR+'<\/P>';
str+='			<P CLASS="variable"><SPAN CLASS="variable">Exposure Requirement:<\/SPAN> '+pExpos+'<\/P>';


var moistureCount = 0;
	var moistureVar = '';
	if (plants.veryWet != null){
		moistureCount = moistureCount + 1;
		moistureVar = "Very Wet";
	}
	if (plants.veryDry != null){
		moistureCount = moistureCount + 1;
		if (moistureCount > 1){
			moistureVar = moistureVar + "; Very Dry";
		}else{
			moistureVar = "Very Dry";
		}
	}
	if (plants.moistWellDrained != null){
		moistureCount = moistureCount + 1;
		if (moistureCount > 1){
			moistureVar = moistureVar + "; Moist & Well Drained";
		}else{
			moistureVar = "Moist & Well Drained";
		}
	}
	if (plants.occDry != null){
		moistureCount = moistureCount + 1;
		if (moistureCount > 1){
			moistureVar = moistureVar + "; Occasionally Dry";
		}else{
			moistureVar = "Occasionally Dry";
		}
	}


str+='			<P CLASS="variable"><SPAN CLASS="variable">Soil Moisture Requirement:<\/SPAN>'+moistureVar+'<\/P>';

			if (plants.nativePlant == null){
				pNative = 'No';
			}else{
				pNative = 'Yes';
			}

str+='			<P CLASS="variable"><SPAN CLASS="variable">Native:<\/SPAN> '+pNative+'<\/P>';
			
			if (plants.erosionControl == null){
				pErosion = 'No';
			}else{
				pErosion = 'Yes';
			}

str+='			<P CLASS="variable"><SPAN CLASS="variable">Erosion Control:<\/SPAN> '+pErosion+'<\/P>';


var playValCount = 0;
	var playValVar = '';
	if (plants.plantSound != null){
		playValCount = playValCount + 1;
		playValVar = "Wind-Shimmer & Sound";
	}
	if (plants.plantBuffer != null){
		playValCount = playValCount + 1;
		if (playValCount > 1){
			playValVar = playValVar + "; Wind Screen & Buffers";
		}else{
			playValVar = "Wind Screen & Buffers";
		}
	}
	if (plants.moistWellDrained != null){
		playValCount = playValCount + 1;
		if (playValCount > 1){
			playValVar = playValVar + "; Wildlife Enhancement";
		}else{
			playValVar = "Wildlife Enhancement";
		}
	}

str+='			<P CLASS="variable"><SPAN CLASS="variable">Play Value:<\/SPAN> '+playValVar+'<\/P>';
str+='			<P CLASS="variable"><SPAN CLASS="variable">Notes:<\/SPAN> '+pNotes+'<\/P><\/TD>';
str+='		<TD CLASS="data-right"><P CLASS="variable"><SPAN CLASS="variable">Shape:<\/SPAN> '+pShape+'<\/P>';
str+='			<P CLASS="variable"><SPAN CLASS="variable">Vine Physical Attachment:<\/SPAN> '+pVineAttach+'<\/P>';
str+='			<P CLASS="variable"><SPAN CLASS="variable">Leaf Texture:<\/SPAN> '+pleafTex+'<\/P>';
str+='			<P CLASS="variable"><SPAN CLASS="variable">Shade Quality:<\/SPAN> '+pSQ+'<\/P>';

if (plants.barkTex != null){
		pBarkTex = plants.barkTex;
		if (plants.exfolBark != null){
			pBarkTex = pBarkTex + "; Exfoliating";
		
		}
	}else{
		pBarkTex = strNA;
	}
	
	
str+='			<P CLASS="variable"><SPAN CLASS="variable">Bark Texture:<\/SPAN> '+pBarkTex+'<\/P>';
str+='			<P CLASS="variable"><SPAN CLASS="variable">Fall Color:<\/SPAN> '+pfColor+'<\/P>';



str+='			<P CLASS="variable"><SPAN CLASS="variable">Edible Fruit:<\/SPAN> '+pEFruit+'<\/P>';

var fruitCount = 0;
	var fruitVar = '';
	if (plants.fruitColor != null){
		fruitCount = fruitCount + 1;
		fruitVar = plants.fruitColor;
	}
	if (plants.fruitSeason != null){
		fruitCount = fruitCount + 1;
		if (fruitCount > 1){
			fruitVar = fruitVar + "; " + plants.fruitSeason;
		}else{
			fruitVar = plants.fruitSeason;
		}
	}
	if (fruitCount==0){
		fruitVar = strNA;
	}

str+='			<P CLASS="variable"><SPAN CLASS="variable">Fruit Color\/Season:<\/SPAN> '+fruitVar+'<\/P>';
str+='			<P CLASS="variable"><SPAN CLASS="variable">Seed:<\/SPAN> '+pSeed+'<\/P>';

var bloomCount = 0;
	var bloomVar = '';
	if (plants.bloomColor != null){
		bloomCount = bloomCount + 1;
		bloomVar = plants.bloomColor;
	}
	if (plants.bloomSeason != null){
		bloomCount = bloomCount + 1;
		if (bloomCount > 1){
			bloomVar = bloomVar + '; ' +plants.bloomSeason;
		}else{
			bloomVar = plants.bloomSeason;
		}
	}
	if (bloomCount==0){
		bloomVar = strNA;
	}

str+='			<P CLASS="variable"><SPAN CLASS="variable">Bloom Color\/Season:<\/SPAN> '+bloomVar+'<\/P>';
str+='			<P CLASS="variable"><SPAN CLASS="variable">Bloom Fragrance:<\/SPAN> '+pBFrag+'<\/P><\/TD>';
str+='	<\/TR>';
str+='<\/TABLE>';
			
			//alert(index);
			//$('welcomeContent').empty();
			//$('welcomeToggle').removeClass('toggler');
			//$('welcomeToggle').addClass('notToggler');
			
			if ($('sortVar').get('value') == 'latin'){
				var headStr = '<SPAN CLASS="collapsed-latin">' + plants.botanicalName+ '</span>' + ' ' + '<SPAN CLASS="common-sub">(' + plants.commonName + ')</span>';
			}else{
				var headStr = plants.commonName+' ' + '<SPAN CLASS="latin-sub">(' + plants.botanicalName +')</span>' ;
			}
			
				var headline = new Element('a', {'class': 'collapsed', 'html': headStr}).inject(log1);
				var content = new Element('div', {'class': 'element', 'html': str}).inject(headline, 'after');
				myAccordion.addSection(headline, content, index + 1);	
				
				createImageBlock(plants.id,plants.botanicalName);
				
		});
		//alert(i);
		if (i==0){
		 	clearAccordShowPag();
		}
		//var menu = new Element('table', {'class': 'notToggler', 'html': howManyPages}).inject(log1);
	};
	
	
	var createImageBlock = function(id,botName) {
	//alert("functionTriggered")
	//let's create a bunch of images here on the fly
				var noMoreImages = false;
				var countImagesVar = 0;
				var countImageTailsVar = 0;
			//alert("/plantSearch/_ajax/ajax.asp?submitBy=images&botName=" + botName);
			var request = new Request.JSON({
			url: '/plantSearch/_ajax/ajax.asp?submitBy=images&botName=' + botName,
			//onSuccess: function(images) {
			onComplete: function(images) {
				//alert('OnCompleteImages: ' + images);
				images.each(function(images, index) {
					countImagesVar = countImagesVar + 1;
					if(countImagesVar <= 2){
						
 				 		$('slimboxHolder'+ id).adopt(
    						new Element('a').setStyle('cursor','pointer').addClass('quiet').setProperties({
     							href:images.imageURLLarge,
      							rel: 'anotherLightBoxSet[set2]'
    						}).adopt(
      						new Element('img').setProperties({
															 
															 src:images.imageURLSmall,
															 border:'0'
															 }).setStyle('margin', 2)
    						)
  						);
  
					}else{
					
					 	$('slimboxHolder'+ id).adopt(
    						new Element('a').setStyle('cursor','pointer').setProperties({
     							href:images.imageURLLarge,
      							rel: 'anotherLightBoxSet[set2]'
    						}).adopt(
      						new Element('img').setProperty('src',images.imageURLSmall).setStyle('display', 'none')
    						)
  						);
  
					}
					
					
					
				});
				new Lightbox({ relString: 'anotherLightBoxSet' }, $('slimboxHolder'+ id).getElements('a'));
				//paginationBuildMenu(jsonObj);
				//clearAccordPre();
			}
			}).send();
				
		
				
				
				//while (noMoreImages != true){
				
				
					//document.write("The number is " + i);
					//document.write("<br />");
					//i++;
				//	noMoreImages = true;
				//}
				
				
				
	};
	
 
	ReMooz.assign('#imagePop a', {
		'origin': 'a',
		'shadow': 'onOpenEnd', // fx is faster because shadow appears after resize animation
		'resizeFactor': 0.5, // resize to maximum 80% of screen size
		'cutOut': false, // don't hide the original
		'opacityResize': 0.4, // opaque resize
		'dragging': false, // disable dragging
		'centered': true // resize to center of the screen, not relative to the source element
	});
 

});

function disableEnterKey(e)
{
     var key;     
     if(window.event)
          key = window.event.keyCode; //IE
     else
          key = e.which; //firefox     

     return (key != 13);
}



function capitalizeMe(obj) {
        val = obj;
        newVal = '';
       
        for(var c=0; c < val.length; c++) {
                newVal += val[c].substring(0,1).toUpperCase() +
val[c].substring(1,val[c].length) + ' ';
        }
        capitalizeMe = newVal;
}