var coord = {'location1':'169,90' , 'location2':'215,200' , 'location4':'281,291' , 'location5':'290,207',
             'location6':'270,131' , 'location7':'390,280','location8':'382,208' , 'location9':'431,245',
             'location11':'402,198' , 'location12':'327,261' , 'location13':'359,353' , 'location14':'408,395' ,
             'location15':'376,318' , 'location16':'315,328' , 'location17':'426,370' , 'location18':'398,323' ,
             'location19':'308,360' ,'location20':'448,373' , 'location21':'484,356' , 'location22':'483,414' ,
             'location23':'423,328' , 'location24':'570,384' , 'location25':'664,310' , 'location26':'688,337' ,
             'location27':'587,418' , 'location28':'638,361' , 'location29':'424,356' , 'location30':'408,356' ,
             'location34':'449,355' , 'location35':'346,289'  , 'location36':'162,251' , 'location10':'324,199' ,
             'location3':'25,14' };

var mapMaker = {
	offsetX: -16, // tooltip X offset
	offsetY: 16,  // tooltip Y offset
	element: null,
	DLs:     false,
	DTs:     false,
	DDs:     false,
	on:      false,
	/* constructor - sets events */
	init: function(){
		var i=0;
		var ii=0;
		var currentLocation = 0;
		mapMaker.DLs = document.getElementsByTagName('dl');
		mapMaker.DTs = document.getElementsByTagName('dt');
		mapMaker.DDs = document.getElementsByTagName('dd');
		
				
		// only loop thru items once
		if( mapMaker.on == false ){
			//loop through each DL on page
			while (mapMaker.DLs.length > i) {
				//only affect DLs with a class of 'map'
				
				if (mapMaker.DLs[i].className == 'map'){
					//change map DL class, this way map is text only without javascript enabled
					mapMaker.DLs[i].className = 'map on';
					//strip whitespace
					mapMaker.stripWhitespace(mapMaker.DLs[i]);
					mapMaker.stripWhitespace(mapMaker.DTs[i]);
					mapMaker.stripWhitespace(mapMaker.DDs[i]);
					// loop thru all DT elements
					while (mapMaker.DTs.length > ii){
						// set the link for the current DT
						currentLocation = mapMaker.DTs[ii].firstChild;
						// add events to links
						mapMaker.addEvt(currentLocation,'mouseover',mapMaker.showTooltip);//displays tooltip on mouse over
						mapMaker.addEvt(currentLocation,'focus',mapMaker.showTooltip);//display tooltip on focus, for added keyboard accessibility
						mapMaker.addEvt(currentLocation,'blur',mapMaker.hideTooltip);//hide tooltip on focus, for added keyboard accessibility
						ii++;
					};
					ii=0;
					//loop through DT elements and assign event to close link
					while (mapMaker.DDs.length > ii){
						currentLocation = mapMaker.DDs[ii].firstChild;
						mapMaker.addEvt(currentLocation,'click',mapMaker.hideTooltip);//hide tooltip on click of close button
						ii++;
					};
					ii=0;
				};
				i++;
			};
			mapMaker.on = true;
		};
	},
	/* SHOW TOOLTIP */
	showTooltip: function() {
		var evt = this;
		var i = 0;
		mapMaker.hideTooltip();
			
      	//Find DD to display - based on currently hovered anchor move to parent DT then next sibling DD
		var objid = evt.parentNode.nextSibling;
		mapMaker.element = objid;//set for the hideTooltip

		//get width and height of background map
		var mapWidth  = objid.parentNode.offsetWidth;
		var mapHeight = objid.parentNode.offsetHeight;

		//get width and height of the DD
		var toopTipWidth = objid.offsetWidth;
		var toopTipHeight = objid.offsetHeight;

		//figure out where tooltip should be places based on point location
		var newX = evt.offsetLeft + mapMaker.offsetX;
		var newY = evt.offsetTop + mapMaker.offsetY;
		
           var x_y = new Array();
           x_y = coord[evt.id].split(","); 
            
         if ((newX + toopTipWidth) < mapWidth  && (newY + toopTipHeight) < mapHeight) {
              
               
               if ( evt.id == "location3" || evt.id == "location1" || evt.id == "location6") {
               
               
               objid.style.background='url(images/globo.png)';    
               
               objid.style.top = (eval(x_y[1]) + 79) + 'px';
               objid.style.left = eval(x_y[0]) - (47) + 'px';
               
               //alert("X : " + newX + " Y : " + newY);
               
               pnta = document.getElementById('punta');
               pnta.innerHTML = "<img src='images/g1.png'>";               
               pnta.style.left = x_y[0] + 'px'; 
               pnta.style.top =  x_y[1] + 'px'; 
               pnta.style.display='block';
               
               }else{  
               
               objid.style.background='url(images/globo.png)';   
               
               objid.style.top = (eval(x_y[1]) - 239) + 'px';
               objid.style.left = (eval(x_y[0]) - 150) + 'px';
               
               pnta = document.getElementById('punta');
               pnta.innerHTML = "<img src='images/g2.png'>";               
               pnta.style.left = (eval(x_y[0]) + 5) + 'px';
               pnta.style.top =  (eval(x_y[1]) - 81) + 'px';
               pnta.style.display='block';
               
              }   
               
         }else if ( (newX + toopTipWidth) > mapWidth  && (newY + toopTipHeight) > mapHeight ){  /*----*/
         
               objid.style.background='url(images/globo.png)';   
               objid.style.top = (eval(x_y[1]) - (170 + 66)) + 'px';
               objid.style.left = (eval(x_y[0]) - 270) + 'px';

               pnta = document.getElementById('punta');
               pnta.innerHTML = "<img src='images/g3.png'>";               
               pnta.style.left = eval(x_y[0]) - 94 + 'px';
               pnta.style.top =  eval(x_y[1]) - 78 + 'px';
               pnta.style.display='block';
        
         }else if ( (newX + toopTipWidth) < mapWidth  && (newY + toopTipHeight) > mapHeight ) {
         
               objid.style.background='url(images/globo.png)';   
               objid.style.top = (eval(x_y[1]) - 239) + 'px';
               objid.style.left = (eval(x_y[0]) - 150) + 'px';
               
               pnta = document.getElementById('punta');
               pnta.innerHTML = "<img src='images/g2.png'>";               
               pnta.style.left = (eval(x_y[0]) + 5) + 'px';
               pnta.style.top =  (eval(x_y[1]) - 81) + 'px';
               pnta.style.display='block';
         }else if ( (newX + toopTipWidth) > mapWidth  && (newY + toopTipHeight) < mapHeight ) {
 
               objid.style.background='url(images/globo.png)';   
               objid.style.top = eval(x_y[1]) - (170 + 82) + 'px';
               objid.style.left = (eval(x_y[0]) - (250)) + 'px';
               
               pnta = document.getElementById('punta');
               pnta.innerHTML = "<img src='images/g3.png'>";               
               pnta.style.left = eval(x_y[0]) - 95 + 'px';
               pnta.style.top =  eval(x_y[1]) - 95 + 'px';
               pnta.style.display='block';
         }
         flitBackGround();
	},
	
	/* HIDE TOOLTIP */
	hideTooltip: function() {
		if (mapMaker.element != null) {
		    pnta = document.getElementById('punta');
            pnta.style.display='none';
			mapMaker.element.style.left = '-9999px';
		};
	},

	addEvt: function(element, type, handler) {
		// assign each event handler a unique ID
		if (!handler.$$guid) handler.$$guid = mapMaker.addEvt.guid++;
		// create a hash table of event types for the element
		if (!element.events) element.events = {};
		// create a hash table of event handlers for each element/event pair
		var handlers = element.events[type];
		if (!handlers) {
			handlers = element.events[type] = {};
			// store the existing event handler (if there is one)
			if (element["on" + type]) {
				handlers[0] = element["on" + type];
			};
		};
		// store the event handler in the hash table
		handlers[handler.$$guid] = handler;
		// assign a global event handler to do all the work
		element["on" + type] = mapMaker.handleEvent;
	},
	handleEvent: function(event) {
		var returnValue = true;
		// grab the event object (IE uses a global event object)
		event = event || mapMaker.fixEvent(window.event);
		// get a reference to the hash table of event handlers
		var handlers = this.events[event.type];
		// execute each event handler
		for (var i in handlers) {
			this.$$handleEvent = handlers[i];
			if (this.$$handleEvent(event) === false) {
				returnValue = false;
			};
		};
		return returnValue;
	},
	fixEvent: function(event) {
		// add W3C standard event methods
		event.preventDefault = mapMaker.fixEvent.preventDefault;
		event.stopPropagation = mapMaker.fixEvent.stopPropagation;
		return event;
	},
	stripWhitespace: function( el ){
		for(var i = 0; i < el.childNodes.length; i++){
			var node = el.childNodes[i];
			if( node.nodeType == 3 &&
				!/\S/.test(node.nodeValue) ) node.parentNode.removeChild(node);
		}
	}
};

