$(document).ready(
	function(){

	$('div.expandable').expander();

	// Rotating Headlines Control
		$('#rotatingHeadlines').innerfade({
			animationtype: 'fade',
			speed: 1000,
			timeout: 6500,
			type: 'sequence',
			containerheight: '1em'
		});

	// Accordion Menu Control
		$('.subMenu ul').hide();
		$('.subMenu li a').click(
				function() {
			  		var checkElement = $(this).next();
			  		if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
			  		return false;
					}
				if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
					$('.subMenu ul:visible').slideUp('normal');
					checkElement.slideDown('normal');
				return false;
				}
			}
		);

		$("a[rel^='prettyPhoto']").prettyPhoto();

	// Tool-tip pop-up
		$('.bubbleInfo').each(function () {
		// options
		var distance = 10;
		var time = 250;
		var hideDelay = 500;

		var hideDelayTimer = null;

		// tracker
		var beingShown = false;
		var shown = false;

		var trigger = $('.trigger', this);
		var popup = $('.popup', this).css('opacity', 0);

		// set the mouseover and mouseout on both element
		$([trigger.get(0), popup.get(0)]).mouseover(function () {
		  // stops the hide event if we move from the trigger to the popup element
		  if (hideDelayTimer) clearTimeout(hideDelayTimer);

		  // don't trigger the animation again if we're being shown, or already visible
		  if (beingShown || shown) {
			return;
		  } else {
			beingShown = true;

			// reset position of popup box
			popup.css({
			  top: -50,
			  left: -150,
			  display: 'block' // brings the popup back in to view
			})

			// (we're using chaining on the popup) now animate it's opacity and position
			.animate({
			  top: '-=' + distance + 'px',
			  opacity: 1
			}, time, 'swing', function() {
			  // once the animation is complete, set the tracker variables
			  beingShown = false;
			  shown = true;
			});
		  }
		}).mouseout(function () {
		  // reset the timer if we get fired again - avoids double animations
		  if (hideDelayTimer) clearTimeout(hideDelayTimer);

		  // store the timer so that it can be cleared in the mouseover if required
		  hideDelayTimer = setTimeout(function () {
			hideDelayTimer = null;
			popup.animate({
			  top: '-=' + distance + 'px',
			  opacity: 0
			}, time, 'swing', function () {
			  // once the animate is complete, set the tracker variables
			  shown = false;
			  // hide the popup entirely after the effect (opacity alone doesn't do the job)
			  popup.css('display', 'none');
			});
		  }, hideDelay);
		});
	  });

	// External Links
		$('a[rel=external]').click(function(){
		this.target = "_blank";
		});

	// Zebra Stripes
		$('.zebraTable tr:odd').addClass('odd');
		$('#searchResults .articleList li:odd').addClass('stripe');
		$('.relatedInfoList li:odd').addClass('odd');
		$('.latestTopThreeList li:even').addClass('even');
		$('.calendar tr:odd').addClass('odd');
	}
);


	jQuery.fn.highlight = function(selector, className, eventStart, eventEnd){

		// variables
			var className		= className || 'highlight';
			if(eventStart == undefined && eventEnd == undefined){
				var eventStart = 'mouseover';
				var eventEnd = 'mouseout';
				}
			else if(eventStart == eventEnd || eventStart != undefined && eventEnd == undefined){
				var toggle = true;
				}

		// code
			this.each
				(
				function(){

					var tagName	= this.tagName.toLowerCase();

					if(tagName == 'form'){

						selector		= selector || 'li';
						var elements 	= jQuery("textarea, select, multi-select, :text, :image, :password, :radio, :checkbox, :file", this);

						elements.bind
							(
							'focus',
							function(){
								var parents	= jQuery(this).parents(selector)
								var parent	= jQuery(parents.get(0))
								parent.addClass(className);
								}
							);

						elements.bind
							(
							'blur',
							function(){
								var parents	= jQuery(this).parents(selector)
								var parent	= jQuery(parents.get(0))
								parent.removeClass(className);
								}
							);

						}

					else{


						if(tagName.match(/^(table|tbody)$/) != null){
							selector = selector || 'tr';
							}
						else if(tagName.match(/^(ul|ol)$/) != null){
							selector = selector || 'li';
							}
						else{
							selector = '*';
							}

						var elements	= jQuery(selector, this);

						if(toggle){
							elements.bind
								(
								eventStart,
								function(){
									if($(this).hasClass(className)){
										$(this).removeClass(className);
										}
									else{
										$(this).addClass(className);
										}
									}
								);

							}

						else{
							elements.bind
								(
								eventStart,
								function(){
									$(this).addClass(className);
									}
								);

							elements.bind
								(
								eventEnd,
								function(){
									$(this).removeClass(className);
									}
								);
							}

						}
					}
				);

		}

	function cover_swap(element_id,img){
		element = $(element_id);
		element.attr("src",img);
	}
