function addMap(lat,lng,name) {
	var myLatlng = new google.maps.LatLng(lat,lng);
	var myOptions = {
		zoom: 13,
		center: myLatlng,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	}
	var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
	
	var marker = new google.maps.Marker({
		position: myLatlng, 
		map: map,
		title:name
	});   
}
function featureOver(id,pos){
	id.style.backgroundPosition = pos;
	id.style.cursor = "pointer";
}
function featureOut(id,pos){
	id.style.backgroundPosition = pos;
	id.style.cursor = "";
}
function featureClick(id){
	link = $(id).down('a');
	if(link != undefined) {
		location.href = link.href;
	}
}


function scrollImages(){

	var scrollTime = 7000;
	var images;
	var width;
	var current = 0;

    this.setUp = setUp;
    this.scroll = scroll;

	function setUp(id,w) {
		images = $$(id);
		width = w;
		
		if(id.search(/img/) != -1){
			if(images.length == 1){
				return;
			}
		}
		else {
			imagesTest = $$(id+' img');
			if(imagesTest.length == 1){
				return;
			}
		}
		var firstImage = true;
		images.each(function(s, index) {
			if(firstImage){
				firstImage = false;
				s.style.left = '0px';
			}
			else {
	  			s.style.left = width+'px';
	  		}
		});
		setTimeout(this.scroll,scrollTime);
	}

	function scroll(){
		if(images.length == current+1){
			nextCurrent = 0;
		}
		else {
			nextCurrent = current + 1;
		}
		images[nextCurrent].style.left = width+'px';
		new Effect.Move(images[current], { x: -width, y: 0, mode: 'relative' });
		new Effect.Move(images[nextCurrent], { x: -width, y: 0, mode: 'relative' });
		current = nextCurrent;
		setTimeout(scroll,scrollTime);
	}
}

var places=["Guernsey","Jersey","Mayo","Offaly","Westmeath","Longford","Galway","Roscommon","Sligo","Leitrim","Cavan","Kildare","Meath","Tipperary","Laois","Kilkenny","Carlow","Clare","Limerick","Cork","Waterford","Donegal","Monaghan","Wicklow","Dublin","Wexford","Louth","Kerry","Fermanagh","Tyrone","Armagh","Down","Londonderry","Antrim","Bedfordshire","Buckinghamshire","Cambridgeshire","Cheshire","Cornwall","Cumbria","Derbyshire","Devon","Dorset","Durham","East_Sussex","Essex","Gloucestershire","Hampshire","Herefordshire","Hertfordshire","Kent","Lancashire","Leicestershire","Lincolnshire","Norfolk","Northamptonshire","Northumberland","North_Yorkshire","Nottinghamshire","Oxfordshire","Shropshire","Somerset","Staffordshire","Suffolk","Surrey","Warwickshire","West_Sussex","Wiltshire","Worcestershire","Greater_Manchester","Merseyside","South_Yorkshire","Tyne_and_Wear","West_Midlands","West_Yorkshire","London","Rutland","East_Yorkshire","City_of_Bristol","Berkshire","Isle_of_Wight","Aberdeen_City","Aberdeenshire","Angus","Argyll_and_Bute","Clackmannanshire","Dumfries_and_Galloway","Dundee_City","East_Ayrshire","East_Dunbartonshire","East_Lothian","East_Renfrewshire","City_of_Edinburgh","Eilean_Siar","Falkirk","Fife","Glasgow_City","Highland","Inverclyde","Midlothian","Moray","North_Ayrshire","North_Lanarkshire","Perth_and_Kinross","Renfrewshire","Scottish_Borders","South_Ayrshire","South_Lanarkshire","Stirling","West_Dunbartonshire","West_Lothian","Isle_of_Anglesey","Gwynedd","Conwy","Denbighshire","Flintshire","Wrexham","Powys","Ceredigion","Pembrokeshire","Carmarthenshire","Swansea","Neath_Port_Talbot","Bridgend","The_Vale_of_Glamorgan","Rhondda_Cynon_Taff","Merthyr_Tydfil","Caerphilly","Blaenau_Gwent","Torfaen","Monmouthshire","Newport","Cardiff"];var searchMap;
window.onsvgload = function (){
	searchMap = $('search_map').contentDocument;
	places.each(function(item) {
		if(searchMap.getElementById(item)){
			searchMap.getElementById(item).addEventListener('mouseover', respondToOver, false);
			searchMap.getElementById(item).addEventListener('mouseout', respondToOut, false);
			searchMap.getElementById(item).addEventListener('click', respondToClick, false);
		}
	});
}
function respondToOver(event) {
	$('map_name').update(event.target.id.replace(/_/g, " "));
	event.target.style.fill="#357CBD";
}

function respondToOut(event) {
	$('map_name').update('');
	event.target.style.fill="#A0C34A";
}
function respondToClick(event) {
	place = event.target.id.replace(/_/g, " ");
	new Ajax.Request('/sitestyle/templates/home/find-companies.php?place='+event.target.id, { onSuccess:displayCompanies });
}
function displayCompanies(transport){
	var places = transport.responseText.evalJSON(true);

	placesHTML = '';
	places.each(function(item) {
		placesHTML += '<div class="comapany">';
		placesHTML += '<h4>'+item.name+'</h4>';
		placesHTML += '<h5>'+item.phone+'</h5>';
		placesHTML += item.address;
		placesHTML += '<a href="'+item.link+'" class="more">'+item.name+'</a>';
		placesHTML += '<a href="javascript:void(0);" onclick="closeCompany(this);" class="close">Close</a>';
		placesHTML += '</div>';
	});
	if(placesHTML == ''){
		placesHTML += '<div class="comapany">';
		placesHTML += '<h4>The California Company</h4>';
		placesHTML += '<h5>0845 123 5661</h5>';
		placesHTML += '<p>There is currently a DIY option for this county. Please select from the options below:</p>';
		placesHTML += '<a href="/DIY-shutters/" class="diy">DIY Shutters</a>';
		placesHTML += '<a href="/Trade-enquiries/" class="trade">Trade Enquiry</a>';
		placesHTML += '<a href="javascript:void(0);" onclick="closeCompany(this);" class="close">Close</a>';
		placesHTML += '</div>';
	}
	
	$('map_companies').update(placesHTML);
}
function closeCompany(id){
	box = id.ancestors();
	id.hide();
	box[0].hide();
}
