jQuery.imagemap = {	inelement: false,
					ffGetPosition: 	function(obj) {
										var topValue = 0;
										var leftValue = 0;
										var follow = obj;
										
										while(follow){
											leftValue += follow.offsetLeft;
											topValue += follow.offsetTop;
											follow = follow.offsetParent;
										}
										
										obj.actualPosX = leftValue;
										obj.actualPosY = topValue;
									},
					getEventX:	function(ev){
									if(ev.originalEvent.offsetX){
										return ev.originalEvent.offsetX;
									}
									
									if(typeof ev.originalTarget.actualPosX == 'undefined'){
										jQuery.imagemap.ffGetPosition(ev.originalTarget);
									}
									
									return ev.originalEvent.pageX - ev.originalTarget.actualPosX;
								},
					getEventY:	function(ev){
									if(ev.originalEvent.offsetY){
										return ev.originalEvent.offsetY;
									}
									
									if(typeof ev.originalTarget.actualPosY == 'undefined'){
										jQuery.imagemap.ffGetPosition(ev.originalTarget);
									}
									
									return ev.originalEvent.pageY - ev.originalTarget.actualPosY;
								}
					};
jQuery.fn.imagemap = function(mapinfo) {
	return this.each(function(){
		jQuery(this).click(function(ev){
			var x = jQuery.imagemap.getEventX(ev);
			var y = jQuery.imagemap.getEventY(ev);
			
			for(var i = 0; i < mapinfo.length; i++){
				if((x >= mapinfo[i].top_x) &&
				   (y >= mapinfo[i].top_y) &&
				   (x <= mapinfo[i].bottom_x) &&
				   (y <= mapinfo[i].bottom_y)){
					if(typeof mapinfo[i]['link'] != 'undefined'){
						window.location = mapinfo[i]['link'];
					}else{
						mapinfo[i]['callback'](this,ev);
					}
					
					return;
				}
			}
		});
		
		jQuery(this).mousemove(function(ev){
			var x = jQuery.imagemap.getEventX(ev);
			var y = jQuery.imagemap.getEventY(ev);
			
			for(var i = 0; i < mapinfo.length; i++){
				if((x >= mapinfo[i].top_x) &&
				   (y >= mapinfo[i].top_y) &&
				   (x <= mapinfo[i].bottom_x) &&
				   (y <= mapinfo[i].bottom_y)){
					if(!jQuery.imagemap.inelement){
						$(this).css('cursor','pointer');
						jQuery.imagemap.inelement = true;
					}
					
					return;
				}
			}
			
			if(jQuery.imagemap.inelement){
				$(this).css('cursor','default');
				jQuery.imagemap.inelement = false;
			}
		});
	});
};
jQuery.fn.imagecoords = function() {
	return this.each(function(){
		jQuery(this).click(function(ev){
			var x = jQuery.imagemap.getEventX(ev);
			var y = jQuery.imagemap.getEventY(ev);
			
						
			if ((x < 102) && (y > 274))
				$("body").removeClass().addClass("citizen");
				
			else if ((x > 103 && x < 205) && (y > 274))
				$("body").removeClass().addClass("marine"); 

			else if ((x > 206 && x < 399) && (y > 274))
				$("body").removeClass().addClass("smallbusinessman"); 
				
			else if ((x > 400) && (y > 274))
				$("body").removeClass().addClass("volunteer"); 
			
			if (x < 102)
				$("#photoBox").html("<a href='#'><img src='images/home/citzen.jpg' border='0' id='companion'/></a>");
				if ((y < 274) && $("body").hasClass("citizen") == true)
					window.location.href = '/biography/index.htm';
			else if (x > 103 && x < 205)
				$("#photoBox").html("<a href='#'><img src='images/home/marine.jpg' border='0' id='companion'/></a>");
				if ((y < 274) && $("body").hasClass("marine") == true)
					window.location.href = '/biography/index.htm#Marine';
			else if (x > 206 && x < 399)
				$("#photoBox").html("<a href='#'><img src='images/home/smbusinessman.jpg' border='0' id='companion'/></a>");
				if ((y < 274) && $("body").hasClass("smallbusinessman") == true)
					window.location.href = '/biography/index.htm#Businessman';
			else if (x > 400 )
				$("#photoBox").html("<a href='#'><img src='images/home/volunteer.jpg' border='0' id='companion'/></a>");
				if ((y < 274) && $("body").hasClass("volunteer") == true)
					window.location.href = '/biography/index.htm#Volunteer';
		});
	});
};
