locationMap = new Object;
locationMap.imagePath = siteRoot + 'images/map/';
locationMap.images    = new Array();
locationMap.regions   = new Array(
	'scotland',
	'eastanglia',
	'eastmidlands',
	'london',
	'northeast',
	'northireland',
	'northwest',
	'southeast',
	'southwest',
	'wales',
	'westmidlands',
	'yorkshire'
);

locationMap.handleMouseOver = function(e) {

  eventSrc = Event.element(e).id;
  eventSrc = eventSrc.replace(/Area/, '');

  if( eventSrc ){
    $('areamap').src = this.imagePath + eventSrc + '.jpg';
  }
}

locationMap.handleMouseClick = function(e) {

  eventSrc = Event.element(e).id;
	
	if( eventSrc )
	  document.location = siteRoot + 'dealer/' + eventSrc + '/1';
		
	Event.stop(e);
}

locationMap.setActions = function() {

  for(i=0;i<this.regions.length;i++){

    areaName = this.regions[i];

    if( $(areaName + 'Area') ){
    
		  $(areaName + 'Area').observe('mouseover', this.handleMouseOver.bind(this));
      $(areaName + 'Area').observe('click', this.handleMouseClick.bind(this));
		}
  }

	if( $('areamap') )
    $('areamap').observe('mouseout', this.reset.bind(this));
}

locationMap.reset = function(e){

  $('areamap').src = this.imagePath + 'map.jpg';
}

locationMap.preloadMapTiles = function() {

  preImage = new Image();

  for(i=0;i<this.regions.length;i++){

    preImage.src = this.imagePath + this.regions[i] + '.jpg';
  }
}

document.observe("dom:loaded", function() {

  locationMap.setActions();
  locationMap.preloadMapTiles();
});

