/* Menu Rollover Code */
$.fn.rolloverMenu = function(){
	return this.each(function(){
		var active = $('LI.active', this);
		active.addClass('over');
		$('LI', this).hover(
			function(){
				active.removeClass('over');
				$(this).addClass('over');
			},
			function(){
				$(this).removeClass('over');
				active.addClass('over');
			}
		);
	});
};

$(function(){
	
	$('#nav, #jumpnav').rolloverMenu();
	
});

$(function(){
	$('A, AREA').filter(function(){
		var href = $(this).attr('href');
		return !this.target && ((href.indexOf(window.location.hostname) == -1 && href.match(/^https?/i)) || href.match(/\.pdf$/i));
	}).attr('target', '_blank');
});

/**
 * Hookup YouTube videos to fancybox popup
 */
$(function(){
	$('BODY').append('<div style="display:none" id="video"></div>').append('<a href="#video" id="videoLink" />');
	$('a[href*="youtube.com/"]').click(function(evt) {
		var matches = $(this).attr('href').match(/v=([^&]+)/);
		if (matches) {
			var id = matches[1];
			$('#videoLink').css({position:'absolute', top:evt.pageY, left:evt.pageX}).fancybox({
					callbackOnShow:function(){
						$('#fancy_content').html('<object width="480" height="397"><param name="movie" value="http://www.youtube-nocookie.com/v/'+id+'&hl=en&fs=1&rel=0&autoplay=1&ap=%2526fmt%3D18"></param><param name="allowFullScreen" value="true"><param name="bgcolor" value="#000000"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube-nocookie.com/v/'+id+'&hl=en&fs=1&rel=0&autoplay=1&ap=%2526fmt%3D18" type="application/x-shockwave-flash" allowscriptaccess="always" bgcolor="#000000" allowfullscreen="true" width="480" height="397"></embed></object>');
					},
					callbackBeforeClose:function() {
						$('#fancy_content').empty();
					},
					zoomSpeedIn:400,
					zoomSpeedOut:400,
					frameWidth:480,
					frameHeight:397,
					overlayShow: true,
					overlayColor: '#000',
					overlayOpacity: 0.8,
					hideOnContentClick:false
				}).trigger('click');
			return false;
		}
	});
});