var objVisibleLayer;
var infowindow;

function RefreshForm(formName) 
{
	var f = document.getElementById(formName);
	f.postback.value = 1;

	f.submit();
}

function swapImage(image, caption)
{
	var ext = '';
	ext = image.substring(image.length-3);
	
	if(ext == 'peg' || ext == 'jpg')
	{
		document.getElementById('mainPropImage').src = 'images/property/main/' + image;		
	}
	else
	{
		document.getElementById('mainPropImage').src = 'images/property/' + image;
	}
	
	document.getElementById('mainPropImage').alt = caption;
}

function addToFavourites()
{
	window.external.AddFavorite(self.location.href, window.title); 
}

function ShowPopUp(url, w, h)
{
	var t=0, l = 0, winstring = "";

	if(infowindow){
		if(!infowindow.closed) infowindow.close()
	}

	l = ((screen.width / 2) - (w / 2))
	t = ((screen.height / 2) - (h / 2))

	winstring = "width=" + w + ", height=" + h + ",left=" + l + ",top=" + t +  ",status=" + 'no' + ",resizable=" + 'yes' + ",scrollbars=" + 'yes';

	infowindow = window.open(url,'extnew' ,winstring);
}

function bigpiclink(picID, w, h, newWin)
{
	BigPicLink(picID, w, h, newWin);
}

function BigPicLink(picID, w, h, newWin)
{	
	var pUrl = basehref + 'getbigpiccontent.cfm?id=' + picID;
	
	$.ajax({
		url: pUrl,
		success: function(data) {
				if(data != 'NONE')
				{
					$("#divDlgPicViewer").dialog("option", "width", data.split('|')[0] + 'px' );
					$("#divDlgPicViewer").dialog("option", "height", data.split('|')[1] );
					$('#divDlgPicViewer').html(data.split('|')[2]);
					$('#divDlgPicViewer').dialog('open');
				}
			}
		});
}

function showContactDetails(divID)
{
	document.getElementById(divID).style.visibility = 'visible';
	document.getElementById(divID).style.display = '';
	
	document.getElementById(divID + 'link').style.visibility = 'hidden';
	document.getElementById(divID + 'link').style.display = 'none';
}

function showLayer(layerID){
	if( objVisibleLayer ){
		if( objVisibleLayer.id == layerID ) return 0;
	}

	objVisibleLayer = document.getElementById(layerID);

	if( objVisibleLayer )
		objVisibleLayer.style.display = '';

}

function hideLayer(){

	if( objVisibleLayer ){
		objVisibleLayer.style.display = 'none';
		objVisibleLayer = null;
	}

}

function swapSideImage(imgName, imgPath){
	var imgRef = document.getElementById(imgName);

	if( imgRef ){

		imgRef.src = imgPath;

	}

}

function ShowPopUpWindow(Name, File, w, h, Status, Resize, Scroll){
	var t=0, l = 0, winstring = "";

	if(infowindow){
		if(!infowindow.closed) infowindow.close()
	}

	l = ((screen.width / 2) - (w / 2))
	t = ((screen.height / 2) - (h / 2))

	winstring = "width=" + w + ", height=" + h + ",left=" + l + ",top=" + t +  ",status=" + Status + ",resizable=" + Resize + ",scrollbars=" + Scroll;

	infowindow = window.open(basehref + File,Name,winstring);
}

function showElement(eName)
{
	var e = document.getElementById(eName);
	e.style.visibility = 'visible';
	e.style.display = '';
}

function hideElement(eName)
{
	var e = document.getElementById(eName);
	e.style.visibility = 'hidden';
	e.style.display = 'none';
}

function getRadioButtonValue(radioButtonArray) {
	var value = '';
	
	if (!radioButtonArray.length) {
		// Only one radio button, so form.radiobuttonname returns a radiobutton element, not an array
		if (radioButtonArray.checked) {
			value = radioButtonArray.value;
		}
	}
	else {
		for (var i=0; i<radioButtonArray.length; i++) {
			if (radioButtonArray[i].checked) {
				value = radioButtonArray[i].value;
				break;
			}
		}
	}
	
	return value;
}

function GetElementPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}

