/**********************************
Static properties
**********************************/

var BAR_START_Y = -30; // Starting Y coord of the moving bar.
var BAR_END_Y = 305; // Ending Y coord of the moving bar.
var BAR_STEPS = 5; // Number of pixels that the bar moves each step.
var BAR_STEP_INTERVAL = 0.005; // Seconds between each bar movement.

/**********************************
Properties
**********************************/

var nMoveBar_int; // Interval used for controlling the bar movement.

/**********************************
Functions
**********************************/

/*
Starts the horizontal bar moving.
*/

function startMoveBar()
	{
		nMoveBar_int = setInterval("moveBar()", BAR_STEP_INTERVAL * 1000);
	}

/*
Called on interval to move the bar.
*/

function moveBar()
	{
		var nCurrBarPosition = document.getElementById("bar").style.top;
		var nNewPosition = getStyleString(validateBarPosition(getStyleNumber(nCurrBarPosition) + BAR_STEPS));
		document.getElementById("bar").style.top = nNewPosition;
	}

/*
Checks if the new bar position is valid according to its end position.
If the end is reached, returns the adjusted value and stops the interval for movement.

	@position:Number				New bar position being validated.
	@return:Number					Validated new position for the bar.
*/

function validateBarPosition(position)
	{
		if (position >= BAR_END_Y)
		{
			position = BAR_END_Y;
			clearInterval(nMoveBar_int);
			barMoveComplete();
		}
		
		return position;
	}

/*
Called when the horizontal bar has completed its movement.
*/

function barMoveComplete()
	{
		document.contact.SetVariable("initiateEmailAnimation", "true");
	}

/*
Returns the numeric value of the specified style string (e.g. "100px" returns 100).

	@styleString:String			Style string to check.
	@return:Number					Numeric value of style string.
*/

function getStyleNumber(styleString)
	{
		return Number(styleString.substring(0, styleString.length - 2));
	}

/*
Returns the style string for the specified numeric value (e.g. 100 returns "100px").

	@styleString:Number			Style number to check.
	@return:String					Style string for the numeric value.
*/

function getStyleString(styleNumber)
	{
		return String(styleNumber + "px");
	}

/*
Inserts the Flash movie.
*/

function insertFlash()
	{
		document.writeln('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="755" height="410" id="contact" align="middle">');
		document.writeln('<param name="allowScriptAccess" value="sameDomain" />');
		document.writeln('<param name="allowFullScreen" value="false" />');
		document.writeln('<param name="movie" value="contact.swf?inPage=true&sent=' + (getQueryData().sent == "true") + '" /><param name="loop" value="false" /><param name="menu" value="false" /><param name="quality" value="best" /><param name="bgcolor" value="#AF5903" />	<embed src="contact.swf?inPage=true&sent='+ (getQueryData().sent == "true") + '" loop="false" menu="false" quality="best" bgcolor="#AF5903" width="755" height="410" name="contact" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
		document.writeln('</object>');
	}

/*
If we are not running at 'www' ensure that we are relocated.
*/

function locateToWWW()
	{
		if (window.location.toString().indexOf("www") == -1) window.location = "http://www.malca.co.uk";
	}
		
/*
Returns the query part of the location string.
window.loaction.search is the url query including the '?'.
*/

function getQuery()
	{
		return window.location.search.substring(1);
	}
	
/*
Returns an object containing name value pairs from the url query (e.g. myObject.myName = myValue).
window.loaction.search is the url query including the '?'.
*/

function getQueryData()
	{
		var aCurrPair; // Current name value pair being assessed.
		var aQueries = getQuery().split("&");
		var oData = {}; // Holds the return data
		
		for (var i = 0; i < aQueries.length; i++)
		{
			aCurrPair = aQueries[i].split("=");
			oData[aCurrPair[0]] = aCurrPair[1];
		}
		
		return oData;
	}
