YAHOO.namespace("rentals");

YAHOO.rentals = {
	mapdiv: null
	,Map: null
	,areaimgs: {}
	,currentimage: null
};
	
YAHOO.rentals.preloadImages = function(){
	var $this = YAHOO.rentals;
	var areas = $this.Map.getElementsByTagName('area');
	var area,coords,src,image;
	//the first poly coordinates pair is the corresponding image name
	for(var i = 0; i<areas.length; i++){
		area = areas.item(i);
		href = area.href;
		coords = area.coords;
		src = coords.split(",",2);
		src = src.join("-") + ".gif";
		image = document.createElement("img");
		image.src = '/html/ce/images/canada-map/'+src;
		image.style.position = 'absolute';
		image.style.display = 'none';
		image.style.zIndex = 2;
		image.style.top = 0;
		image.style.left = 0;
		$this.mapdiv.appendChild(image);
		$this.areaimgs[href] = image;
	}
}
YAHOO.rentals.mouseover = function(e){
	var $this = YAHOO.rentals;
	var target = YAHOO.util.Event.getTarget(e);
	YAHOO.log('mouseover '+target.tagName);
	if ( target.tagName.toLowerCase() == 'area' ){
		if ( $this.areaimgs[target.href] === $this.currentimage ) return;
		$this.currentimage = $this.areaimgs[target.href];
		$this.currentimage.style.display = 'inline';
	}
	//else if ( $this.currentimage ) $this.currentimage.style.display = 'none';
}
YAHOO.rentals.mouseout = function(e){
	YAHOO.log('mouseout');
	var $this = YAHOO.rentals;
	if ( $this.currentimage ){
		$this.currentimage.style.display = 'none';
		$this.currentimage = null;
	}
}


YAHOO.rentals.load = function(){
	var $this = YAHOO.rentals;
	$this.mapdiv = $('mapdiv');
	if ( !$this.mapdiv ) return;
	$this.Map = $('Map');
	if ( !$this.Map ) return;
	$this.preloadImages();
	$this.mapdiv.style.position = 'relative';
	var img = $('MapImg');
	$this.mapdiv.style.width = ''+img.width+'px';
	$this.mapdiv.style.height = ''+img.height+'px';
	img.style.position = 'absolute';
	img.style.top = 0;
	img.style.left = 0;
	img.style.zIndex = 1;
	img.removeAttribute("useMap");

	//create a transparent 'cover' at zIndex 3; highliting images displayed at zIndex 2
	var cover = document.createElement("img");
	cover.src = '/html/images/blank.gif';
	cover.width = img.width;
	cover.height = img.height;
	cover.setAttribute("useMap","#Map");
	cover.style.position = 'absolute';
	cover.style.top = 0;
	cover.style.left = 0;
	cover.style.zIndex = 3;
	$this.mapdiv.appendChild(cover);

	YAHOO.util.Event.addListener($this.Map,'mouseover',$this.mouseover);
	YAHOO.util.Event.addListener($this.Map,'mouseout',$this.mouseout);
}
YAHOO.util.Event.addListener(window,'load',YAHOO.rentals.load);


