/* -- -- -- -- -- -- --
 * cfge.js
 * -- -- -- -- -- -- --
 */

$(document).ready(function(){

	//open all external sites in new window
	$('a[href^="http"]').each(function(){
		// make the title spiffy
		if( ! /popup/i.test($(this).attr('class')) ) {
			var currentTitle = $(this).attr('title');
			if( currentTitle.length > 0 ) {
				$(this).attr('title',currentTitle + '. This link opens in a new window');
			} else {
				$(this).attr('title','This link opens in a new window');
			}

			$(this).click(function(e){
				e.preventDefault();
				window.open ($(this).attr('href'), "","status=1,toolbar=1,location=1,menubar=1,directories=1,resizable=1,scrollbars=1,width=800,height=600");
			});
		}
	});

	// append (PDF) to pdf links
	$('#page-contents-left a[href$=".pdf"]').each(function(){
		 //only add the PDF link if the link does not contain an image
		 $(this).filter(function(index){
				return $("img", this).length == 0;
		 }).append(" (PDF)");

	}); // end: .pdf-each

	// pdfs open in a new window.
	$('a[href$=".pdf"]').each(function(){
		var currentTitle = $(this).attr('title');
		if( currentTitle.length > 0 ) {
			$(this).attr('title',currentTitle + '. This link opens in a new window');
		} else {
			$(this).attr('title','This link opens in a new window');
		}

		if( !(/^http/.test($(this).attr('href'))) ) {
			$(this).click(function(e){
				e.preventDefault();
				window.open ($(this).attr('href'), "etsOpenWindow","status=1,toolbar=1,location=1,menubar=1,directories=1,resizable=1,scrollbars=1,width=800,height=600");
			});
		}

	}); // end: .pdf-each

	//add left border to first nav item
	$('#site-navigation ul li:first a').css('border-left', '1px solid black');

	// tweak the height of the page so that the footer is always flush with
	// the bottom of the canvas
	var window_height = parseInt($(window).height());
	var footer_offset  = parseInt($('#footer').offset().top);
	var footer_height  = parseInt($('#footer').height());
	diff = window_height - footer_offset - footer_height;
	if( diff > 1 ) { $('#page-contents').css('padding-bottom', 62 + Math.abs(diff)); }

}); // end: document.ready

// popup code for video
function popUp( strURL, strType, strHeight, strWidth ) {
   var strOptions = "";
   if( strType == "console" ) { strOptions = "resizable,scrollbars=1,height="+strHeight+",width="+strWidth; }
   if( strType == "fixed" ) {   strOptions = "status,height="+strHeight+",width="+strWidth; }
   if( strType == "elastic" ) { strOptions = "toolbar,menubar,scrollbars,resizable,location,height="+strHeight+",width="+strWidth; }
   window.open( strURL, 'newWin', strOptions );
}

