$(document).ready(function(){
	
		// sets the initial value for search phrase field, then removes text on focus
		var sDefaultPhrase = 'Search';
	  
		$("#sSearchPhrase").val(sDefaultPhrase).focus(function () {
			if ($(this).val() == sDefaultPhrase) {
				$(this).val('');
			};
		}).blur(function(){
			if ($(this).val() == '') {
				$(this).val(sDefaultPhrase);
			};
		});
		
		$('#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;
		});		
		
		
(function($){
	var settings;
	$.fn.alternator = function(callerSettings) {
		settings = $.extend({
		partTabID: "mostCommented",
		partControlID: "MCcontrol",
		previousCtrl: "MCprevious",
		nextCtrl: "MCnext",
		tabClass: "visible"
	},callerSettings||{});
	

$('.tabContent').each(function(){
		
		var tabsNo = $(this).find("ul li.number").length;
		
		var elmCounter = 1;
		var tabs=new Array();
		var controls=new Array();
		
		
		for(i=1;i<=tabsNo;i++){
			tabs.push(settings.partTabID+i);
			controls.push(settings.partControlID+i);
			
			$('#'+settings.partTabID+i).hide();
			$('#'+settings.partTabID+1).show().addClass(settings.tabClass);
			$('#MCPanel li.number:first,#MRPanel li.number:first').addClass('highlighted');	
			
			$('#'+settings.partControlID+i).click(function(){
				//Find the correct tab content
				$(this).closest('.tabContent').find('.'+settings.tabClass).hide().removeClass(settings.tabClass);
				
				// if your parent is MC do something otherwise do something else
				var sParent = $(this).parent().attr('id');
				if(sParent=="MRPanel"){
					$('#MRPanel').find('.highlighted').removeClass('highlighted');
					$(this).addClass('highlighted');
				} else {
					//Its MC Panel
					$('#MCPanel').find('.highlighted').removeClass('highlighted');
					$(this).addClass('highlighted');
				}
				var currOpenIndex=$(this).attr('id');
				currOpenIndex=currOpenIndex.substring(9);
				//Get the tab ID
				var tabId = $(this).closest('.tabContent').attr('id');
				$('#'+tabId+currOpenIndex).show().addClass(settings.tabClass);
				elmCounter=parseInt(currOpenIndex);
				return false;
			});
		}
		
		$('#'+settings.nextCtrl).click(function(){
			var sParent = $(this).parent().attr('id');
			//Find the correct tab content
			$(this).closest('.tabContent').find('.'+settings.tabClass).hide().removeClass(settings.tabClass);
			elmCounter=elmCounter+1;
			if(elmCounter>tabsNo){elmCounter=1};
			if (sParent == "MRPanel") {
				$('#MRPanel').find('.highlighted').removeClass('highlighted');
				$('#MRcontrol'+elmCounter).addClass('highlighted');
				//alert($('#MRcontrol'+elmCounter).attr('id'));
			} else {
				$('#MCPanel').find('.highlighted').removeClass('highlighted');
				$('#MCcontrol'+elmCounter).addClass('highlighted');
				//alert($('#MCcontrol'+elmCounter).attr('id'));
			}
			//Get the tab ID
			var tabId = $(this).closest('.tabContent').attr('id');
			$('#'+tabId+elmCounter).show().addClass(settings.tabClass);
			return false;
		});
		
		$('#'+settings.previousCtrl).click(function(){
			var sParent = $(this).parent().attr('id');
			//Find the correct tab content
			$(this).closest('.tabContent').find('.'+settings.tabClass).hide().removeClass(settings.tabClass);
			elmCounter=elmCounter-1;
			if(elmCounter<=0){elmCounter=tabsNo};
			if (sParent == "MRPanel") {
				$('#MRPanel').find('.highlighted').removeClass('highlighted');
				$('#MRcontrol'+elmCounter).addClass('highlighted');
			} else {
				$('#MCPanel').find('.highlighted').removeClass('highlighted');
				$('#MCcontrol'+elmCounter).addClass('highlighted');
			}
			//Get the tab ID
			var tabId = $(this).closest('.tabContent').attr('id');
			$('#'+tabId+elmCounter).show().addClass(settings.tabClass);
			return false;
		});
		
	});
	return this;											
	}


})(jQuery);


	$('#mostRead').alternator({
		partTabID: "mostRead",
		partControlID: "MRcontrol",
		previousCtrl: "MRprevious",
		nextCtrl: "MRnext"
	});
	
	$('#mostCommented').alternator();
	
	
	// 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();
	});
	
		
});