function SetValue(id, newValue) {
	identity=document.getElementById(id);
	identity.value=newValue;
}

function SetInnerHtml(id, newValue) {
	identity=document.getElementById(id);
	identity.innerHTML=newValue;
}

function SetStyle(id, newClass) {
	identity=document.getElementById(id);
	identity.className=newClass;
}

function isEmail(email) {
	var invalidCharString = " ,<>!\"?%^&*()+=*/\\\';:#~[]{}";
	var i = 0;
	
	for (i = 0; i < invalidCharString.length; i++) {
		if (-1 < email.indexOf(invalidCharString.charAt(i))) {
			return false;
		}
	}
	
	var firstAt = email.indexOf('@');
	var lastAt = email.lastIndexOf('@');
	var lastDot = email.lastIndexOf('.');
	if (!((0 < firstAt) && (1 < lastDot) && (firstAt == lastAt) && ((firstAt + 1) < lastDot) && (lastDot < (email.length - 2)))) 
	{
		return false;
	}
	else {
		return true;
	}
}

function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
var dtCh= "/";
var minYear=1900;
var maxYear=2100;
	var daysInMonth = DaysArray(12);
	var pos1=dtStr.indexOf(dtCh);
	var pos2=dtStr.indexOf(dtCh,pos1+1);
	var strDay=dtStr.substring(0,pos1);
	var strMonth=dtStr.substring(pos1+1,pos2);
	var strYear=dtStr.substring(pos2+1);
	strYr=strYear;
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1);
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1);
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1);
	}
	month=parseInt(strMonth);
	day=parseInt(strDay);
	year=parseInt(strYr);
	if (pos1==-1 || pos2==-1){
		return false;
	}
	if (strMonth.length<1 || month<1 || month>12){
		
		return false;
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		
		return false;
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		
		return false;
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		
		return false;
	}
return true;
}
function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

function IsNumeric(sText)
{
	var ValidChars = "0123456789.-";
	var IsNumber=true;
	var Char;


	for (i = 0; i < sText.length && IsNumber == true; i++) 
	{ 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) 
		{
			IsNumber = false;
		}
	}
	return IsNumber;
   
}

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function SetVisibility(id, visible) {
	var identity=document.getElementById(id);
	if (visible) {
		identity.className = "visibleElement";
	}
	else {
		identity.className = "hiddenElement";
	}
}

function getInputArrayValue(inputArray) {
	var value = '';
	
	if (!inputArray.length) {
		// Only one radio button, so form.radiobuttonname returns a radiobutton element, not an array
		if (inputArray.checked) {
			value = inputArray.value;
		}
	}
	else {
		for (var i=0; i<inputArray.length; i++) {
			if (inputArray[i].checked) {
				value = inputArray[i].value;
				break;
			}
		}
	}
	
	return value;
}

function InsertTextAtCursor(inputElement,textToInsert) {
	inputElement.focus();
	
	if (inputElement.selectionStart) {
		var curPos = inputElement.selectionStart;
		inputElement.value = inputElement.value.substr(0,inputElement.selectionStart) + textToInsert + inputElement.value.substr(inputElement.selectionEnd,inputElement.value.length);
		inputElement.selectionStart = curPos + textToInsert.length;
		inputElement.selectionEnd = inputElement.selectionStart;
	}
	else if (document.selection) {
		var sel = document.selection.createRange();
		sel.text = textToInsert;
	}
	else {
		inputElement.value += textToInsert;
	}
}

function NoneLink() {}

function ReturnKeyCheck(source, e) {
	var characterCode; // literal character code will be stored in this variable
	
	if (e && e.which){ //if which property of event object is supported (NN4)
		characterCode = e.which; //character code is contained in NN4's which property
	}
	else{
		characterCode = e.keyCode; //character code is contained in IE's keyCode property
	}
	
	return (characterCode == 13);
}

