var loopFunction, processRunning, siteCoverAlpha = 0, viewerWidth = 100, viewerHeight = 100, viewerWidths = new Array(), viewerHeights = new Array(), sizeCount = 0, closePosition = 25, loadingImage = false, viewerImage = new Image(), imageAlpha = 0, featureIcon = new Image(), descriptionPosition = -1, displayedDescription, displayTime = null, changeDescription, imageFeatures = new Object();

if(window.location.pathname == '/contactus') {
	document.write('<script type="text/javascript" src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAwAIMDuPOGdUZWhAt4eBOHhRm6tGiNKrV3vLrekjGbx5seiTCUBRRudJPU2bdjI2FdUGCh3RkW2VFQQ"><\/script>');
}

window.onload = function() {
	imageFeatures['completeplan'] = new Array();
	imageFeatures['completeplan'][0] = new Object();
	imageFeatures['completeplan'][0]['posTop'] = 210;
	imageFeatures['completeplan'][0]['posLeft'] = 80;
	imageFeatures['completeplan'][0]['displayDescription'] ='topiary';
	imageFeatures['completeplan'][1] = new Object();
	imageFeatures['completeplan'][1]['posTop'] = 223;
	imageFeatures['completeplan'][1]['posLeft'] = 334;
	imageFeatures['completeplan'][1]['displayDescription'] ='allweathersurface';
	imageFeatures['completeplan'][2] = new Object();
	imageFeatures['completeplan'][2]['posTop'] = 212;
	imageFeatures['completeplan'][2]['posLeft'] = 225;
	imageFeatures['completeplan'][2]['displayDescription'] ='thegreen';
	imageFeatures['completeplan'][3] = new Object();
	imageFeatures['completeplan'][3]['posTop'] = 47;
	imageFeatures['completeplan'][3]['posLeft'] = 306;
	imageFeatures['completeplan'][3]['displayDescription'] ='stannestower';
	imageFeatures['completeplan'][4] = new Object();
	imageFeatures['completeplan'][4]['posTop'] = 179;
	imageFeatures['completeplan'][4]['posLeft'] = 460;
	imageFeatures['completeplan'][4]['displayDescription'] ='pavingstones';
	imageFeatures['completeplan'][5] = new Object();
	imageFeatures['completeplan'][5]['posTop'] = 66;
	imageFeatures['completeplan'][5]['posLeft'] = 455;
	imageFeatures['completeplan'][5]['displayDescription'] ='seatingandtables';
	
	imageFeatures['playarea'] = new Array();
	imageFeatures['playarea'][0] = new Object();
	imageFeatures['playarea'][0]['posTop'] = 300;
	imageFeatures['playarea'][0]['posLeft'] = 475;
	imageFeatures['playarea'][0]['displayDescription'] ='childrensplayarea';
	imageFeatures['playarea'][1] = new Object();
	imageFeatures['playarea'][1]['posTop'] = 100;
	imageFeatures['playarea'][1]['posLeft'] = 410;
	imageFeatures['playarea'][1]['displayDescription'] ='trees';
	imageFeatures['playarea'][2] = new Object();
	imageFeatures['playarea'][2]['posTop'] = 300;
	imageFeatures['playarea'][2]['posLeft'] = 100;
	imageFeatures['playarea'][2]['displayDescription'] ='pavingstones';
	imageFeatures['playarea'][3] = new Object();
	imageFeatures['playarea'][3]['posTop'] = 216;
	imageFeatures['playarea'][3]['posLeft'] = 65;
	imageFeatures['playarea'][3]['displayDescription'] ='topiary';
	imageFeatures['playarea'][4] = new Object();
	imageFeatures['playarea'][4]['posTop'] = 224;
	imageFeatures['playarea'][4]['posLeft'] = 180;
	imageFeatures['playarea'][4]['displayDescription'] ='seatingandtables';
	
	imageFeatures['thegreen'] = new Array();
	imageFeatures['thegreen'][0] = new Object();
	imageFeatures['thegreen'][0]['posTop'] = 235;
	imageFeatures['thegreen'][0]['posLeft'] = 225;
	imageFeatures['thegreen'][0]['displayDescription'] ='thegreen';
	imageFeatures['thegreen'][1] = new Object();
	imageFeatures['thegreen'][1]['posTop'] = 290;
	imageFeatures['thegreen'][1]['posLeft'] = 130;
	imageFeatures['thegreen'][1]['displayDescription'] ='walloflight';
	imageFeatures['thegreen'][2] = new Object();
	imageFeatures['thegreen'][2]['posTop'] = 268;
	imageFeatures['thegreen'][2]['posLeft'] = 357;
	imageFeatures['thegreen'][2]['displayDescription'] ='allweathersurface';
	imageFeatures['thegreen'][3] = new Object();
	imageFeatures['thegreen'][3]['posTop'] = 215;
	imageFeatures['thegreen'][3]['posLeft'] = 22;
	imageFeatures['thegreen'][3]['displayDescription'] ='waterfeature';
	imageFeatures['thegreen'][4] = new Object();
	imageFeatures['thegreen'][4]['posTop'] = 50;
	imageFeatures['thegreen'][4]['posLeft'] = 140;
	imageFeatures['thegreen'][4]['displayDescription'] ='trees';
	imageFeatures['thegreen'][5] = new Object();
	imageFeatures['thegreen'][5]['posTop'] = 110;
	imageFeatures['thegreen'][5]['posLeft'] = 404;
	imageFeatures['thegreen'][5]['displayDescription'] ='stannestower';
	imageFeatures['thegreen'][6] = new Object();
	imageFeatures['thegreen'][6]['posTop'] = 290;
	imageFeatures['thegreen'][6]['posLeft'] = 535;
	imageFeatures['thegreen'][6]['displayDescription'] ='pavingstones';
	
	imageFeatures['artshedtoilet'] = new Array();
	imageFeatures['artshedtoilet'][0] = new Object();
	imageFeatures['artshedtoilet'][0]['posTop'] = 150;
	imageFeatures['artshedtoilet'][0]['posLeft'] = 350;
	imageFeatures['artshedtoilet'][0]['displayDescription'] ='artshedtoilet';
	imageFeatures['artshedtoilet'][1] = new Object();
	imageFeatures['artshedtoilet'][1]['posTop'] = 75;
	imageFeatures['artshedtoilet'][1]['posLeft'] = 75;
	imageFeatures['artshedtoilet'][1]['displayDescription'] ='thegreen';
	imageFeatures['artshedtoilet'][2] = new Object();
	imageFeatures['artshedtoilet'][2]['posTop'] = 50;
	imageFeatures['artshedtoilet'][2]['posLeft'] = 525;
	imageFeatures['artshedtoilet'][2]['displayDescription'] ='topiary';
	
	imageFeatures['waterfeature'] = new Array();
	imageFeatures['waterfeature'][0] = new Object();
	imageFeatures['waterfeature'][0]['posTop'] = 300;
	imageFeatures['waterfeature'][0]['posLeft'] = 115;
	imageFeatures['waterfeature'][0]['displayDescription'] ='waterfeature';
	imageFeatures['waterfeature'][1] = new Object();
	imageFeatures['waterfeature'][1]['posTop'] = 300;
	imageFeatures['waterfeature'][1]['posLeft'] = 492;
	imageFeatures['waterfeature'][1]['displayDescription'] ='seatingandtables';
	imageFeatures['waterfeature'][2] = new Object();
	imageFeatures['waterfeature'][2]['posTop'] = 180;
	imageFeatures['waterfeature'][2]['posLeft'] = 410;
	imageFeatures['waterfeature'][2]['displayDescription'] ='topiary';
	imageFeatures['waterfeature'][3] = new Object();
	imageFeatures['waterfeature'][3]['posTop'] = 50;
	imageFeatures['waterfeature'][3]['posLeft'] = 342;
	imageFeatures['waterfeature'][3]['displayDescription'] ='trees';
	
	imageFeatures['topiary'] = new Array();
	imageFeatures['topiary'][0] = new Object();
	imageFeatures['topiary'][0]['posTop'] = 80;
	imageFeatures['topiary'][0]['posLeft'] = 380;
	imageFeatures['topiary'][0]['displayDescription'] ='topiary';
	imageFeatures['topiary'][1] = new Object();
	imageFeatures['topiary'][1]['posTop'] = 50;
	imageFeatures['topiary'][1]['posLeft'] = 75;
	imageFeatures['topiary'][1]['displayDescription'] ='trees';
	imageFeatures['topiary'][2] = new Object();
	imageFeatures['topiary'][2]['posTop'] = 50;
	imageFeatures['topiary'][2]['posLeft'] = 500;
	imageFeatures['topiary'][2]['displayDescription'] ='thegreen';
	
	if(document.getElementById('map')) {
		if(GBrowserIsCompatible()) {
			var map = new GMap2(document.getElementById('map'));
			map.setCenter(new GLatLng(51.51224,-0.132601), 16);
			map.addOverlay(new GMarker(new GLatLng(51.51224,-0.132601)));
			map.addControl(new GSmallMapControl());
			map.setUIToDefault();
		}
	}
}