function flitBackGround(){
  
var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

if ((version >= 5.5) && (document.body.filters)) 
{
  
  
   
for(var i=0; i<document.images.length; i++)

   {
      var img =document.images[i];
        
      var imgName =img.src.toUpperCase();
         
       
            
      if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
      {
         var imgID = (img.id) ? "id='" + img.id + "' " : ""
         
         var imgClass = (img.className) ? "class='" + img.className + "' " : ""
         
         
         var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "


         var imgStyle = "display:inline-block;" + img.style.cssText 
         if (img.align == "left") imgStyle = "float:left;" + imgStyle
         if (img.align == "right") imgStyle = "float:right;" + imgStyle
         if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
         var strNewHTML = "<span " + imgID + imgClass + imgTitle
         + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
         + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
         + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
           img.outerHTML = strNewHTML
         i = i-1
         
      }
  }
}

}


mapMaker.fixEvent.preventDefault = function() {this.returnValue = false;};
mapMaker.fixEvent.stopPropagation = function() {this.cancelBubble = true;};
mapMaker.addEvt.guid = 1;


/* LOAD SCRIPT */
	/* for Mozilla */
		if (document.addEventListener) {
		   
		
			document.addEventListener("DOMContentLoaded", mapMaker.init, null);
		};
		
	/* for Internet Explorer */
		/*@cc_on @*/
		/*@if (@_win32)
			document.write("<script defer src=ie_onload.js><"+"/script>");
		/*@end @*/
		
	/* for other browsers */
		mapMaker.addEvt( window, 'load', mapMaker.init);