function NewWindowLink(a) {
	if (!window.focus) 
	{
		return true;
	}
	window.open(a.href,"_blank");
	return false;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function ValidateEnquiry()
{
	var msg="";
	var f = document.getElementById('frmEnquiry');	
	
	if(f.txtName.value == "")
	{
		msg += "\r\n- Name";
	}
	
	if(f.txtEmail.value == "")
	{
		msg += "\r\n- Email";
	}
	else if(!isEmail(f.txtEmail.value))
	{
		msg += "\r\n- Valid email";
	}
	
	if(msg == "")
	{
		document.frmEnquiry.submit();
	}
	else
	{
		alert("Please complete the following:" + msg);
	}
}

function showMap()
{
	document.getElementById('mapSearch').style.visibility = 'visible';
	document.getElementById('mapSearch').style.display = '';
}

function hideMap()
{
	document.getElementById('mapSearch').style.visibility = 'hidden';
	document.getElementById('mapSearch').style.display = 'none';
}

function CountWords (this_field) 
{
	var char_count = this_field.value.length;
	var fullStr = this_field.value + " ";
	var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi;
	var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, "");
	var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi;
	var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");
	var splitString = cleanedStr.split(" ");
	var word_count = splitString.length -1;
	
	if (fullStr.length <2) {
		word_count = 0;
	}
	
	return word_count;
}

function addPageToFavourites()
{
	// IE 
	if (navigator.appName == "Microsoft Internet Explorer")
	{
		if((parseInt(navigator.appVersion) >= 4))
		{
			if(navigator.userAgent.indexOf("MSIE 7") > 0)
			{
				alert("To add this page to your favourites please either press Ctrl+D on your keyboard or click the 'Add to Favorites' button in the Internet Explorer toolbar.");
			}
			else
			{
				window.external.AddFavorite (location.href, document.title); 
			}
		}
	} 
	else 
	{
		window.sidebar.addPanel ( document.title, location.href,""); 
	}
}

function ShowFlashPlayer(f,w,h)
{
	CloseFlashPlayer();
	 
	var s = '<p class="closePlayerLink"><a href="JavaScript:CloseFlashPlayer()" class="closePlayerLink">Close player</a></p><object width="' + w + '" height="' + h + '"><param name="movie" value="' + basehref + 'swf/' + f + '"><embed src="' + basehref + 'swf/' + f + '" type="application/x-shockwave-flash" width="' + w + '" height="' + h + '"></embed></object>';

	document.getElementById('flashplayercontainer').innerHTML = s;	
	
	h += 18;
	
	document.getElementById('flashplayercontainer').style.width = w + 'px';
	document.getElementById('flashplayercontainer').style.height = h + 'px';
	
	var ScrollTop = 0;

	if (window.pageYOffset)
	{
		ScrollTop = window.pageYOffset;
	}
	else if(document.getElementById('flashplayercontainer').offsetParent)
	{
		ScrollTop = document.getElementById('flashplayercontainer').offsetParent.scrollTop;
	}
	else if(document.body.parentElement)
	{
		ScrollTop = document.body.parentElement.scrollTop;
	}
	else
	{
		ScrollTop = 0;
	}


	ScrollTop = ScrollTop + 50;

	document.getElementById('flashplayercontainer').style.top = ScrollTop + 'px';

	var bodyWidth = document.body.clientWidth;
	var availWidth = 741;
	
	var availLeft = 0;

	if(availWidth < bodyWidth)
	{
		availLeft = (bodyWidth - availWidth) / 2;
	}

	availLeft += 100;

	document.getElementById('flashplayercontainer').style.left = availLeft + 'px';
	
	document.getElementById('flashplayercontainer').style.display = '';
	document.getElementById('flashplayercontainer').style.visibility = 'visible';
}

function CloseFlashPlayer()
{
	document.getElementById('flashplayercontainer').innerHTML = '';	
	document.getElementById('flashplayercontainer').style.display = 'none';
	document.getElementById('flashplayercontainer').style.visibility = 'hidden';
}

function RefreshForm() {
	var f = document.getElementById('frmEnquiry');
	f.postback.value = 1;

	f.submit();
}

