// JavaScript Document
document.observe("dom:loaded",function(){
	$('mainlogo').observe("click",function(){window.location='/';});
	$('leftpanel').observe("click",function(){window.location='/residential-properties.asp';});
	$('rightpanel').observe("click",function(){window.location='/commercial-developments.asp';});
});

//maps.google.co.uk/maps?q=6+Flaghead+Road,+Poole,+Dorset+BH13+7JW+(Anglo+St+James)&hl=en&ll=50.701473,-1.92426&spn=0.011864,0.012896&sll=50.701473,-1.92426&sspn=0.011864,0.012896&vpsrc=6&t=v&hnear=6+Flaghead+Rd,+Poole+BH13+7JW,+United+Kingdom&z=16&iwloc=A

function initMap(){
	var marker;
	var map;
	var geocoder;
	var address;
	var html="<h3 style=\"margin:0;\">Anglo St James</h3>6 Flaghead Road,<br/>Poole,<br/>Dorset,<br/>BH13 7JW<br /><strong>Tel: 07836 525811</strong>";
		   
  if (GBrowserIsCompatible()) {
	map = new GMap2(document.getElementById("map_canvas"));
	map.addControl(new GLargeMapControl());
	map.setCenter(new GLatLng(50.701473,-1.92426), 15);
	marker = new GMarker(new GLatLng(50.701473,-1.92426));
	map.addOverlay(marker);
	map.enableContinuousZoom();
	map.enableScrollWheelZoom();
	marker.openInfoWindowHtml(html);
	GEvent.addListener(marker,"click", function(){marker.openInfoWindowHtml(html);});
	}
}
function initContact(){
	initMap();
	contactValidation = new Validation('frmContact');
	$('frmContact').observe('submit',contactSend)
}

function contactSend(e){
	if (contactValidation.validate()){
		$('btnSend').hide()
		$('contactAjaxLoader').show()
		var strBody=$F('strMessage')
		new Ajax.Request("/ajax/sendenquiry.asp",{method:'post',parameters:$('frmContact').serialize(true),
					 onSuccess: function(transport){
						 try{pageTracker._trackEvent('Contact Form','Sent',$F('strName'))}
						 catch(err){};
						 var response=transport.responseText.strip() || "no response";
						 if (response=="no response"){
							 $('frmContact').update('<h4><abbr title="(f) '+response.stripTags().strip()+'">Oops.</abbr></h4>There was a problem submitting the form. Sorry about that... you might want to <a href="mailto:enquiries@anglostjames.co.uk">email us</a> instead.')
						 }else{
							 $('frmContact').update(response)
							 var _gaq = _gaq || [];
							 _gaq.push(['_trackEvent', 'Contact Form', 'Enquiry']);
						 }
					 },
						 onFailure: function(transport){
						 var response=transport.responseText.strip() || "no response";
							 $('frmContact').update('<h4><abbr title="(f) '+response.stripTags().strip()+'">Oops.</abbr></h4>There was a problem submitting the form. Sorry about that... you might want to <a href="mailto:enquiries@anglostjames.co.uk?body='+encodeURI(strBody)+'">email us</a> instead.')
						 }
					});
	}
	if(e){
		Event.stop(e)
	}
}
function initPanels(){
	$('photopane')._panelID=Math.floor(Math.random()*5)+1
	$('leftpanel').setStyle({backgroundImage: 'url(\'/images/slides/residential'+$('photopane')._panelID+'.jpg\')'});
	$('rightpanel').setStyle({backgroundImage: 'url(\'/images/slides/commercial'+$('photopane')._panelID+'.jpg\')'});
	leftArray = new Array();
	rightArray = new Array();
	for (i=1; i<5; i++){
		leftArray[i]=new Image();
		rightArray[i]=new Image();
		leftArray[i].src='/images/slides/residential'+i+'.jpg';
		rightArray[i].src='/images/slides/commercial'+i+'.jpg';
	}
	new PeriodicalExecuter(rotatePanels,7)
}
function rotatePanels(){
	$('photopane')._panelID=$('photopane')._panelID+1;
	if($('photopane')._panelID==6){$('photopane')._panelID=1};
	new Effect.Opacity('leftpanel',{from:1,to:0,duration:0.2})
	new Effect.Opacity('rightpanel',{from:1,to:0,duration:0.2})
	Element.setStyle.delay(0.3,'leftpanel',{backgroundImage: 'url(\'/images/slides/residential'+$('photopane')._panelID+'.jpg\')'});
	Element.setStyle.delay(0.3,'rightpanel',{backgroundImage: 'url(\'/images/slides/commercial'+$('photopane')._panelID+'.jpg\')'});
	new Effect.Opacity('leftpanel',{from:0,to:1,duration:0.3,delay:0.3})
	new Effect.Opacity('rightpanel',{from:0,to:1,duration:0.3,delay:0.3})
}
