// $Date:
// $Id:
// $Revision:
document.observe('dom:loaded',briSetWidth);
window.onresize=briSetWidth;

function briSetWidth(){
	w= document.viewport.getWidth();
	if( w>1004){
		m=Math.floor((w-1004)/2);
		$('container').setStyle({marginLeft:m+'px'});	
	}
}
function collectionMenuShow(event){
	allMenuReset();
	a=event.element();
	menu=$(a).next('div');
	$(menu).show();
	$(a).addClassName('active');
	Event.stop(event);

}
function collectionMenuReset(){
	$$('.collectionMenu').each(function(d){
		d.hide();
		d.previous('h2').removeClassName('active');
	});
}
function centerMenuShow(event){
	allMenuReset();
	a=event.element();
	$(a).addClassName('active');
	$(a.id+'Menu').show();
	Event.stop(event);

}

function centerMenuReset(){
	$$('.second a').each(function(a){
		$(a).removeClassName('active');
		$(a.id+'Menu').hide();
	});
}

function allMenuReset(){
	centerMenuReset();
	collectionMenuReset();
}

function briMenuMore(event){
	a=event.element();
	Event.stop(event);
	m=$(a).up('div.centerMenu');
	m.select('h2').each(function(e){ e.show(); });
	m.select('div').each(function(e){ e.show(); });
	$(a).hide();
	m.show();


}
document.observe('dom:loaded', function(){
	$$('.second a').each(function(e){
			$(e).observe('mouseenter', centerMenuShow);
			$(e).observe('click', centerMenuShow);
			$(e.id+'Menu').observe('mouseleave', centerMenuReset);
	});
	
	$$('.collectionMenu').each(function(e){
		e.previous('h2').observe('click', collectionMenuShow);
		e.previous('h2').observe('mouseenter', collectionMenuShow);
		e.observe('mouseleave',collectionMenuReset);

	});
	
	if( Prototype.Browser.IE){
		$$('body').first().addClassName('msie');
					offset=-40;
			$$('.centerMenu').each(function(e){
				e.style.marginLeft=offset+'px';
				offset+=170;
			});
	}
	/* These trap events outside the menu areas to hide them, the how much have Event.stop() to prevent bubbling */
	$$('body').first().observe('click', allMenuReset);
	$$('nav.second').first().observe('mouseover', allMenuReset);
	$$('header').first().observe('mouseover', allMenuReset);
	$('content').observe('mouseover', allMenuReset);

	
});


//CRUFT BELOW

var AJAX_STATUS='<img src="/lib/icons/ajax_loader.gif" height="16" width="16" alt="Loading..." />';
var imgCache = new Image(16,16);
imgCache.src = '/lib/icons/ajax_loader.gif';



function imageClose(){
	$('hoverImage').hide();
	
}


function positionAt(a,e,params){
	if(!params){
		params = { 'under':true};
	}
	if(params.under===null){
		params.under = 1;
	}

	pos=$(a).cumulativeOffset();
	if(params.rightAlign){
		pos.left-=$(e).getDimensions().width;
		pos.left+=$(a).getDimensions().width;
	}
	if(params.under){
		pos.top+=$(a).getDimensions().height;
	}
	if(params.after){
			pos.left+=$(a).getDimensions().width;
	}

	$(e).style.top=pos.top+'px';
	$(e).style.left=pos.left+'px';
	
	$(e).show();
	
}




//Toggle visibility of the passed element with scriptacuous effect


function setMenuCookie(){
	// store state in cookie
	cookie='';
	$$('#leftNav p').each( function(e){if(e.visible()){cookie+='1:';}else{cookie+='0:';}});
	
	temp=document.domain.split(/\./);
	domainName=temp[temp.length-2]+'.'+temp[temp.length-1];
	// cookie should now be: '1:0:0:1..' format 1 for visible, 0 for hidden packed with colons
	document.cookie = 'menu_state='+cookie+'; path=/; domain='+domainName;
	
}


