jQuery(function(){

	// pop-ups
	// we can replace this functionality with a lightbox clone if we want to
	jQuery('a.IsPopUp').click(function(){
		PopUp({
			href: jQuery(this).attr('href'),
			name: '_new',
			location: false,
			menubar: false,
			toolbar: false,
			status: false
		});
		return false;
	});
	
	// print links
	jQuery('a.IsPrint').click(function(){
		window.print();
		return false;
	});
	
	// hack for select boxes
	jQuery('select').focus(function(){
		jQuery(this).addClass('focused');
	}).blur(function(){
		jQuery(this).removeClass('focused');
	});
});

// controls the search form
var Search = {
	label: null,
	keyword: null,
	onClick: function () {
		// Search.label.hide();
		Search.keyword.focus();
	},
	onFocus: function () {
		Search.label.hide();
	},
	onBlur: function () {
		if (Search.keyword.val() == '') {
			Search.label.show();
		}
	},
	init: function () {
		Search.label = jQuery('#SearchLabel');
		Search.keyword = jQuery('#SearchKeyword');
		Search.label.click(Search.onClick);
		Search.keyword.focus(Search.onFocus);
		Search.keyword.blur(Search.onBlur);
	}
};
jQuery(Search.init);

// controls the menu  
jQuery(function(){
	// we need the immediate descendant selector here
	// this will have to be changed if/when we implement submenus
	var MenuLIs = jQuery('#nav > ul > li');
	MenuLIs.bind('mouseenter', function(){
		var realTarget = jQuery(this);
		
		// fade in the child of the target
		realTarget.children('ul').bgiframe().fadeIn('fast');
		return false;
	})
	.bind('mouseleave', function(){
		var realTarget = jQuery(this);
		realTarget.children('ul').fadeOut('slow');
		return false;
	});
});