//	wp_default.js
//	Portions (C) PyrusMalus, 2007.
//	www.pyrusmalus.com


//	setOpacity takes an object and an opacity value (0..100)
//	and sets the appropriate opacity.

function pm_setOpacity(object, opacity)
{
	if ((opacity >= 0) && (opacity <=100) && (object != null))
	{
		opacity = (opacity == 100 ? 99.999 : opacity);

		//	Safari 1.2, Firefox, Mozilla, CSS3...
		object.style.opacity = opacity / 100;

		//	Old Mozilla, Firefox...
		object.style.MozOpacity = opacity / 100;

		//	Old Safari, Konqueror...
		object.style.KHTMLOpacity = opacity / 100;

		//	IE/Win...
		object.style.filter = "alpha(opacity:"+opacity+")";
	}
}

function pm_setOpacityForId(objectId, opacity)
{
	if (document.getElementById)
	{
		object = document.getElementById(objectId);
		pm_setOpacity(object, opacity);
	}
}


//	cycleImages: cycle through the images in the named div, fading each one up in turn

function pm_cycleImagesInDiv(inDivId, inInitialDelay, inFadeIncrement, inFadeDelay, inHoldDelay)
{
	if (document.getElementById)
	{
		cycleDiv = document.getElementById(inDivId);
		childCount = cycleDiv.children.length;
		window.setTimeout("pm_cycleIn('" + inDivId + "_" + "', " + 1 + ", " + childCount + ", " + 0 + ", " + inFadeIncrement + ", " + inFadeDelay + ", " + inHoldDelay + ")", inInitialDelay);
	}
}


//	cycleIn: private method which handles the actual fading

function pm_cycleIn(objectIdPrefix, initial, count, opacity, inFadeIncrement, inFadeDelay, inHoldDelay)
{
	objectId = objectIdPrefix + initial;

	if (document.getElementById)
	{
		object = document.getElementById(objectId);
		if (opacity <= 100)
		{
			//	keep fading up image...
			pm_setOpacity(object, opacity);
			opacity += inFadeIncrement;
			window.setTimeout("pm_cycleIn('" + objectIdPrefix + "', " + initial + ", " + count + ", " + opacity + ", " + inFadeIncrement + ", " + inFadeDelay + ", " + inHoldDelay + ")", inFadeDelay);
		}
		else
		{
			//	move on to next image...
			initial += 1;
			if (initial <= count)
			{
				opacity = 0;
				window.setTimeout("pm_cycleIn('" + objectIdPrefix + "', " + initial + ", " + count + ", " + opacity + ", " + inFadeIncrement + ", " + inFadeDelay + ", " + inHoldDelay +")", inHoldDelay);
			}
			else
			{
				//	cycle complete...
			}
		}
	}
}

//	specific routines to display the random reason...

function pm_randomReason(inDivId, inInitialDelay, inFadeIncrement, inFadeDelay, inHoldDelay)
{
	//	pick a random number 1..45 for the reason image...
	now = new Date();
	seed = now.getSeconds();
	index = Math.floor(Math.random(seed) * 45) + 1;
	reasonImageObject = document.getElementById("reason_image");
	reasonImageSource = "/_resources/interface/reasons/reason" + index + ".gif";
	reasonImageObject.src = reasonImageSource;
	
	window.setTimeout("pm_fadeInReason('reason_image', 0, " + inFadeIncrement + ", " + inFadeDelay + ");", inInitialDelay);
	
	
}

function pm_fadeInReason(objectId, opacity, inFadeIncrement, inFadeDelay)
{
	if (document.getElementById)
	{
		object = document.getElementById(objectId);
		if (opacity <= 100)
		{
			//	keep fading up image...
			pm_setOpacity(object, opacity);
			opacity += inFadeIncrement;
			window.setTimeout("pm_fadeInReason('" + objectId + "', " + opacity + ", " + inFadeIncrement + ", " + inFadeDelay + ")", inFadeDelay);
		}
		else
		{
			//	swap this into placeholder...
			placeholderObject = document.getElementById("reason_placeholder");
			placeholderObject.src = object.src;
			
			//	reset the opacity on the foremost reason...
			pm_setOpacity(object, 0);
			
			//	and repeat...
			pm_randomReason("reason", 4000, 1, 10, 200);
		}
	}
}


function pm_contact(inName, inDomain)
{
	address='mailto:' + inName + '@' + inDomain;
	location = (address);
}

function pm_showPreview(inImageUrl, inCaptionString)
{
	placeholderImg = document.getElementById("preview_image");
	placeholderImg.src = "/_resources/images/" + inImageUrl;
	
	
	placeholderCaption = document.getElementById("preview_caption");
	placeholderCaption.innerHTML = inCaptionString;
	
	previewDiv = document.getElementById("preview");
	previewDiv.style.display = "block";
	
}

function pm_closePreview()
{
	previewDiv = document.getElementById("preview");
	previewDiv.style.display = "none";
}
