//------
// @TL@ : Avril 2008 : onload auto de initMaps('Map_Bottom')
//  Pas de Down ...
//------

//-- http://www.phon.ucl.ac.uk/home/mark/audio/play.htm  -- Example 4 & 6
//-- http://www.webdesign.org/web/flash-&-swish/swish-tutorials/play-and-stop-control-in-java-script.10785.html

b_ns = (document.layers) ? 1:0 ;
b_ie = (document.all) ? 1:0 ;

Browser = BrowserDetect.browser + ' ' + BrowserDetect.version;
b_ie7 = (Browser == "Explorer 7") ? 1 : 0;
b_ie8 = (Browser == "Explorer 8") ? 1 : 0;

function Play_Sound(soundobj) {
	var thissound= eval("document."+soundobj);
	if ( b_ie7 || b_ie8 ) {
    document.all['BGSOUND_ID'].src='Media/Magic_Harp_5.wav';
  } else {
    thissound.Stop();
    thissound.Play();
	}
}
function Stop_Sound(soundobj) {
	var thissound= eval("document."+soundobj);
	if ( b_ie7 || b_ie8 ) {
    document.all['BGSOUND_ID'].src='Silence.wav';
  } else {
    thissound.Stop();
	}
	if ( ! b_ie ) thissound.Rewind();
}

function Roll_Over_Init() {
	if (document.getElementById) {
		var mapIds = Roll_Over_Init.arguments;			// pass string IDs of containing map elements
		
		var i, j, area, areas;
		
		for (i = 0; i < mapIds.length; i++) {

			areas = document.getElementById( mapIds[ i ] ).getElementsByTagName( "area" );

			//alert("arg=" + areas.length);

			for (j = 0; j < areas.length; j++) {	// loop thru img elements
				area = areas[ j ];
				area.onmousedown = imgSwap;			// set event handlers
				area.onmouseout  = imgSwap;
				area.onmouseover = imgSwap;
				area.onmouseup   = imgSwap;
			}
		}
	}
}

function imgSwap() {
alert("ok");
}

// image swapping event handling
function imgSwap(evt) {
	evt = (evt) ? evt : event;
	var elem = (evt.target) ? evt.target : evt.srcElement;
	var imgClass = elem.parentNode.name;
	
	var shape = elem.shape.substring( 0, 4 );
	var coordr;

	if ( shape == "poly" ) {
		shape = "POLY";
	}	

	if ( shape == "POLY" ) {
		var Attr_coordr = elem.getAttribute("coordr")
		coordr = Attr_coordr.split(",");
	} else {
		coordr = elem.coords.split(",");
	}
  
	var clipVal = "rect(" + coordr[1] + "px " +
							coordr[2] + "px " +
							coordr[3] + "px " +
							coordr[0] + "px)";
	var imgStyle;

	switch (evt.type) {
		case "mouseout" :
			document.getElementById(imgClass + "_over").style.visibility = "hidden";
			if ( shape == "POLY" ) {
				Stop_Sound('MySound');
			}
			//document.getElementById(imgClass + "Down").style.visibility = "hidden";
			break;
		case "mousedown" :
			//imgStyle = document.getElementById(imgClass + "Down").style;
			//imgStyle.clip = clipVal;
			//imgStyle.visibility = "visible";
			break;
		case "mouseover" :
			//alert(shape + " = " + clipVal);
			if ( shape == "POLY" ) {
				Play_Sound('MySound');
			}
			imgStyle = document.getElementById(imgClass + "_over").style;
			imgStyle.clip = clipVal;
			imgStyle.visibility = "visible";
			break
		case "mouseup" :
			//document.getElementById(imgClass + "Down").style.visibility = "hidden";
			// guarantee click in IE
			if (elem.click) {
				elem.click();
			}
			break;
	}

	evt.cancelBubble = true;
	return false;
}

function addLoadEvent( func ) {
	var oldonload = window.onload;
  
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
		if (oldonload) {
			oldonload();
		}
		func();
    }
  }
}

//addLoadEvent( Maps_Init ); 

var Previous_Onload = (window.onload) ? window.onload : function(){};

window.onload = function() { 
	//Previous_Onload();
	Roll_Over_Init('menubarMap');
}

