// JavaScript Document

//first, make some global variables
var _menustate = 'open';
var _fixedstate = 'closed';
var _drag = '';

//persist menu location by grabbing a session cookie
//Cookie.init({name: 'menuxy'});

//now let's fire some initial events to set up the page and navigation
document.observe("dom:loaded", init);

function init(){
	
	
	
	var _nav = $('globalnav');
	
	
	
	
	//_nav.style.visibility = 'visible';
	
/*
	
	if(Cookie.getData('x') != 'undefined' && Cookie.getData('x') != undefined){	
			//alert(Cookie.getData('x'));
	_nav.style.left = Cookie.getData('x');
	
	_nav.style.top = Cookie.getData('y');

	_menustate = Cookie.getData('menustate');
	
		if(_menustate == 'closed'){
		$('twocol_default').style.display = 'none';
		$('toggle').style.backgroundPosition = '0px 1px';
		}
	
	}
	
	
	
	
	_nav.style.visibility = 'visible';
	
	
	//set up some event handlers for the core menus
	Event.observe($('toggle'), 'click',  switchMenu);
	Event.observe($('fixednavtoggle'), 'click',  switchFixed);
	
	
	//finally, make draggable (needs to be last to avoid cookie overwrite issues).
	
	//to do - make loop and all items with clas draggable as draggable
	//var _draggables = $$('div.draggable');

	
	_drag = new Draggable('globalnav', {handle: 'handle', snap: function(x, y) {
            return[ (x < 1200) ? (x > -200 ? x : -200 ) : 1200,
                    (y < 800) ? (y > 0 ? y : 0) : 800 ];
    },
 onEnd: handleRelease});
 */

Event.observe($('toggle'), 'click',  switchMenu);

//now reposition lower navigation based on dynamic height + position of main content item

var _contentHeight = $('display_content').getHeight();
$('fixednav').style.top = (_contentHeight + 140)+'px';
$('fixednav').style.visibility = 'visible';



}

function handleRelease(){
	//update cookie with each menu release
	Cookie.setData('x', $('globalnav').style.left);
	Cookie.setData('y', $('globalnav').style.top);
}

//menu name hardcoded here... may need to be passed in from PHP. Watch out for this!
function switchMenu(){
	
	if(_menustate == 'open'){
	_menustate = 'closed';
	Effect.Shrink('mainnav_default', {direction:'top-left', duration: 0.5});
	$('toggle').style.backgroundPosition = '0px 0px';
	$('toggle').style.backgroundColor = '#FFFFFF';
	}
	else{
		$('toggle').style.backgroundColor = 'transparent';
	_menustate = 'open';
	Effect.Grow('mainnav_default', {direction:'top-left', duration: 0.5});
	$('toggle').style.backgroundPosition = '-20px 0px';
	
	}
}


function switchFixed(){
	
	
	
	
	if(_fixedstate == 'open'){
	_fixedstate = 'closed';
	new Effect.Move('fixednav', { x: -304, y: 0, mode: 'relative' });
	//Effect.Shrink('fixednavcontent', {direction:'top-left', duration: 0.5});
	$('fixednavtoggle').style.backgroundPosition = '0px 5px';
	}
	else{
	_fixedstate = 'open';
	new Effect.Move('fixednav', { x: 304, y: 0, mode: 'relative' });
	//Effect.Grow('fixednavcontent', {direction:'top-left', duration: 0.5});
	$('fixednavtoggle').style.backgroundPosition = '-20px 5px';
	}
}