function submitEnquiry() {
	var msg = "";

	var f = document.getElementById('frmEnquiry');
	
	
	if(f.lstProductReq && f.lstProduct.options && f.lstProduct.options[f.lstProduct.selectedIndex].value=="-1") { msg += "\n- Product"; }
	if(f.lstInfoProductReq && f.lstProduct.options && f.lstProduct.options[f.lstProduct.selectedIndex].value=="-1") { msg += "\n- Information pack request for"; }
	
	if(f.optContactTimesReq)
	{
		if(getRadioButtonValue(f.optContactTimes) == "")
		{
			msg += "\n- My preferred date and times or contact me to discuss";
		}
		else if(getRadioButtonValue(f.optContactTimes) == "Times" && f.txtContactTimes.value == "")
		{
			msg += "\n- Preferred date and times";
		}
	}
	
	if(f.txtContactNameReq && f.txtContactName.value=="") { msg += "\n- Name"; }
	if(f.txtPracticeNameReq && f.txtPracticeName.value=="") { msg += "\n- Business name"; }
	if(f.txtAddressReq && f.txtAddress.value=="") { msg += "\n- Postal address"; }
	if(f.txtPostCodeReq && f.txtPostCode.value=="") { msg += "\n- Post code"; }
	if(f.txtTelephonReq && f.txtTelephone.value=="") { msg += "\n- Telephone"; }
	
	if(f.txtEmailReq && f.txtEmail.value=="") 
	{
		msg += "\n- E-mail address"; 
	}
	else if(f.txtEmailReq && !isEmail(f.txtEmail.value))
	{
		msg += "\n- Valid e-mail address"; 
	}
	
	if(f.chkProductReq)
	{
		var chkCount = 0;
		var elems = f.elements;
		for (var ix=0; ix < elems.length; ix++) {
			var elem = elems[ix];

			if(elem.name.substring(0, 10) == 'chkProduct' && elem.checked)
			{
				chkCount++;
			}
		}		
		
		if(chkCount == 0)
		{
			msg += "\n- Select at least one product";
		}
	}
	
	if(f.txtTelephoneReq && f.txtTelephone.value=="") { msg += "\n- Telephone"; }
	
	if(f.optSendPrefReq && getRadioButtonValue(f.optSendPref) == "")
	{
		msg += "\n- How would you prefer to receive the information pack?";
	}
	
	if(f.optSendPrefReqPresentation && getRadioButtonValue(f.optSendPref) == "")
	{
		msg += "\n- How would you prefer to be contacted?";
	}

	if(f.lstSectorReq && f.lstSector.options && f.lstSector.options[f.lstSector.selectedIndex].value=="-1") { msg += "\n- Type of business"; }
	

	if(f.txtTrialUsersReq && f.txtTrialUsers.value=="") 
	{
		msg += "\n- Number of users for trial"; 
	}
	else if(f.txtTrialUsersReq && !IsNumeric(f.txtTrialUsers.value))
	{
		msg += "\n- Number of users for trial must be numeric"; 
	}
		
	if(f.txtPracticeSizeReq && f.txtPracticeSize.value=="") 
	{
		msg += "\n- Practice size"; 
	}
	else if(f.txtPracticeSizeReq && !IsNumeric(f.txtPracticeSize.value))
	{
		msg += "\n- Practice size must be numeric"; 
	}
	
	if(f.lstTrialUsersReq && f.lstTrialUsers.selectedIndex == 0) { msg += "\n- Number of users for trial"; }
	if(f.lstPracticeSizeReq && f.lstPracticeSize.selectedIndex == 0) { msg += "\n- Number of potential users"; }
	
	if(f.lstHeardAboutReq && f.lstHeardAbout.selectedIndex == 0) { msg += "\n- How did you become aware of our software?"; }
	
	if (trim(f.captchatext.value) == "") { msg += "\n- The code given in the image at the bottom of the form"; }

	if(msg == "") 
	{
		f.submit();
	}
	else 
	{
		alert("Please complete the following:" + msg);
	}
}

function setTextAreaMaxLengths()
{
	var textareaArray = document.getElementsByTagName('textarea');
	if (textareaArray) {
		if (!textareaArray.length) {
			var i = 0;
			if (textareaArray[i] && textareaArray[i].getAttribute('maxlength'))
			{
				textareaArray[i].onkeyup = textareaArray[i].onchange = checkMaxLength;
				textareaArray[i].onkeyup();
			}
		}
		else
		{
			for (var i=0; i<textareaArray.length; i++)
			{
				if (textareaArray[i].getAttribute('maxlength'))
				{
					textareaArray[i].onkeyup = textareaArray[i].onchange = checkMaxLength;
					textareaArray[i].onkeyup();
				}
			}
		}
	}
}

