// map_handler.js
// --------------
// Author: Bradley J. Spaulding, USAi.net
// CrystalMotorExpress.com

// initialize_map()
// ----------------
// Must be called *after* DOM is loaded.
// Requires the prototype library.
function find_pos(obj) {
	var left = top = 0;
	if(obj.offsetParent) {
		do {
			left += obj.offsetLeft;
			top += obj.offsetTop;
		} while(obj = obj.offsetParent)
	}
	return [left, top];
}

function initialize_map() {
		Event.observe('contact_us_locations_map', 'click', function(event) {
    if(event.offsetX && event.offsetY) {
    	x = event.offsetX;
	    y = event.offsetY;
	  } else {
	  	pos = find_pos(event.target);
	  	x = event.pageX - pos[0];
	  	y = event.pageY - pos[1];
	  }
	  
		if( x >= 120 && x <= 140 && y >= 76 && y <= 96 ) {
			$('contact_us_ma_terminal_info').show();
			
			$('contact_us_ct_terminal_info').hide();
			$('contact_us_nj_terminal_info').hide();
			
		} else if( x >= 98 && x <= 112 && y >= 92 && y <= 112 ) {
			$('contact_us_ct_terminal_info').show();

			$('contact_us_ma_terminal_info').hide();
			$('contact_us_nj_terminal_info').hide();
			
		} else if( x >= 80 && x <= 100 && y >= 100 && y <= 126 ) {
			$('contact_us_nj_terminal_info').show();
			
			$('contact_us_ct_terminal_info').hide();
			$('contact_us_ma_terminal_info').hide();
		}
	});
	
	Event.observe('contact_us_locations_map', 'mousemove', function(event) {
    if(event.offsetX && event.offsetY) {
    	x = event.offsetX;
	    y = event.offsetY;
	  } else {
	  	pos = find_pos(event.target);
	  	x = event.pageX - pos[0];
	  	y = event.pageY - pos[1];
	  }
	  
		if( x >= 120 && x <= 140 && y >= 76 && y <= 96 ) {
			$('ma_terminal_tooltip').show();

			$('ct_terminal_tooltip').hide();
			$('nj_terminal_tooltip').hide();
		} else if( x >= 98 && x <= 112 && y >= 92 && y <= 112 ) {
			$('ct_terminal_tooltip').show();
			
			$('ma_terminal_tooltip').hide();
			$('nj_terminal_tooltip').hide();
		} else if( x >= 80 && x <= 100 && y >= 100 && y <= 126 ) {
			$('nj_terminal_tooltip').show();

			$('ma_terminal_tooltip').hide();
			$('ct_terminal_tooltip').hide();
		} else {
			$('ma_terminal_tooltip').hide();
			$('ct_terminal_tooltip').hide();
			$('nj_terminal_tooltip').hide();
		}
	});
}