function openViewer(viewImage, viewDescription) {
	if(processRunning == null || processRunning == 'openViewer') {
		processRunning = 'openViewer';
		if(document.getElementById('sitecover')) {
			document.getElementById('sitecover').style.top = '0px';
			document.getElementById('sitecover').style.left = '0px';
			if(document.getElementById('viewercontainer')) {
				loopFunction = false;
				if(siteCoverAlpha < 80) {
					siteCoverAlpha += Math.ceil((80 - siteCoverAlpha) / 2);
					loopFunction = true;
				}
				else {
					siteCoverAlpha = 80;
					document.getElementById('viewercontainer').style.top = '0px';
					document.getElementById('viewercontainer').style.left = '0px';
					if(viewerWidth < 630) {
						viewerWidth += Math.ceil((630 - viewerWidth) / 8);
						viewerWidths[viewerWidths.length] = viewerWidth;
						loopFunction = true;
					}
					else {
						viewerWidth = 630;
					}
					document.getElementById('viewer').style.width = viewerWidth +'px';
					document.getElementById('viewer').style.marginLeft = '-'+ Math.floor(viewerWidth / 2) +'px';
					if(viewerHeight < 445) {
						viewerHeight += Math.ceil((445 - viewerHeight) / 8);
						viewerHeights[viewerHeights.length] = viewerHeight;
						loopFunction = true;
					}
					else {
						viewerHeight = 445;
					}
					document.getElementById('viewer').style.height = viewerHeight +'px';
					document.getElementById('viewer').style.marginTop = '-'+ Math.floor(viewerHeight / 2) +'px';
					if(viewerWidth == 630 && viewerHeight == 445) {
						loopFunction = true;
						if(closePosition > 0) {
							closePosition -= Math.ceil(closePosition / 4);
						}
						else {
							closePosition = 0;
						}
						document.getElementById('v_closetab').style.top = '-'+ closePosition +'px';
						if(!loadingImage) {
							document.getElementById('viewer').style.backgroundImage = 'url(/_files/images/core/viewer/loader.gif)';
							viewerImage.src = '/_files/images/ourplans/photos/'+ viewImage +'.jpg';
							featureIcon.src = '/_files/images/core/viewer/feature_marker.png';
							featureIcon.style.position = 'absolute';
							featureIcon.style.cursor = 'pointer';
							loadingImage = true;
						}
						else {
							if(viewerImage.complete) {
								if(imageAlpha == 0) {
									document.getElementById('v_image').appendChild(viewerImage);
									document.getElementById('viewer').style.backgroundImage = 'none';
								}
								if(imageAlpha < 100) {
									imageAlpha += Math.ceil((100 - imageAlpha) / 4);
								}
								else {
									imageAlpha = 100;
									if(document.getElementById('v_desc_'+ viewDescription)) {
										if(descriptionPosition == -1) {
											for(featureCount = 0; featureCount < imageFeatures[viewImage].length; featureCount++) {
												var currentFeature = featureIcon.cloneNode(false);
												currentFeature.style.top = imageFeatures[viewImage][featureCount]['posTop'] +'px';
												currentFeature.style.left = imageFeatures[viewImage][featureCount]['posLeft'] +'px';
												currentFeature.showDescription = imageFeatures[viewImage][featureCount]['displayDescription'];
												currentFeature.onclick = function() {
													changeDescription = false;
													displayDescription(this.showDescription, new Date().getTime());
												}
												document.getElementById('v_features').appendChild(currentFeature);
											}
											descriptionPosition = document.getElementById('v_desc_'+ viewDescription).offsetHeight;
											document.getElementById('v_desc_'+ viewDescription).style.visibility = 'visible';
										}
										else {
											if(descriptionPosition > 0) {
												descriptionPosition -= Math.ceil(descriptionPosition / 8);
											}
											else {
												descriptionPosition = 0;
												if(closePosition == 0) {
													displayedDescription = viewDescription;
													loopFunction = false;
													processRunning = null;
												}
											}
										}
										document.getElementById('v_desc_'+ viewDescription).style.bottom = '-'+ descriptionPosition +'px';
									}
								}
								viewerImage.style.opacity = (imageAlpha / 100);
								viewerImage.style.filter = 'alpha(opacity='+ imageAlpha +')';
							}
						}
					}
				}
				document.getElementById('sitecover').style.opacity = (siteCoverAlpha / 100);
				document.getElementById('sitecover').style.filter = 'alpha(opacity='+ siteCoverAlpha +')';
				if(loopFunction) {
					setTimeout(function() {openViewer(viewImage, viewDescription);}, 10);
				}
			}
		}
	}
}