function checkMaxLength()
{
	var maxLength = this.getAttribute('maxlength');
	var currentLength = this.value.length;
	if (currentLength > maxLength)
	{
		this.value = this.value.substring(0,maxLength);
	}
}

function OpenVideoViewer(id, w, h, filename, openPopup)
{
	if(openPopup == 1)
	{
		ShowPopUp(basehref + 'VideoViewer.cfm?id=' + id, w + 28, h + 30)
	}
	else
	{
		var vidContent = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab##version=6,0,29,0" width="' + w + '" height="' + h + '" ID="Captivate1">';	
		vidContent += '<param name="movie" value="library/' + filename + '">';
		vidContent += '<param name="quality" value="high">';
		vidContent += '<param name="menu" value="false">';
		vidContent += '<param name="loop" value="0">';
		vidContent += '<embed src="library/' + filename + '" width="' + w + '" height="' + h + '" loop="0" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" menu="false"></embed>';
		vidContent += '</object>';

		var d = document.getElementById('divDlgVideoViewer');
		d.innerHTML = vidContent;

		$('#divDlgVideoViewer').dialog('open');
	}
}


/* Page Slide */
var slideLX = 0;
var slideCX = 0;
var slideRX = 0;
var slideOffScreen = 0;

var cancelCarouselNudge = false;

var pageLeft = 0;
var pageWidth = 0;

var furtherInfoTop = 645;

// On load code

$(document).ready(function() {

	positionPageElements();

	if(initSlider === true)
	{
		if(slideLeftI > 0)
		{
			$("#contentcontainer" + slideLeftI).hide();
			$("#contentcontainer" + slideLeftI).load(basehref+'slides/loadslideajax.cfm?id='+slideMenuIDs[slideLeftI], function() { $(this).fadeIn(); setupRevealLinks(); });
		}

		if(slideRightI > 0)
		{
			$("#contentcontainer" + slideRightI).hide();
			$("#contentcontainer" + slideRightI).load(basehref+'slides/loadslideajax.cfm?id='+slideMenuIDs[slideRightI], function() { $(this).fadeIn(); setupRevealLinks(); });
		}


		if(slideCount > 1)
		{
			for(i = 1; i <= slideCount; i++)
			{
				if(i != slideLeftI && i != slideCentreI && i != slideRightI)
				{
					$("#contentcontainer" + i).hide();
					$("#contentcontainer" + i).load(basehref+'slides/loadslideajax.cfm?id='+slideMenuIDs[i], function() { $(this).fadeIn(); setupRevealLinks(); });
				}
			}
		}

		$("#leftarrowcontainer").mouseover(function() { leftArrowOver() });
		$("#rightarrowcontainer").mouseover(function() { rightArrowOver() });
		$("#furtherinfoimage").mouseover(function() { furtherInfoOver() });

		$("#leftarrowcontainer").mouseout(function() { leftArrowOut() });
		$("#rightarrowcontainer").mouseout(function() { rightArrowOut() });
		$("#furtherinfoimage").mouseout(function() { furtherInfoOut() });

		$("#leftarrowcontainer").click(function() { leftArrowClick() });
		$("#rightarrowcontainer").click(function() { rightArrowClick() });
		$("#furtherinfoimage").click(function() { furtherInfoShow() });
	}
	
	setupRevealLinks();;
	
	$(window).resize(function() { positionPageElements(); });
});

