$(document).ready(function(){
	
		// sets the initial value for search phrase field, then removes text on focus
		var sDefaultPhrase = 'Search';
		var sDefaultClass = 'searchDefault';
		
		//Add a class to style default state
		$("#sSearchPhrase").addClass(sDefaultClass);
	  
		$("#sSearchPhrase").val(sDefaultPhrase).focus(function () {
			if ($(this).val() == sDefaultPhrase) {
				$(this).val('');
				$(this).removeClass(sDefaultClass);
			};
		}).blur(function(){
			if ($(this).val() == '') {
				$(this).val(sDefaultPhrase);
				$(this).addClass(sDefaultClass);
			};
		});
		
		$('#emailThis').hide();
		
		jQuery.fn.fadeToggle = function(speed, easing, callback) {
			return this.animate({opacity: 'toggle'}, speed, easing, callback);
		}; 
			
		$('.emailArticle a').click(function(){
			$('#emailThis').fadeToggle();
			return false;
		})
		/**************************************************************************/
		/***							TABS									***/
		/**************************************************************************/

	
		/* Copyright (c) 2009 Mark Gandolfo http://www.markgandolfo.com.au
		* Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
		* Copyright notice and license must remain intact for legal use
		* tabbify
		* Requires: jQuery 1.2.6+
		*           jCookie
		*
		* Original Code Copyright (c) 2009 ANDREAS LAGERKVIST
		* Website: http://andreaslagerkvist.com/jquery/super-simple-tabs/
		*
		*/
		
		// Modified to set selected class on the LI too
		
			jQuery.fn.tabbify = function (options) {
		  return this.each(function () {
		    var ul = jQuery(this);
		    var tabs_div = $(this).parent().attr('id');
		  
		    ul.find('a[href^=#]').each(function (i, element) {
		      var link = jQuery(this);
		 
		      if(!jQuery.cookie(tabs_div)) {
		        if(i) {
		          jQuery(link.attr('href')).hide();
		        } else {
		          link.addClass('selected').parent().addClass('selected');
		        }
		      } else {
		        if(jQuery(element).attr('href') == $.cookie(tabs_div)) {
		          link.addClass('selected').parent().addClass('selected');
		        }  else {
		          jQuery(link.attr('href')).hide();
		        }
		      }
		      
		      link.click(function () {
		        id = jQuery(this).attr('href');
		        if (tabs_div) $.cookie(tabs_div, id, { path: '/' });
		  
		        jQuery(ul.find('a.selected').removeClass('selected').attr('href')).hide();
				jQuery(ul.find('li.selected')).removeClass('selected');
		        jQuery(link.addClass('selected').attr('href')).show();
		        jQuery(link).parent().addClass('selected')			
		        return false;
		      });
		    });
		  });
		};
	
	$('.tabContainer ul.tabs').tabbify();

		// Title, Text & Image promo in the xcol, rollover effect
		
		// sets the element that is the hover trigger
		var sPromoItem					= '.xcolPromoImageTitleText';
		
		// sets the child element of sPromoItem that is the popup
		var sPopupElement				= 'p'
		
		var sPopup						= $(sPromoItem).find(sPopupElement);
		var bHover						= false;
		
		// hides the popup on page load and sets styling
		$(sPopup).hide().css({'position':'absolute','bottom':'0px','left':'0','opacity':'0.9'});
		
		$(sPromoItem).hover(
		function() {
			// on mouseover
			if (!bHover) {
				$(sPopupElement, this).slideToggle("slow");
				bHover = true;
			}
		}, 
		function() {
			// on mouseout
			$(sPopupElement, this).slideToggle("slow");
			bHover = false;
		});		
		
		
	// hide all captions
	$('#featureCaptions p').hide();
	
	// show first caption as default
	$('#featureCaptions p:first').addClass('active');
	
	//show the first image and caption as default
	//$('#featureImage6').addClass('selectedImage');
	
	$("#features .feature").hover(function() {
		
		//resets classes once you have hovered and function has been triggered
		$('#featureImage1').removeClass('selectedImage');
		$('#featureCaptions').find('p.active').removeClass('active');
		$('.features').find('img.selected').removeClass("selected");
		$('.features').find('.shadow').removeClass("shadowbg");
		
		
		$(this).css({'z-index' : '10'});
		$(this).find('img').addClass("hover").stop().animate(200);
			$(this).find('img').addClass("selected");
			$(this).find('.shadow').addClass('shadowbg');
			
			//finds the index number of the element
			var openIndex=this.id.substring(12);
			$('#featureCaptions').find('#featureText'+openIndex).addClass('active');
			$('#featureCaptions').find('#featureText'+openIndex).fadeIn('fast');
						
	} , function() {
		$(this).css({'z-index' : '0'});
		$(this).find('img').removeClass("hover").stop().animate(300);
			
			//finds the index number of the element
			var openIndex=this.id.substring(12);
			$('#featureCaptions').find('#featureText'+openIndex).hide();
	});
	
		
});


