function closePopup(whatDiv) {
	if(document.getElementById(whatDiv)) {
		var popups = document.getElementById(whatDiv);
		$("#"+whatDiv).slideUp("fast");
//		popups.style.display = "none";
	}
}

function initNav() {
	if(!document.getElementById('nav')) return false;
	var navHolder = document.getElementById('nav');
	var lis = navHolder.getElementsByTagName('li');
	for(i=0; i<lis.length; i++) {
		lis[i].onmouseover = function() {
			if(undefined!==window.closeTheThing) {
				clearTimeout(closeTheThing);
			}
			var liPartialName = this.id.substring(3, this.id.length);
			var popupName = "s"+liPartialName;
			if((document.getElementById(popupName))) {
				var popups = document.getElementById(popupName);
//				alert(popupName);
				$("#"+popupName).show(150);
//				popups.style.display = "block";
			}
			for(j=0; j<lis.length; j++) {
				var liPName = lis[j].id.substring(3, lis[j].id.length);
				var pName = "s"+liPName;
				if(document.getElementById(pName)) {
					var ps = document.getElementById(pName);
					if(ps!=popups) {
						$("#"+pName).slideUp("fast");
//						ps.style.display = "none";
					}
				}
			}
		}		
		lis[i].onmouseout = function() {
			var liPartialName = this.id.substring(3, this.id.length);
			var popupName = "s"+liPartialName;
			var closeIt = "closePopup('"+popupName+"')";
			closeTheThing = setTimeout(closeIt, 50)  
		}
	}
	
	// to keep boxes open //
	var navPop = document.getElementsByTagName('div');
	for(i=0; i<navPop.length; i++) {
		var navClass = navPop[i].className.substring(0, 6);
		if(navClass=="navpop") {
			navPop[i].onmouseover = function() {
				if(undefined!==window.closeTheThing) {
					clearTimeout(closeTheThing);
				}
				this.style.display = "block";
				thisID = this.id;
				linkID = "np-"+thisID.substring(1, thisID.length);
				
				if(document.getElementById(linkID)) {
					linkClass = document.getElementById(linkID);
					linkClass.className = "hovered";
				}
			}
			navPop[i].onmouseout = function() {
				thisID = this.id;
				linkID = "np-"+thisID.substring(1, thisID.length);
				if(document.getElementById(linkID)) {
					linkClass = document.getElementById(linkID);
					linkClass.className = "";
				}
				var closeIt = "closePopup('"+thisID+"')";
				closeTheThing = setTimeout(closeIt, 60) 
			}
		}
	}
}


function makeLinksWork() {
	// LINK ACTIONS

	$('a[rel="external"]').click(function(){
		window.open(this.href); return false;
	});
}


$(document).ready(function() {
	initNav();
	makeLinksWork();
});




// sIFR

var myriad = { src: '/f/fontin.swf' };
var myriad2 = { src: '/f/fontin.swf' };

sIFR.useStyleCheck = true;
sIFR.activate(myriad, myriad2);

sIFR.replace(myriad, {
  selector: 'h2',
  css: [ 
		'.sIFR-root { letter-spacing: -1.2}'
		,'a { text-decoration: none; }'
		,'a:link { color: #000000; }'
		,'a:hover { color: #772224; }'
	],
  wmode: "Transparent"
});

sIFR.replace(myriad2, {
  selector: '#cLinks h3',
  css: [ 
		'.sIFR-root { letter-spacing: -0.8;}'
		,'a { text-decoration: none; }'
		,'a:link { color: #000000; }'
		,'a:hover { color: #772224; }'
	],
  wmode: "Transparent"
});