function positionPageElements()
{
	pageLeft = $('#headercontainer').offset().left + 1;
	pageWidth = $("#headercontainer").width() - 2;
	var buttonWidth = $("#leftarrowcontainer").width();

	if(initSlider === true)
	{
		var lArrowPos = (pageLeft - buttonWidth) + 10;
		var rArrowPos = (pageLeft + pageWidth) - 10;
	
		$("#leftarrowcontainer").css('left', lArrowPos + 'px');
		$("#rightarrowcontainer").css('left', rArrowPos + 'px');

		slideCX = pageLeft;
		slideLX = pageLeft - pageWidth;
		slideRX = pageLeft + pageWidth;
		slideOffScreen = 0 - pageWidth;

		$("#contentcontainer" + slideLeftI).css('left', slideLX + 'px');
		$("#contentcontainer" + slideCentreI).css('left', slideCX + 'px');
		$("#contentcontainer" + slideRightI).css('left', slideRX + 'px');
		
		for(i = 1; i <= slideCount; i++)
		{
			if(i != slideLeftI && i != slideCentreI && i != slideRightI)
			{
				$("#contentcontainer" + i).css('left', slideOffScreen + 'px');
			}
		}
		
		var furtherInfoLeft = slideCX + ((pageWidth / 2) - 38);
		$('#furtherinfocontainer').css('left', furtherInfoLeft + 'px');
		
		$('#footercontainer').css('left', (slideCX + 20) + 'px');
		$('#formcontainer').css('left', slideCX + 'px');
		
		var maskWidth = (($(window).width() - pageWidth) / 2) - 1;
		$('#leftmask').width(maskWidth);
		$('#rightmask').width(maskWidth);
	
		$('#leftmask').css('left', '0px');
		$('#rightmask').css('left', (slideRX + 1) + 'px');
	}
	
	var logoLeft = (pageLeft + pageWidth) - $("#logocontainer").width() - 21;	
	$("#logocontainer").css('left', logoLeft + 'px');
}

function setupRevealLinks()
{
	$(".RevealContactDetails").mouseover(function() { revealLinkOver(this) });
	$(".RevealContactDetails").mouseout(function() { revealLinkOut(this) });
	$(".RevealContactDetails").click(function() { revealLinkShow(this) });
	
	$(".RevealContactDetailsChar").mouseover(function() { revealLinkOver(this) });
	$(".RevealContactDetailsChar").mouseout(function() { revealLinkOut(this) });
	$(".RevealContactDetailsChar").click(function() { revealLinkShow(this) });
}

function revealLinkOver(e)
{
	$(e).css('cursor', 'pointer');
}

function revealLinkOut(e)
{
	$(e).css('cursor', 'auto');
}

function revealLinkShow(e)
{
	$(e).load('loademailaddress.cfm');
}

function furtherInfoOver()
{
	// $('#furtherinfocontainer').stop();
	$("#furtherinfocontainer").css('cursor', 'pointer');
	
	if(formShown)
	{
		$("#furtherinfoimage").attr('src', 'images/Return_to_page_over.jpg');
	}
	else
	{
		$("#furtherinfoimage").attr('src', 'images/Further_info_over.jpg');
	}
	// var newTop = furtherInfoTop + 5;
	// $('#furtherinfocontainer').animate({top:newTop+'px'},'fast');
}

function furtherInfoOut()
{
	// $('#furtherinfocontainer').stop();
	$("#furtherinfocontainer").css('cursor', 'auto');
	if(formShown)
	{
		$("#furtherinfoimage").attr('src', 'images/Return_to_page.jpg');
	}
	else
	{
		$("#furtherinfoimage").attr('src', 'images/Further_info.jpg');
	}
	// $('#furtherinfocontainer').animate({top:furtherInfoTop+'px'},'fast');
}

function furtherInfoShow()
{
	if(formShown)
	{
		furtherInfoHide();
	}
	else
	{
		$('#formcontainer').css('top', $("#contentcontainer" + slideCentreI).height() + 'px');
		$('#formcontainer').show();
		$("#contentcontainer" + slideCentreI).slideUp();
		$('#formcontainer').animate({top:'0px'}, 'fast', function() { formShown = true; $("#furtherinfoimage").attr('src', 'images/Return_to_page.jpg'); });
		
		window.scrollTo(0,0);
	}
}

function furtherInfoHide()
{
	$('#formcontainer').animate({top:$("#contentcontainer" + slideCentreI).height() + 'px'}, 'fast', function() { $('#formcontainer').hide(); formShown = false; $("#furtherinfoimage").attr('src', 'images/Further_info.jpg'); });
	$("#contentcontainer" + slideCentreI).slideDown();
	window.scrollTo(0,0);
}

function leftArrowOver()
{
	$("#leftarrowimage").attr('src', 'images/left_arrow2_over.png');
	$("#leftarrowimage").css('cursor', 'pointer');

//	nudgeCarousel(10);
}

