/*
 * @developer Bitface
 * @date 2009
 * www.pls.com Javascript functionality
 *
 */ 



/*
 * UI manager
 *
 */

var UIManager = {
  Common: {
  
    init: function(e) {
      $('body').removeClass('nojs').addClass('js');
    }
	
  }
};


$(document).ready(function() {
// init the UI
UIManager.Common.init();

// init the thought bubble
$('#button-bar').thoughtBubbleControl({}); 

// course listing popups
$('.course_flyout p:empty').remove(); // some have empty p tags
$('.pop-trigger').hover(function(e){
	e.preventDefault();
	$(e.target).parent().css('z-index', 3000).find('div.course_flyout').show();
}, function(e){
	e.preventDefault();
	$(e.target).parent().css('z-index', 1).find('div.course_flyout').hide();
}); 

 // main nav tabs
$(".main-nav-links a").hover(function(event){
	$(event.target).closest("li").addClass('hover');
}, function(event){
	$(event.target).closest("li").removeClass('hover');
}); 
// search form reset
$('#zip_code').searchhelper({});

});






/**
 * Homepage Thought Bubble
 * Shows and hides the thought bubbles on the homepage.
 * @version 1.0
 */
(function($){
  var settings;

  $.fn.thoughtBubbleControl = function(callerSettings) {
    settings = $.extend({
	  openId: null,
	  flyout: '.homepage-flyout'
    },callerSettings||{});
	// set up
	$(this, 'a').click(showBubble);
	$(settings.flyout+' a.close').click(hideBubble);
	$(settings.flyout).hide();
	return this;
  };
// show a bubble
  var showBubble = function(e) {
	e.preventDefault();
	if (settings.openId != null && $(e.target).attr('rel') == settings.openId) {
		// already open, toggle close
		hideBubble();
	} else {
		hideBubble();
		settings.openId = $(e.target).attr('rel');
		$('#'+settings.openId).show();
	}
  };
// hide a Bubbles
  var hideBubble = function(e) {
	  if (e) {e.preventDefault();}
	// close the openId
	if (settings.openId != null) {
		$('#'+settings.openId).hide();
		settings.openId = null;
	}
  }

})(jQuery);

/**
 * Zipcode search helper
 * Adds a default radius or resets the zip code.
 * @version 1.0
 */
(function($){
  var settings;

  $.fn.searchhelper = function(callerSettings) {
    settings = $.extend({
	  pulldown: '#radius',
	  zipbox: '#zip_code'
    },callerSettings||{});
	// add events
	$(settings.zipbox).focus(setDefaultRadius);
	$(settings.pulldown).change(clearZipValue);
	return this;
  };
  var setDefaultRadius = function(e) {
	if (e) {e.preventDefault();}
	var elm = $(settings.pulldown);
	if (elm.val() == 0) {
		elm[0].selectedIndex = 3;
	}
  };
  var clearZipValue = function(e) {
	if (e) {e.preventDefault();}
	if ($(settings.pulldown).val() == 0) {
		$(settings.zipbox).val('');
	}
  }

})(jQuery);