function displayDescription(viewDescription, clickTime) {
	if(displayTime == null || displayTime == clickTime) {
		displayTime = clickTime;
		processRunning = 'displayDescription';
		if(document.getElementById('v_desc_'+ displayedDescription)) {
			if(document.getElementById('v_desc_'+ viewDescription)) {
				if(displayedDescription != viewDescription) {
					loopFunction = true;
					if(descriptionPosition < document.getElementById('v_desc_'+ displayedDescription).offsetHeight) {
						descriptionPosition += Math.ceil((document.getElementById('v_desc_'+ displayedDescription).offsetHeight - descriptionPosition) / 8);
						document.getElementById('v_desc_'+ displayedDescription).style.bottom = '-'+ descriptionPosition +'px';
					}
					else {
						descriptionPosition = document.getElementById('v_desc_'+ displayedDescription).offsetHeight;
						document.getElementById('v_desc_'+ displayedDescription).style.bottom = '-'+ descriptionPosition +'px';
						document.getElementById('v_desc_'+ displayedDescription).style.visibility = 'hidden';
						displayedDescription = viewDescription;
						descriptionPosition = document.getElementById('v_desc_'+ displayedDescription).offsetHeight;
						document.getElementById('v_desc_'+ displayedDescription).style.bottom = '-'+ descriptionPosition +'px';
						document.getElementById('v_desc_'+ displayedDescription).style.visibility = 'visible';
						changeDescription = true;
					}
				}
				else {
					if(changeDescription) {
						loopFunction = true;
						if(descriptionPosition > 0) {
							descriptionPosition -= Math.ceil(descriptionPosition / 8);
						}
						else {
							descriptionPosition = 0;
							changeDescription = false;
							loopFunction = false;
							displayTime = null;
							processRunning = null;
						}
						document.getElementById('v_desc_'+ displayedDescription).style.bottom = '-'+ descriptionPosition +'px';
					}
					else {
						displayTime = null;
						processRunning = null;
					}
				}
				if(loopFunction) {
					setTimeout(function() {displayDescription(viewDescription, clickTime);}, 10);
				}
			}
		}
	}
}