function rightArrowOver()
{
	$("#rightarrowimage").attr('src', 'images/right_arrow2_over.png');
	$("#rightarrowimage").css('cursor', 'pointer');

//	nudgeCarousel(-10);
}

function leftArrowOut()
{
	$("#leftarrowimage").attr('src', 'images/left_arrow2.png');
	$("#leftarrowimage").css('cursor', 'auto');

//	nudgeCarousel(0);
}

function rightArrowOut()
{
	$("#rightarrowimage").attr('src', 'images/right_arrow2.png');
	$("#rightarrowimage").css('cursor', 'auto');

//	nudgeCarousel(0);
}

function nudgeCarousel(x)
{
	if(!cancelCarouselNudge)
	{

		$('#contentcontainer' + slideLeftI).stop();
		$('#contentcontainer' + slideCentreI).stop();
		$('#contentcontainer' + slideRightI).stop();

		var cLeft = slideLX + x;
		var cCentre = slideCX + x;
		var cRight = slideRX + x;

		$('#contentcontainer' + slideLeftI).animate({left:cLeft + 'px'},'fast');
		$('#contentcontainer' + slideCentreI).animate({left:cCentre + 'px'},'fast');
		$('#contentcontainer' + slideRightI).animate({left:cRight + 'px'},'fast');
	}

	cancelCarouselNudge = false;
}

function showCarouselSlide(i)
{
	furtherInfoHide();
	
	while(slideCentreI != i)
	{
		rotateCarousel(-1);
	}
}

function rotateCarousel(i)
{
	cancelCarouselNudge = true;
	
	for(x = 1; x <= slideCount; x++)
	{
		$('#contentcontainer' + x).height(580);
	}

	$('#contentcontainer' + slideLeftI).stop();
	$('#contentcontainer' + slideCentreI).stop();
	$('#contentcontainer' + slideRightI).stop();

	var iToL = 0;
	var iToC = 0;
	var iToR = 0;

	var newslideLeftI = 0;
	var newslideCentreI = 0;
	var newslideRightI = 0;

	if(i > 0)
	{
		newslideLeftI = slideLeftI - 1;
		if(newslideLeftI < 1)
			newslideLeftI = slideCount;

		newslideCentreI = slideLeftI;
		newslideRightI = slideCentreI;

		moveSlide(slideRightI, slideOffScreen, true);
		moveSlide(newslideLeftI, slideLX - pageWidth, true);
		moveSlide(newslideRightI, slideRX, false);
		moveSlide(newslideCentreI, slideCX, false);
		moveSlide(newslideLeftI, slideLX, false);
	}
	else if(i < 0)
	{
		newslideLeftI = slideLeftI - 1;
		if(newslideLeftI < 1)
			newslideLeftI = slideCount;

		newslideLeftI = slideCentreI;
		newslideCentreI = slideRightI;

		newslideRightI = newslideCentreI + 1;
		if(newslideRightI > slideCount)
			newslideRightI = 1;

		moveSlide(slideLeftI, slideOffScreen, true);
		moveSlide(newslideRightI, slideRX + pageWidth, true);
		moveSlide(newslideLeftI, slideLX, false);
		moveSlide(newslideCentreI, slideCX, false);
		moveSlide(newslideRightI, slideRX, false);
	}

	slideCentreI = newslideCentreI;
	slideLeftI = newslideLeftI;
	slideRightI = newslideRightI;

	updateSlideBullet();
}

function moveSlide(i, newX, instant)
{
	if(instant)
		$('#contentcontainer' + i).css('left', newX + 'px');
	else
		$('#contentcontainer' + i).animate({left:newX + 'px'});
}

function leftArrowClick()
{
	furtherInfoHide();
	rotateCarousel(1);
}

function rightArrowClick()
{
	furtherInfoHide();
	rotateCarousel(-1);
}

function updateSlideBullet()
{
	for(i = 1; i <= slideCount; i++)
	{
		$('#slidebullet' + i).attr('src', 'images/slidebulletoff.png');
	}

	$('#slidebullet' + slideCentreI).attr('src', 'images/slidebulleton.png');
}


