$(document).ready(function(){

var noIcon = $("#main .no-icon"),
	pdfs = $("#main a[href$=.pdf]").not(noIcon),
	docs = $("#main a[href$=.doc], #main a[href$=.docx]").not(noIcon),
	xls = $("#main a[href$=.xls], #main a[href$=.xlsx]").not(noIcon),
	links = $("#main a[href^=http]").not(noIcon),
	mail = $("#main a[href^=mailto:]").not(noIcon),
	flash = $("#main a[href$=.swf], #main a[href$=.flv], a.file-type-flash").not(noIcon);

// Exit link marking
	links.not("#main [href*=.nasadvantage.com]", pdfs, docs, xls, flash).addClass("external").attr({target: "_blank"}).append("&nbsp;<img src='/assets/images/ext.gif' alt='' title='This link takes you to an external website.' width='10' height='9'>");
	
// PDF link marking
	pdfs.addClass("file").attr({title: "This link opens a PDF document."}).attr({target: "_blank"}).append("&nbsp;<img src='/assets/images/pdf.gif' alt='' width='22' height='8'>");

// DOC link marking
	docs.addClass("file").attr({title: "This link opens a Word document."}).append("&nbsp;<img src='/assets/images/doc.gif' alt='' width='23' height='8'>");

// XLS link marking
	xls.addClass("file").attr({title: "This link opens an Excel document."}).append("&nbsp;<img src='/assets/images/xls.gif' alt='' width='22' height='8'>");

// Mailto: link marking
	mail.addClass("mail").append("&nbsp;<img src='/assets/images/mail.gif' alt='' width='12' height='8'>");

// Flash link marking
	flash.addClass("flash").attr({title: "This link opens a Flash file."}).append("&nbsp;<img src='/assets/images/flash.gif' alt='' width='27' height='8'>");

// Current page marking in sub-navigation
	currentPage = window.location.href.split("/").slice(-1);
	$("#sidebar ul a[href=" + currentPage + "]").addClass("current");

// Table striping
	$("#content tbody tr:even").addClass("even");
	$("#content tbody tr").hover(function(){
		$(this).addClass("active")
	  }, function() {
		$(this).removeClass("active")
	});
		
// Attach launchWin function to appropriate links
//  link must have attributes of class = "popup" and
//  data-popup = "windowName,width,height" (no spaces)
	$("#content").delegate("a.popup", "click", function(e){
		e.preventDefault() // stop link from being normally followed
		$this = $(this);
//		console.log($this.attr("class").split(" "));
		data = $this.attr("data-popup");
		data = data.split(",");

		winUrl = $this.attr("href");
		winName = data[0];
		winWidth = data[1];
		winHeight = data[2];

		launchWin(winUrl, winName, winWidth, winHeight);
	});
	
});



function launchWin(winUrl, winName, w, h)
{
	var winW = (screen.width-w)/2;
	var winH = (screen.height-h)/2;
	settings='height='+h+',width='+w+',top='+winH+',left='+winW+',scrollbars=no,toolbar=no,location=no,status=no,menubar=no,resizable=no,dependent=no';
	newWindow = window.open (winUrl, winName, settings);
	if (window.focus) {newWindow.focus()}
}
