
//--------------------------------------------------------------------------------
// Pushbutton
//--------------------------------------------------------------------------------

/**
 * @author Piers Cowburn
 * Initialise the nav button rollover/rollout animations
 */
$(function() {
	if (!($.browser.msie && $.browser.version.substr(0, 1) < 7)) {
		var navButtons = '#navAbout, #navClients, #navWork, #navProducts, #navPress, #navBlog, #navContact';
		$(navButtons).hover(function(){
			animateIn(this.id);
		}, function(){
			animateOut(this.id);
		});
	}
});

/**
 * @author Piers Cowburn
 * Animate the buttons in (replacement for JQuery animation which was too jerky)
 */
function animateIn(element)
{
	element = document.getElementById(element);
	
	if (element.animating == "out")
		clearInterval(element.animationInterval);
	else if (element.animating == "in")
		return;
		
	element.animating = "in";
	element.animationInterval = setInterval(function(){ doAnimate(element, -22); }, 12);
}

/**
 * @author Piers Cowburn
 * Animate the buttons out (replacement for JQuery animation which was too jerky)
 */
function animateOut(element)
{
	element = document.getElementById(element);
	
	if (element.animating == "in")
		clearInterval(element.animationInterval);
	else if (element.animating == "out")
		return;
		
	element.animating = "out";
	element.animationInterval = setInterval(function(){ doAnimate(element, 0); }, 12);	
}

/**
 * @author Piers Cowburn
 * Do the actual animation (called via setInterval)
 */
function doAnimate(element, value)
{	
	// Set initial start position, if it is not already set
	if (!element.interimValue)
		element.interimValue = 0;

	// Tween the value
	if (value < element.interimValue)
		element.interimValue-=2;
	else if (value > element.interimValue)
		element.interimValue+=2;
	
	// Apply the interim value
	element.style.backgroundPosition = "0 " + element.interimValue + "px";
	
	// Check if the animation is complete
	if (element.interimValue == value)
	{
		clearInterval(element.animationInterval);
		element.animating = "";
	}
}

/**
 * Replace an h1 tag with a flash text field replacement
 */
function replaceElement(basePath, elementType, elementId, width, height){	
	var so = new SWFObject(basePath+"flash/elements/"+elementType+".swf", "replacement_for_" + elementId, width, height, "9", "#FFFFFF");
	so.addVariable("contents", encodeURIComponent(innerXHTML(elementId)));
	so.addParam("wmode", "transparent");
	so.write(elementId);
}

/**
 * Insert the Flash for a feature area
 */
function insertFeatureFlash(basePath, featureVideo, overlayVideo, overlayAec, staticImageZip, backgroundImage, isHome, getContentsFromElementId){
	var so = new SWFObject(basePath + "flash/features/Main.swf", "featureSwf", 736, 348, "10", "#FFFFFF");
	so.addVariable("localRoot", basePath);
	so.addVariable("featureVideo", featureVideo);
	so.addVariable("overlayVideo", overlayVideo);
	so.addVariable("overlayAec", overlayAec);
	so.addVariable("staticImageZip", staticImageZip);
	so.addVariable("backgroundImage", backgroundImage);
	so.addVariable("isHome", isHome);
	if (isHome != true)
		so.addParam("wmode", "transparent");
	
	if (getContentsFromElementId != undefined && getContentsFromElementId != null && getContentsFromElementId != ''){
		so.addVariable("title", encodeURIComponent(innerXHTML(getContentsFromElementId)));
		document.getElementById(getContentsFromElementId).style.display = 'none';
	}
	
	so.write("feature");
}