// VERY IMPORTANT - DO NOT DELETE
// prevents flicker with moving background images for those IE users who have their cache
// settings for those IE users who have their cache settings to 'every visit to the page'
try { document.execCommand("BackgroundImageCache",false,true); } catch(e) {};

// jquery functions
$(document).ready(function(){
	//Replace body class if JavaScript is enabled
	$('body.jsDisabled').removeClass('jsDisabled');
	$('body').addClass('jsEnabled');
	
	//IE6 needs this otherwise space is left - display:none in the stylesheet doesn't work - probably due to inheritance. 
	$('.tabContent .headers').hide();
	
	// button rollover for all browsers   
		$('.button').hover(
		function() {
		    $(this).addClass('hover');
		}, 
		function() {
		    $(this).removeClass('hover');
		});
	
	// sets the initial value for search phrase field, then removes text on focus
		var sDefaultPhrase 				= 'Search';
	  
		$("#frmNewsSearch--sSearchPhrase").val(sDefaultPhrase).focus(function () {
		 if (this.value === sDefaultPhrase) {
		  this.value    = '';
		 }
		});
		
	// Set max width on images for blogs landing page (needed by IE6/IE8)
		var maxWidth = 370;
		$("#blogsRSS .rss img").each(function() {
				if ($(this).width() > maxWidth) {
					var h = Math.ceil($(this).height() / $(this).width() * maxWidth);
					$(this).css({ height: h, width: maxWidth });
				}
			}
		)
		
	// Title, Text & Image promo in the xcol, rollover effect
		
		// sets the element that is the hover trigger
		var sPromoItem					= '#xcol .promoImageTitleText, #relatedColumn .articlePromoImageTitleText';
		
		// 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':'15px','left':'0','opacity':'0.8'});
		
		$(sPromoItem).hover(
		function() {
			// on mouseover
			if (!bHover) {
				$(sPopupElement, this).slideToggle("slow");
				bHover = true;
			}
		}, 
		function() {
			// on mouseout
			$(sPopupElement, this).slideToggle("slow");
			bHover = false;
		});			
	
	$('#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/
	*
	*/
	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');
	        }
	      } else {
	        if(jQuery(element).attr('href') == $.cookie(tabs_div)) {
	          link.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(link.addClass('selected').attr('href')).show();
			jQuery(this).blur();
	        return false;
	      });
	    });
	  });
	};
	
	$('.tabContainer ul.tabs').tabbify();
	
});