function closeViewer() {
	if(processRunning == null || processRunning == 'closeViewer') {
		processRunning = 'closeViewer';
		if(document.getElementById('v_desc_'+ displayedDescription)) {
			loopFunction = true;
			if(descriptionPosition < document.getElementById('v_desc_'+ displayedDescription).offsetHeight) {
				descriptionPosition += Math.ceil((document.getElementById('v_desc_'+ displayedDescription).offsetHeight - descriptionPosition) / 8);
			}
			else {
				descriptionPosition = document.getElementById('v_desc_'+ displayedDescription).offsetHeight;
				while(document.getElementById('v_features').childNodes[0]) {
					document.getElementById('v_features').removeChild(document.getElementById('v_features').childNodes[0]);
				}
				document.getElementById('v_desc_'+ displayedDescription).style.display = 'none';
				if(closePosition < 25) {
					closePosition += Math.ceil((25 - closePosition) / 4);
				}
				else {
					closePosition = 25;
				}
				document.getElementById('v_closetab').style.top = '-'+ closePosition +'px';
				if(imageAlpha > 0) {
					imageAlpha -= Math.ceil(imageAlpha / 4);
				}
				else {
					imageAlpha = 0;
					if(document.getElementById('v_image').childNodes[0]) {
						document.getElementById('v_image').removeChild(document.getElementById('v_image').childNodes[0]);
					}
					sizeCount++;
					var viewerWidthCount = viewerWidths.length - sizeCount;
					if(viewerWidths[viewerWidthCount]) {
						viewerWidth = viewerWidths[viewerWidthCount];
					}
					else {
						viewerWidth = 100;
					}
					document.getElementById('viewer').style.width = viewerWidth +'px';
					document.getElementById('viewer').style.marginLeft = '-'+ Math.floor(viewerWidth / 2) +'px';
					var viewerHeightCount = viewerHeights.length - sizeCount;
					if(viewerHeights[viewerHeightCount]) {
						viewerHeight = viewerHeights[viewerHeightCount];
					}
					else {
						viewerHeight = 100;
					}
					document.getElementById('viewer').style.height = viewerHeight +'px';
					document.getElementById('viewer').style.marginTop = '-'+ Math.floor(viewerHeight / 2) +'px';
					if(closePosition == 25 && (viewerWidth == 100 || viewerHeight == 100)) {
						viewerWidth = 100;
						viewerHeight = 100;
						document.getElementById('viewercontainer').style.top = '-101%';
						document.getElementById('viewercontainer').style.left = '-101%';
						if(siteCoverAlpha > 0) {
							siteCoverAlpha -= Math.ceil(siteCoverAlpha / 2);
						}
						else {
							siteCoverAlpha = 0;
							document.getElementById('sitecover').style.top = '-101%';
							document.getElementById('sitecover').style.left = '-101%';
							document.getElementById('v_desc_'+ displayedDescription).style.display = 'block';
							document.getElementById('v_desc_'+ displayedDescription).style.visibility = 'hidden';
							viewerWidths = new Array();
							viewerHeights = new Array();
							sizeCount = 1;
							loadingImage = false;
							viewerImage = new Image();
							descriptionPosition = -1;
							loopFunction = false;
							processRunning = null;
						}
						document.getElementById('sitecover').style.opacity = (siteCoverAlpha / 100);
						document.getElementById('sitecover').style.filter = 'alpha(opacity='+ siteCoverAlpha +')';
					}
				}
				if(document.getElementById('v_image').childNodes[0]) {
					document.getElementById('v_image').childNodes[0].style.opacity = (imageAlpha / 100);
					document.getElementById('v_image').childNodes[0].style.filter = 'alpha(opacity='+ imageAlpha +')';
				}
			}
			if(descriptionPosition >= 0) {
				document.getElementById('v_desc_'+ displayedDescription).style.bottom = '-'+ descriptionPosition +'px';
			}
			if(loopFunction) {
				setTimeout(function() {closeViewer();}, 10);
			}
		}
	}
}