$.noConflict();
jQuery(document).ready(function($) {
	
	// open links externally
	$("a[rel='external']").attr({'target': '_blank'});
	
	// homepage scripts
	if ( $('body').hasClass('home') ) {
	
	//overlay
	//$('body').prepend('<div id="focus">&nbsp;</div>');
	var Overlay = {
		isOpen: false,
		show: function($this, overlayElement) {
			$overlay = $(overlayElement);
			
			var overlayid = $this.attr('href');
			var $iframe = $(overlayElement + ' iframe');
			
			$iframe.attr('src',overlayid);
			
			$iframe.load(function () { 
	
				$iframe.contents().find('#close').click(function() {
						Overlay.close($overlay,$iframe);
				});
				
				$iframe.attr('tabIndex',0);
				$overlay.attr('tabIndex',0);
				$("#focusid").attr('tabIndex',0);
				$("#callout").attr('tabIndex',0);
				
				$iframe.trigger('focus');
				
				$overlay.focus( function() { 
					 $iframe.contents().find('#close').trigger('focus');
				});
				
				$("#focusid").focus( function() {
						if ( Overlay.isOpen ) {
							$iframe.trigger('focus');
						} else {  $('#callout').trigger('focus'); }
				});
				
			});
			
			$overlay.fadeIn(300);
			Overlay.isOpen = true;
			

			$overlay.find("#overlay_bg").click(function(){
					Overlay.close($overlay,$iframe);
			});
			
			$(window).keyup(function (event) {
				if (event.keyCode == 27) { // keyboard escape
					Overlay.close($overlay,$iframe);
				}
			});
		
			return false;
		},
		close: function($overlay,$iframe) {
				$overlay.hide();
				Overlay.isOpen = false;
				$iframe.attr('src','');
				$("#focusid").trigger('focus');
		}
	}
		
	 $('.overlaytrigger',('#content')).click( function(e) { 
	 
	 		Overlay.show($(this), '#overlay');
			
			// if IE6
			if ($.browser.msie && $.browser.version.substr(0,1)<7) {
				var relativeY = (e.pageY - this.offsetTop) - 300;
				$('#overlay_bg').css('height',document.body.offsetHeight);
				$('#overlay #overlaycontent').css('top',relativeY);
			}
			
			return false;
		});
	}
	
});
