

GL_ToolTips=new Array();
Last_ToolTip=null;
RUNS=0;
INPROCESS=false;

function urlencode(str) {
str = escape(str);
return str;
str = str.replace('+', '%2B');
str = str.replace('%20', '+');
str = str.replace('*', '%2A');
str = str.replace('/', '%2F');
str = str.replace('@', '%40');
return str;
}


function MouthEvent(e,nx,ny)
{
this.altKey=e.altKey;
this.button=e.button;
if (nx>-1) this.clientX=nx;
else this.clientX=e.clientX;
if (ny>-1) this.clientY=ny;
else this.clientY=e.clientY;
this.ctrlKey=e.ctrlKey;
this.metaKey=e.metaKey;
this.relatedTarget=e.relatedTarget;
this.screenX=e.screenX;
this.screenY=e.screenY;
this.shiftKey=e.shiftKey;
this.documentopia=true;
}

function show_imagemap_over(e,element,eid)
{
	
	var image_offset=($("finder_image_position").viewportOffset());

	var re='(.*)(_bubble_anchor$)';
	var newstr = eid.match(re);
	
	
	re='([0-9])$';
	var inum=newstr[1].match(re);

	

	if ($("finder_image_position_"+inum[1])) {
		var image_offset=($("finder_image_position_"+inum[1]).viewportOffset());
		}
	
	var x=-1;
	var y=-1;

	//alert(element.href);
	//alert(INPROCESS);
	var href_split=element.href.split("/");
	var last_element=href_split.pop();
	var lalt=urlencode(element.alt);
	


	var re='mouthshift\((.*,.*)\)';
	var shift=element.title.match(re);
	if (shift && image_offset) {
	var sub_match=shift[1];
	var shifts=(sub_match.match('([0-9]+),([0-9]+)'));


	if (shifts[1] && shifts[2] && image_offset[0] && image_offset[1]) {
		x=(parseFloat(shifts[1])+parseFloat(image_offset[0]));
		y=(parseFloat(shifts[2])+parseFloat(image_offset[1]));
		}
		      }
	


	if (!newstr) {
		return;
		}

	ne=new MouthEvent(e,x,y);

	var item=newstr[1];
	
	Last_ToolTip=item;
	if (GL_ToolTips[item]) {
		GL_ToolTips[item].show(ne);
		return;
		}

	var bitem=item;
		
	var re='(.*)[0-9]';
	var submatch = item.match(re);
	
	
	if (submatch) {
		bitem=submatch[1];
		}
	

	var ourl='balloon_'+bitem+'';
	var nurl='/balloon_'+bitem;

        GL_ToolTips[item]=new HelpBalloon({
                dataURL: nurl,
                icon: $(item+'_bubble_anchor')
                });
	GL_ToolTips[item].show(ne);


}

function hide_imagemap_over(e)
{

	//	shieldcan.hide()

}

function container_click(e)
{
	GL_ToolTips[Last_ToolTip].hide();
	return;
alert('container_click');	
alert(Last_ToolTip);
}

Event.observe(window, 'load', function() {
		// RUNS ONCE
	MM_preloadImages('/images/balloon-custom-0.png','/images/balloon-custom-1.png','/images/balloon-custom-2.png','/images/balloon-custom-3.png');

	for (i=1;i<=9;i++) {
		if($('Balloon_Map'+i)) {		
	
        var mapLinks = $('Balloon_Map'+i).childNodes;
        $A(mapLinks).map(function(element) {
		
		if (element.id) {
                Event.observe(element, 'mouseover',function (event) {
			show_imagemap_over(event,element,element.id);
			}
			); 
                Event.observe(element, 'mouseout',hide_imagemap_over); 
			}
        });
    }
    } // FOR
        
 	Event.observe('container-click','click',container_click);
    
});
	
