document.onmouseover = hidePlants;
document.onclick = hidePlants;

$(document).ready(function(){
	$("body").append('<div id="imageScreen"></div><div id="imageWindow"><span id="closeLink">X</span></div>');
	$(".plantImage").click(function(event){
		var thisImg = $(this).attr('id').substr(2);
		var imagePath = '/files/stems/bigs/'+thisImg+'.jpg';
		$("#imageScreen").fadeIn('fast',function(){
			$("#imageWindow").css('background-image','url('+imagePath+')').show();
		});
	});
	$("#imageWindow").live('click',function(){
		$("#imageWindow").fadeOut('fast',function(){
			$("#imageScreen").hide();
		});
	});
});

function raisePlants(where,whatBox,eventObj,direction)
{
	hidePlants();
	eventObj.cancelBubble = true;
  var styleObject = getStyleObject(whatBox);
  if(styleObject) 
	{
		var cords = findPos(where);
		var xPos = (cords[0]);
		var yPos = cords[1];
		var objBox = document.getElementById(whatBox);
		if(typeof(window.innerWidth) == 'number')
		{
			var docWidth = window.innerWidth;
			var boxHeight = objBox.height;
			var letterHeight = where.height;
		}
		if(typeof(document.body.offsetWidth) == 'number')
		{
			var docWidth = document.body.offsetWidth - 10;
			var boxHeight = objBox.offsetHeight;
			var letterHeight = where.offsetHeight;
		}
		//alert(letterHeight);
		if ((xPos + 340) > docWidth)
		{
			xPos = docWidth - 340;
		}
		else
		{
			xPos -= 20;
		}
		var ScrollTop = document.body.scrollTop;
		if (ScrollTop == 0)
		{
	    if (window.pageYOffset)
			{
				ScrollTop = window.pageYOffset;
			}
    	else
			{
        ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
			}
		}
		//if(boxHeight > 300){boxHeight = 335;}
		if(direction > 0)
		{
			boxHeight -= 10;
			yPos -= boxHeight;
			if(yPos < ScrollTop){yPos = ScrollTop;}
		}
		else
		{
			yPos += (letterHeight-5);
			var docHeight = getHeight();
			var docBottom = ScrollTop + docHeight;
			if((yPos + boxHeight) > docBottom){yPos = (docBottom - boxHeight);}
		}
		//alert('yPos:'+yPos+', boxHeight:'+boxHeight);
		//alert(boxHeight);
		xPos += 'px';
		yPos += 'px';
		//alert(yPos);
		styleObject.left = xPos;
		styleObject.top = yPos;
		styleObject.visibility = 'visible';
		styleObject.zIndex = 10;
		//alert(styleObject.visibility);
		return true;
	} 
	else 
	{
		return false;
  }
}
function hidePlants()
{
	for(i=0;i<lettersArray.length+1;i++)
	{
		var whatBox = 'letter' + lettersArray[i];
		changeObjectVisibility(whatBox,'hidden',1);
	}
}
		
function findPos(styleObject) {
	var curleft = 0;
	var curtop = 0;
	if (styleObject.offsetParent) {
		curleft = styleObject.offsetLeft
		curtop = styleObject.offsetTop
		while (styleObject = styleObject.offsetParent) {
			curleft += styleObject.offsetLeft
			curtop += styleObject.offsetTop
		}
	}
	return [curleft,curtop];
}
