$(function(){ //start jquery
	/*safari css hack to move the line up*/
	if ($.browser.safari) {
		$("#explore-opps-line").css("margin-top","-25px");
	 }
	
	/*
		Look for all links that are pdfs. open them in a new window.
	*/
	$("a[href$='.pdf']").attr("target","_blank");
	$("a[href$='.pdf']:not([class*='no-icon'])").addClass("link-pdf");
	
	/*look for anchor links; reset title if clicked*/
	myTitle=document.title;
	$("*").click(function(){
		document.title = myTitle;
	});

	/*
		Show-expand elements based on the click on a neighbor.
	*/
	//set background on the show link, and hide the text with javascript, this makes the page usable without javascript
	$(".show-link a").css({background: "url(i/arrow-plus.gif) 0px 4px no-repeat", padding: "0 10px 0 18px", float: "left", display: "block", overflow: "hidden", width: "auto"});
	
	$(".show-link").css("overflow","hidden")
	$(".show-text").css("display","none");

	$(".show-text").children(":first-child").before("<span id='print-expand' class='float-left'><a id='print-text' class='print-anchor' href='#print'>PRINT</a><a href='#print' id='print-icon' class='print print-anchor'><span>print</span></a></span>");
	$(".show-text").children(":first-child").before("<a href='#close-expand' class='close-expand'>CLOSE <span class='close-x'>X</span></a>");	
	if(($.browser.msie) && ($.browser.version.indexOf("6") == 0)){
		$(".show-link").click(function(){ 
			//add a class click to the element that already has the class .show-link. this will temp. overwrite out faq-off code.
			$(this).toggleClass("expand-on");
			
			//find the next element (.show-text) 
			//set the top margin of the first child to 0, so there is no jumping. 
			//and turn it on/off based on current state.
			$(this).next().children("p").css("margin-top","0");
			$(this).next().children("h3").css("margin-top","0");		
			$(this).next().toggleClass("show");
			//cancel the click
			return false;
		});//close .show-link click event
		
		$(".close-expand").click(function(){
			$(this).parent().prev().toggleClass("expand-on");
			$(this).parent().toggleClass("show")
			return false;
		});
	}else{
		$(".show-link").click(function(){ 
			whatIsTracked = hideExpandTracking($(this))
			pageTracker._trackPageview(whatIsTracked)
			//alert(whatIsTracked);
			//add a class click to the element that already has the class .show-link. this will temp. overwrite out faq-off code.
    	
			$(this).toggleClass("expand-on");
			
			//find the next element (.show-text) 
			//set the top margin of the first child to 0, so there is no jumping. 
			//and turn it on/off based on current state.
			$(this).next().children("p").css("margin-top","0");
			$(this).next().children("h3").css("margin-top","0");		
			$(this).next().slideToggle("normal");
			//cancel the click
			return false;
		});//close .show-link click event
		
		$(".close-expand").click(function(){
			whatIsTracked = hideExpandTracking($(this).parent().prev())
			pageTracker._trackPageview(whatIsTracked)
			//alert(whatIsTracked);
			$(this).parent().prev().toggleClass("expand-on");
			$(this).parent().slideToggle("normal");
			return false;
		});
	}
	/*
		creates a popup window with the content that is contained above the print header
	*/
	$(".print-anchor").click(function(){
		whatWasPrinted = printTracking($(this))
		pageTracker._trackPageview(whatWasPrinted)
		var setting="toolbar=yes,location=no,directories=yes,menubar=yes,scrollbars=yes,width=650, height=600, left=100, top=25"; 
  		var content_value = $(this).parent().parent().html(); 
		var header = $(this).parent().parent().prev(".show-link").text();
    	var docprint=window.open("","",setting); 
   			docprint.document.open(); 
   			docprint.document.write('<html><head><title>Bryan Feller</title>');
   			docprint.document.write('<link rel="stylesheet" type="text/css" media="all" href="css/print-section.css" />');
   			docprint.document.write('</head><body onLoad="self.print()">');          
			docprint.document.write('<h1>'+header+'</h1>');
   			docprint.document.write(content_value);          
   			docprint.document.write('</body></html>'); 
   			docprint.document.close(); 
   		docprint.focus(); 
		return false;
	});


	/*
	adds and removes print hover effect
	*/
	$(".print").hover(
	    function () {
			$(this).addClass("print-hover");
	    }, 
	    function () {
			$(this).removeClass("print-hover")
	    }
	);
		
	/* 
	print button prompt
	*/		
	$("#top-print-expand a").click(function(){
		window.print();
	});

	$("#hw-print a").click(function(){
		window.print();
	});

	
	/*
	open charts in popups; close button closes said popup
	*/
	$("a").click(function(){
		//find if link is height weight or paychart. can add more.
		var myUrl = $(this).attr("href");
		if((myUrl.indexOf("/pay-chart") == 0)){
			myPopup = window.open(myUrl, "", 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,width=1380,height=600,resizable=1')
			myPopup.focus();
			return false;
		}
	});
	
	$("p.close a").click(function(){
		window.close();
	});
	
	$("a").click(function(){
		hrefString = $(this).attr("href");
		if (hrefString.indexOf("http://") == 0){
			pageTracker._trackPageview('/outgoing/'+hrefString)
		}else if(hrefString.indexOf("mailto://") == 0){
			pageTracker._trackPageview('/mailto/'+hrefString)
		}
	});
	
	$(".hide-show-container h2:first-child").addClass("first-show-link");

	/* Only needed for globe and swil */
	if(($("body").attr("id") == "swil") || ($("body").attr("id") == "globe")){
  		doBkgrndResize();
  		$(window).resize(function(){
    		doBkgrndResize();
  		});	
	}

});//close jquery




function pop(url, windowName, width, height) {
	if(!window.open(url,'','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,width='+width+',height='+height+',resizable=1')){
		alert("This site requires pop-up windows to display some content. Please disable pop-up blockers to view this content.")
	}

}
function popBasic(url) {
	window.open(url,'','');
	return false;
}

function echoZuluLink(){
  window.location = "/echo-zulu/";
	return false;
}

function nascarPopup(){
  pop("/interactive/nascar/", "nascar", "1024", "576");
  window.location = "/games-and-extras/";
	return false;
}

function hideExpandTracking(which){
	whatWasClicked = which.text()
	if(which.hasClass("expand-on")){
		isExpanded = "dhtml_closed/";
	}else{
		isExpanded = "dhtml_open/";
	}
	theUrl = window.location.href
	re = new RegExp("^.*//[^/]+/(.*)/.*")
	regExUrl = re.exec(theUrl);
	regExUrl = regExUrl[1]+"/"
	return isExpanded+regExUrl+whatWasClicked;
	
}
function printTracking(which) {
	theUrl = window.location.href
	re = new RegExp("^.*//[^/]+/(.*)/.*")
	regExUrl = re.exec(theUrl);
	regExUrl = regExUrl[1]+"/"
	sectionTitle = which.parent().parent().prev(".show-link").text()
	if(sectionTitle){
		printWhat = "print-section/";
	}else{
		printWhat = "print-page/"
	}
	return printWhat+regExUrl+which.parent().parent().prev(".show-link").text();	
}

//Used on globe and swil
function doBkgrndResize() {
  myHeight = getBrowserHeight();
  if (myHeight < 800) {
    myHeight = 800;
  }
  $("#bkgrnd").css( "height", myHeight+"px");
}

function getBrowserHeight() {
	var h = 0;
	//IE
	if(!window.innerHeight) {
		//strict mode
		if(!(document.documentElement.clientHeight == 0)) {
			h = document.documentElement.clientHeight;
		}
		//quirks mode
		else {
			h = document.body.clientHeight;
		}
	}
	//w3c
	else {
		h = window.innerHeight;
	} 
	return h;
}


function echoZuluPopup(){
  window.location = "/echo-zulu/";
}
function moneyForSchoolPopup(){
  window.location = "/opportunities/enlisted/education/";
}
function switchingSeatsPopup(){
  window.location = "/interactive/racing";
}


function afacademyPopup(){
  window.open("http://www.academyadmissions.com/","_blank");
}
function afrotcPopup(){
  window.open("http://www.afrotc.com/","_blank");
}


