// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
var IE = document.all ? true : false;
if (!IE)
{
	document.captureEvents(Event.MOUSEMOVE);
}
document.onmousemove = getMouseXY;
var tempX = 0;
var tempY = 0;
function getMouseXY(e)
{
	if (document.all)
	{ // grab the x-y pos.s if browser is IE
		tempX = event.clientX + document.body.scrollLeft;
		tempY = event.clientY + document.body.scrollTop;
	}
	else
	{  // grab the x-y pos.s if browser is NS
		tempX = e.pageX;
		tempY = e.pageY;
	}  
	if (tempX < 0)
	{
		tempX = 0;
	}
	if (tempY < 0)
	{
		tempY = 0;
	}
	return true;
}

var spotlightDiv = null;
var overIcon = false;
var overDiv = false;
function CreateImgSpotlight(newid, src)
{
	if(CreateSpotlight(newid))
	{
		
		var imageDiv = document.createElement("div");
		imageDiv.setAttribute("class", "spotlight_image");
		spotlightDiv.appendChild(imageDiv);
		
		var normalImg = document.createElement("img");
		normalImg.setAttribute("src", src);
		imageDiv.appendChild(normalImg);
		
		var closeDiv = document.createElement("div");
		closeDiv.setAttribute("class", "spotlight_close");
		spotlightDiv.appendChild(closeDiv);
		
		var closeLink = document.createElement("a");
		closeLink.setAttribute("href", "#");
		closeLink.setAttribute("onclick", "CloseSpotlight();return false;");
		closeLink.innerHTML = "Close";
		closeDiv.appendChild(closeLink);
	}
}
function CreateSpotlight(newid)
{
	overIcon = true;
	var createdDiv = false;
	if((spotlightDiv != null) && (spotlightDiv.id != newid))
	{
		spotlightDiv.parentNode.removeChild(spotlightDiv);
		spotlightDiv = null;
	}
	if(spotlightDiv == null)
	{
		createdDiv = true;
		spotlightDiv = document.createElement("div");
	}
	if(spotlightDiv.id != newid)
	{
		//spotlightDiv.setAttribute("class", "spotlight");
		spotlightDiv.style.position = "absolute";
		spotlightDiv.style.top = tempY + "px";
		spotlightDiv.style.left = (tempX + 15 ) + "px";
		spotlightDiv.style.opacity = "1";
		spotlightDiv.id = newid;
		spotlightDiv.setAttribute("onmouseover", "overDiv = true;");
		spotlightDiv.setAttribute("onmouseout", "overDiv = false;fadeoutSpotlight();");
		if(createdDiv)
		{
			var body = document.getElementsByTagName("body")[0];
			body.appendChild(spotlightDiv);
		}
	}
	return createdDiv;
};
function CloseSpotlight()
{
	if(spotlightDiv != null)
	{
		spotlightDiv.parentNode.removeChild(spotlightDiv);
		spotlightDiv = null;
	}
	return true;
};
function fadeoutSpotlight()
{
	if(!overIcon && !overDiv)
	{
		setTimeout(function(){fadeoutSpotlight2	(spotlightDiv);}, 1000);
	}
	else
	{
		spotlightDiv.style.opacity = 1;
	}
	return true;
};
function fadeoutSpotlight2()
{
	if(spotlightDiv != null)
	{
		if(!overIcon && !overDiv)
		{
			var opacity = parseFloat(spotlightDiv.style.opacity);

			if (opacity < 0.08)
			{
				CloseSpotlight();
			}
			else
			{
				opacity -= 0.04;
				spotlightDiv.style.opacity = opacity;
				setTimeout(function(){fadeoutSpotlight2();}, 30);
			}
		}
		else
		{
			spotlightDiv.style.opacity = 1;
		}
	}
	return true;
};
