//For switching 
function showValue(selected){
	ditchOverlay();	
	//set up array for the 'creating values' page
	if($('values')){
		var values = $('values').getElements('div');
	}
	//set up array for the 'investment process' page	
	if($('process')){
		var values = $('process').getElements('div');
	}
	//set up array for the 'portfolio' page	
	if($('portfolio-window')){
		var values = $('portfolio-window').getElements('div');
	}
	
	//hide all of the values
	values.each(
		function(value, i){
			//if on the portfolio page, also walks up 2 nodes to the <TR> and sets it to hidden
			if($('portfolio-window')){
				value.getParent().getParent().addClass('hide');
			}
			value.addClass('hide');
		}
	);
	//on creating values page, drop current class on all
	if($('subnav')){
		var links = $('subnav').getElements('a');
		links.each(
			function(link, i){
				link.removeClass('current');
			}
		);		
	}
	//on portfolio page, drop current class on leftnav items
	if($('portfolio-window')){
		var links = $('leftnav').getElements('a');
		links.each(
			function(link, i){
				link.removeClass('current');
			}
		);		
	}
	//remove the 'hide' class on the selected tab
	if($('process') || $('values')){
		$(selected).removeClass('hide');
	}
	//on portfolio page, loop through each portfolio item and check to see if the passed selection matches it's class. If it does
	//then the class of 'hide' is removed from it as well as the parent <TR>
	if($('portfolio-window')){
		values.each(
			function(value,i){
				if(value.hasClass(selected))
				{
					value.removeClass('hide');
					value.getParent().getParent().removeClass('hide');
				}
			}
		);
		var header = "../images/page-headers/h-"+selected+".gif";
		$('port-header').src = header;
	}
	//when selecting a-z browsing, removes all 'hide' classes to allow full list to appear
	if(selected == "reset"){
		values.each(
			function(value,i){
				value.removeClass('hide');
				value.getParent().getParent().removeClass('hide');
			}
		);
		var header = "../images/page-headers/h-all.gif";
		$('port-header').src = header;
	}
	
};
function overlay(i,lin){
	//get logo graphic
	// if ((document.all) && (navigator.userAgent.indexOf('Opera')== -1)){
	// 		var	logo = i.parentNode.childNodes[0].src;
	// 	}
	// 	else{
	// 		var	logo = i.parentNode.childNodes[1].src;
	// 	}
	var hrefnew = lin;
	logo = i.parentNode.getElements('a')[0];
	//get href
	var href = i.parentNode.getElements('a')[1];
	//get company name
	var name = i.parentNode.getElements('h3');
	//get company address
	var adr = i.parentNode.getElements('span.adr');
	//get date
	var date = i.parentNode.getElements('p.date');
	//get type
	var type = i.parentNode.getElements('p.type');
	//get status
	var status = i.parentNode.getElements('p.status');
	//get description
	var description = i.parentNode.getElements('p.desc');
	
	// the overlay (clickable to close)
 	new Element('div').setProperties({id: 'mb_overlay', style: 'display:none'}).injectInside(document.body);
	var div = $('mb_overlay').setStyles({
			display:'block',
			opacity: 0
		});
	new Fx.Style(div, 'opacity', {duration: 1000} ).start(0,.8);
	// the center element
	this.center = new Element('div').setProperty('id', 'mb_center').injectInside(document.body);
	this.contents = new Element('div').setProperty('id', 'mb_contents').injectInside(center);	
	this.close = new Element('span').setProperty('id', 'close').setHTML('close').injectInside(contents);	
	//filling card with content
	// 
	logoSrc = logo.childNodes[0].src.replace("logos/sm","logos/lg");
	this.lgLogo = new Element('a').setProperty('href',hrefnew).injectInside(contents);
	new Element('img').setProperties({id: 'lg_logo', src: logoSrc, height: '80', width: '180'}).injectInside(lgLogo);
	
	new Element('a').setProperties({href: hrefnew, target: '_blank'}).setHTML('Visit Website').injectInside(contents);
	this.cardcontents = new Element('div').setProperty('id','card-contents').injectInside(contents);
	name.clone().injectInside(cardcontents);
  // new Element('span').setHTML(' - ').injectInside(cardcontents); 
	
	date.clone().appendText(' | ').injectInside($('card-contents')).adopt(type.clone().appendText(' | ').adopt(adr.clone()));
	
	description.clone().injectInside(cardcontents);
	
	status.clone().injectInside(cardcontents);

	this.back = new Element('span').setProperty('id', 'back').setHTML('Back to Portfolio').injectInside($('mb_center'));	

	$('mb_overlay').onclick = function(){
		ditchOverlay();
	}
	close.onclick = function(){
		ditchOverlay();
	}
	back.onclick = function(){
		ditchOverlay();
	}
}
function ditchOverlay(){
	if($('mb_center')){
		$('mb_center').empty();
		$('mb_center').remove();
	}
	if($('mb_overlay')){
		new Fx.Style($('mb_overlay'), 'opacity', {duration: 1000,onComplete: function(){$('mb_overlay').remove();}}).start(.8,0);
	}
}