/* CONSTANTS */
var FLASH_VERSION_SUPPORTED = '9';

/* UTILITY VARIABLES */
var isIE = $.browser.msie;
var isIE6 = isIE && parseInt($.browser.version) === 6;

/*
 * ENABLE JS and FLASH FLAGS
 */
$('html').addClass('js-enabled');
if(typeof(swfobject) !== 'undefined' && swfobject.hasFlashPlayerVersion(FLASH_VERSION_SUPPORTED)) {
	$('html').addClass('flash-enabled');
}

/*
* ONLOAD EVENTS
*/
$(document).ready(function() {
	
	/* highlight date when mouseover release link */
	$('.release a').hover(function() {
		$(this).parents('.release').addClass('hover_')
	},function() {
		$(this).parents('.release').removeClass('hover_')
	});
	/* home page news reel */
	if($('.reel').length) {
		$('#recent-news .reel').jScrollPane({showArrows:true,scrollbarWidth:10,dragMinHeight:3,dragMaxHeight:3});
	}

	/* mod footer links */
	$('#footer .locations a').each(function() {
		if($('#contact-information').length) {
			$(this).click(function() {
				$('#panels-nav a[href='+ this.hash +']').click()
				return false;
			});
		} else {
			$(this).attr('href',$(this).attr('href').replace('#','#/'));
		}
	});
	
	
	$('#apply-now-link').click(function() {
		var $this = $(this);
		if(!$('#close-link').length) {
			$(this.hash).prepend('<a href="#" id="close-link">Close</a>');
			$('#close-link').click(function() {
				$('#apply-now-link').click();
				return false;
			});
		}
		if($this.hasClass('open_')) {
			$(this.hash).fadeOut();
			$(this).removeClass('open_');
			$('body').unbind('click', clickOffClose);	
		} else {
			$(this.hash).fadeIn();
			$(this).addClass('open_')
			$('body').bind('click', clickOffClose);	
		}
		return false;
	});
	
	//implement click on anywhere other than apply overlay to close
	function clickOffClose(event) {
		var $trig = $(event.target || event.srcElement);
		if (!$trig.is('#application-information') && $trig.parents('#application-information').length === 0) {
			$('#apply-now-link').click();
		}
	}
	
	
	
	

//end document.ready
});




/*
* GLOBAL ENHANCEMENTS
*/
$(function() {


	/* open external urls in new window */
	$('a.ext, a.doc').live('click', function() {
		window.open(this.href);
		return false;
	});
 
	/* makes whole block clickable
	 	(note: this will not capture any other events bound to the link) 
	 */
	$('.block-link > *:not(a)').css('cursor','pointer').click(function(e) {
		document.location = $(this).siblings('a').attr('href');
	});


});


/*
* IE FIXES
*/
if(isIE6) {

    /* prevents background-image flicker in IE 6
	(http://support.microsoft.com/?scid=kb;en-us;823727&spid=2073&sid=global) */
	try { document.execCommand("BackgroundImageCache",false,true); } 
	catch(e) { }
    
}

