// jquery functions
$(document).ready(function(){
	
	// button rollover for all browsers   
		$('.button, .inputButton input').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    = '';
		 }
		});
		
		var sDefaultPhrase 				= 'Search for Jobs';
	  
		$("#frmSearchJobsPhrase").val(sDefaultPhrase).focus(function () {
		 if (this.value === sDefaultPhrase) {
		  this.value    = '';
		 }
		});
	
	// Title, Text & Image promo in the xCol, rollover effect
		
		// sets the element that is the hover trigger
		var sPromoItem					= '#xcol .promoImageTitleText';
		
		// sets the child element of sPromoItem that is the popup
		var sPopupElement				= '.promoTextContainer'
		
		// sets the speed of the popup in milliseconds
		var nSpeed						= 800;
		
		var sPopup						= $(sPromoItem).find(sPopupElement);
		var bHover						= false;
		var sPopupAnchor				= $(sPopup).find('a');
		
		// hides the popup on page load and sets styling
		$(sPopup).hide().css({'position':'absolute','opacity':'0.8'});
		
		$(sPromoItem).hover(
		function() {
			// on mouseover
			if (!bHover) {
				$(sPopupElement, this).stop().css({'top': 'auto','position': 'absolute'}).show("slide",{direction: "up"}, nSpeed);
				bHover = true;
			}
		}, 
		function() {
			// on mouseout
			$(sPopupElement, this).stop().hide("slide", {direction: "up"}, nSpeed);
			bHover = false;
		});			
		
		
		// --------------------------------------------------------
		// code for tab switching with most read and most commented
		// -------------------------------------------------------- 
		// please refer to wiki documentation to explain this fully
		
		// create variables for reference to html elements in the module
		var sMostReadTab					= 'li#mostReadTab';
		var sMostCommentedTab				= 'li#mostCommentTab';
		var sMostRead						= '#mostRead';
		var sModuleHeaders					= '#mostReadCommented .header';
		var sMostCommented					= '#mostComments';
		
		$('#mostReadCommented .tabbedNav').show(); // show the tabs if javascript available (by default this is hidden)
		$('#mostReadCommented .module').css('border-top','0'); // remove top border for module (when javascript disabled, the top border is shown)
		$(sModuleHeaders).hide(); // hide the h2 tags
		
		$(sMostRead).show(); // show most read list by default
		$(sMostCommented).hide(); // hide most commented list by default
		
		$(sMostReadTab).click(
			function() {
				$(sMostCommentedTab).removeClass('selected');
				$(sMostReadTab).addClass('selected');
				$(sMostCommented).hide();
				$(sMostRead).fadeIn();
				return false;
			}
		)
		
		$(sMostCommentedTab).click(
			function() {
				$(sMostReadTab).removeClass('selected');
				$(sMostCommentedTab).addClass('selected');
				$(sMostRead).hide();
				$(sMostCommented).fadeIn();
				return false;
			}
		)
});