
var debug = false;
var speed = .15;
var currentPane = 0;
var Panes = $H({ });


	
var	path = location.href;
	if(i=path.indexOf('/',7)) path = path.substr(i);
	if((i=path.lastIndexOf('.')) > (path.length-5)) path = path.substr(0, i);
	path = path.split('/').without('');
	if(path.length==0) path.push('home');



//	add an IE6 bool val to Prototype
Prototype.Browser.IE6 = Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5)) == 6;

	
Event.observe(window, 'load', function() {
	
	if($('nav1')) {
		heads = $('nav1').getElementsBySelector('a');
		heads.each(function(item) {
			
			if(!item.hasClassName('selected')) {
				id = item.id.substr(4);
				
				//	clone this head and put it in the hover menu (this will layer over the existing head, with shadow)			
				head = $('head'+id).cloneNode(true);
				
				//	id 99 is the language link, and is fixed width based on css
				if(id!=99){
					w = $('head'+id).getWidth() - 18;
					head.setStyle({'width': w+'px'});
				}
				head.removeAttribute('id');
				
				head = Element.extend(document.createElement('li')).appendChild(head);
				tophead = Element.extend(document.createElement('ul')).addClassName('top');
				tophead.appendChild(head);
				tophead.setStyle({'display':'none'});
				
				//$('pane'+id+'_slider').down('div').insertBefore(tophead, $('pane'+id+'_slider').down('ul'));
				$('pane'+id).insertBefore(tophead, $('pane'+id).down('div'));
				
				
				//	define a mouse over event for this head link
				Event.observe('head'+id, 'mouseover', expandPane.bindAsEventListener($('head'+id),id));
				
				//	initiate a Pane effect holer
				Panes[id] = null;
				}
			});
		}
	
	
	

	//	for debugging
	if(debug) init_output();
	
});





//	for debugging
function output(msg){
	if( ! $('output')) return;
	$('output').insert({top:'<div>'+msg+'</div>'});
	if($$('#output div').length > 5) $('output').down(5).remove();
}
function init_output(){ if( ! $('output') ) $$('body').first().insert('<div id="output" style="position:absolute;top:10px;left:10px;text-align:left;font-size:.8em;"></div>'); }






function expandPane(e){
	
	id = $A(arguments)[1];
		
//	if($('head'+id).hasClassName('hover')) return true;

	if(currentPane != 0){
		clearPane(currentPane);
		Event.stopObserving(document, 'mousemove', rolloutHandler);
		}
	
	offset = Position.positionedOffset($('head'+id));
	offset[0] -= 8;
	offset[1] += $('head'+id).getHeight();
	if(Prototype.Browser.IE6) offset[1] -= 2;
	
	$('pane'+id).setStyle({
		left: offset[0]+'px',
		top: offset[1]+'px'
		});
	$('pane'+id).down('ul.top').setStyle({ top: '-'+offset[1]+'px' }).show();
	
	
//	$('head'+id).addClassName('hover');
	Panes[id] = new Effect.BlindDown('pane'+id+'_slider' , {duration:speed});
	currentPane = id;
	
	Event.observe(document, 'mousemove', rolloutHandler);
	
	}




function clearPane(id,smooth){
	
	if(!Panes[id]) return false;
	
//	$('head'+id).removeClassName('hover');

	$('pane'+id).down('ul.top').hide();

	Panes[id].loop(Panes[id].startOn+speed*1000);
	if(!smooth){
		Panes[id].element.hide();
		Panes[id] = null;
		}
	else Panes[id] = new Effect.BlindUp('pane'+id+'_slider' , {duration:speed*.5});

	}




function rolloutHandler(e){

	var x = Event.pointerX(e);
	var y = Event.pointerY(e);

	inside = Position.within($('pane'+currentPane), x , y);
	inside = (inside || Position.within($('head'+currentPane), x , y));
	
	/*
	var inside = Position.within($('head'+currentPane), x , y);
	menus = $('pane'+currentPane).getElementsByClassName('menu');
	menus.each(function(item) {
		if(Position.within(item, x , y)) inside = true;
		});
	*/

	if(!inside) {
		Event.stopObserving(document, 'mousemove', rolloutHandler);
		clearPane(currentPane,true);
		}

	}









