function openPage(page){
	startElmnt = (page-1) * 18;
	endElmnt = startElmnt + 17;
	$('.body .plant').each(function(i,elmnt){
		if(i >= startElmnt && i <= endElmnt){
			$(this).fadeIn();
		}
		else $(this).hide();
	});
}
$(document).ready(function (){
	$('#defaultIndex #gallery:last-child').ready(function(){
		//Starting Main Slideshow, if on index page
		$('#gallery').cycle({
			fx: 'scrollHorz',
			speed: '200'
		});
	});
	
	
	//Setting Uniform height for each plant div
	$('div.row').each(function (){
		var tallest = 0;
		var elements = $(this).children().filter('.plant');
		elements.each(function (){
			var currHeight = $(this).height();
			if(currHeight > tallest) tallest = currHeight;
		});
		elements.each(function(){
			$(this).css("height",tallest);
		});
	});
	//Moving Inventory UL's to bottom of plant div
	$('.body .plant ul').css('position','absolute').css('bottom',3);
	
	//Hiding all but the first 18 Plant Entries
	var counter = 1;
	$('.plant').each(function(){
		if(counter > 18)$(this).hide();
		counter++;
	});
	//Printing out the paginator HTML if there are any .body.plant div's
	if(counter != 1){
		var controls = "<div class=\"pageNav\">Page: <ul>";
		var pageCount = Math.ceil(counter / 18);
		for(i = 1;i <= pageCount;i++){
			controls+="<li>"+i+"</li>";
		}
		controls+="</ul></div>";
		$('.body').append(controls);
		$('.body .pageNav ul li').click(function(){
			openPage(this.innerHTML);
		});
	}
	//Setting Hover() for Plant Description Div
	$('.body .plant .photo').click(function(e){
		if($('#imageSlideshow').children().length!=0){
			return;
		}
		offset = 20;
		//Getting Info URL for each Plant DIV
		var plantid = $(this).parents('.plant').attr('id').substr(5);
		var infourl = "ajax.php?plant="+plantid;
		//Mouse Over
		var element = $('#slideshowWrap');
		element
		.css('top','16px')
		.css('left','50%')
		.css('position','absolute')
		.css('margin-left','-374px');
		$('#imageSlideshow')
		.load(infourl,function(){
			if(!element.find('img.loading').length){
				element.delay(500).fadeIn(200);
				$('#imageSlideshow').cycle({fx: 'scrollHorz',speed: '200'});
			}
		});
		
	});
	//Mouse Movement for Plant Description Div
	$('#slideshowWrap').click(function(e){
		//Stopping the SlideShow
		$('#imageSlideshow').cycle('stop').empty();
		//Mouse Out
		$('#slideshowWrap').stop().hide();
	});
	//Setting up MouseClick Handlers for Plant Divs
//	$('.body .plant').click(function(e){

//	});
	
	

	
	
	//Do not use below, intentionally empty for end of doc.ready
	
});
