/**
 *	ui.js -> http://locusonus.org/soundmap/
 */



var panels = []; 	// store all panel elements ID





window.onload = function() {
	
	
	// register panels
	var nav  = document.getElementById('nav');
	var divs = document.getElementsByTagName( 'div' );
	
	for( var i=0; i<divs.length; i++ ) {
		if ( divs[i].className=="panel" ) {
			panels[ panels.length ] = divs[i].id;
			divs[i].style.top = ( nav.offsetHeight )+'px';
			if ( navigator.appVersion.indexOf("MSIE")!=-1 ) divs[i].style.left = '-11px';
		}
	}
	
	// initialize _IMG object
	if ( typeof(_IMG)!='undefined' ) _IMG.set();
	else uiSetup();
	
	// init Google Map
	mapSetup();
};

window.onunload = mapDispose;
window.onresize = function() {
	if ( typeof(viewport)!='undefined' ) viewport.update();
}






/**
 * Update container minimum dimension
 */
function uiSetup() {
	document.getElementById('container').style.minWidth  = ( MAP_MIN_WIDTH+228 ) + 'px';
	document.getElementById('container').style.minHeight = ( MAP_MIN_HEIGHT+126 ) + 'px';
}



/**
 * Fix user interface
 */
function uiFix() {
	
	
	var version = /MSIE\s(\d+\.\d+)/.exec( navigator.appVersion );
	
	// fix IE7 container height :
	// _map.setCenter --> force refresh
	if ( version && parseFloat(version[1])<8  ) {
		document.getElementById("main").style.display = 'none';
		document.getElementById("main").style.display = 'block';
	}
}



/**
 * Display/hide the specified panel ID
 * @param id	the element id
 */ 
function panel( id ) {
	if ( !id ) display( panels, 'none' ); // hide all 
	else display(id); // or show the specified
	
}


/**
 * Open the given URL in a new window using the passed window parameters.
 *
 * @param url	the document to be load
 * @param win	the popup window name
 * @param param	an array of windows features
 */
function popup( url, win, param ) {
	window.open(
		url,
		win,
		"left="+((screen.availWidth-param.width)/2)+","+
		"top=0,"+
		"toolbar=no,"+
		"location=0,"+
		"directories=0,"+
		"resizable="+param.resizable+","+
		"menubar=0,"+
		"status=0,"+
		"scrollbars="+param.scrollbars+","+
		"width="+param.width+","+
		"height="+param.height
	);
}


/**
 * Show / hide the element defined bu the given id
 *
 * @param String	the element ID, or a list of element id
 * @param String	[ the display style : block(default), inline, etc… ]
 * @param boolean	[ force the element to stay in the given style (false by default)  ]
 */
function display( id, style, fix ) {

	if ( !style ) style = "block";
	if ( !fix ) fix = false;
	if ( typeof(id)=="string" ) id = [id];
	
	for( var i in id  )
		document.getElementById(id[i]).style.display= 
			document.getElementById(id[i]).style.display== style && !fix ? 'none' : style;
}
