$(document).ready(function(){
	
		// if a-list searchbox exists
		if ($('#frmSearchAList_sSearchPhrase').length) {
		
			// sets the initial value for search phrase field, then removes text on focus
			var sDefaultPhrase = 'Eg, name, company or job title';
			var sDefaultClass = 'searchDefault';
			
			//Add a class to style default state
			$("#frmSearchAList_sSearchPhrase").addClass(sDefaultClass);
		  
			$("#frmSearchAList_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);
				};
			});
		};
	
		//Replace body class if JavaScript is enabled
		$('body.jsDisabled').removeClass('jsDisabled');
	
		//Site Search Type Select box
		jQuery.fn.selectStyling = function(){
			
			 if(!$.browser.msie || ($.browser.msie&&$.browser.version>6)){
				 	
				 	var selected = $(this).find(':selected');
					$(this).after('<span class="selectBox"><span>'+selected.text()+'</span></span>').css({position:'absolute', opacity:0,fontSize:$(this).next().css('font-size')});
					var selectBoxSpan = $(this).next();
					var selectBoxWidth = parseInt($(this).width()) - parseInt(selectBoxSpan.css('padding-left')) -parseInt(selectBoxSpan.css('padding-right'));			
					var selectBoxSpanInner = selectBoxSpan.find(':first-child');
					selectBoxSpan.css({display:'inline-block'});
					selectBoxSpanInner.css({width:selectBoxWidth, display:'inline-block'});
					var selectBoxHeight = parseInt(selectBoxSpan.height()) + parseInt(selectBoxSpan.css('padding-top')) + parseInt(selectBoxSpan.css('padding-bottom'));
					
					$(this).height(selectBoxHeight).change(function(){
						selectBoxSpanInner.text($(this).find(':selected').text());
					});
					
			 }
			 
		};
		$('#searchType').selectStyling();
		$('#frmSearchAList_sYear').css('z-index','1000').selectStyling();
		
		
		$('#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();
	});
	
	
	
		
});
$(function(){	

	// variables
	var nSyncIndex=0,
		elmCounter=0,
		elmsNo=$(".showcaseContent").length,														// the number of stories to show
		eTimer=$('#timer'),
		nCounter=0,
		bState=1,
		fShowCase = {},
		fTimeout,
		rootID = "showcase",
		elmClass = "showcaseContent", 																// the story's class
		partID = "story",																			// the story's partial ID (is followed by a number)
		liPartID = "story",
		imageID = "showcaseImage",																	// the primary image partial ID for The Work section only
		aBgStates	= ['0','5','10','15','20','25','30','35'],

		elms = new Array(),																			// I want an array with all the stories' IDs
		ctrls = new Array(),																		// and one with the list-items' ones
		imgs = new Array();																			// and one with the primary images for The Work section only
	
	for (var i=1;i<=elmsNo;i++) {
		elms.push(partID+i);
		ctrls.push(liPartID+i+'Image');
		imgs.push(imageID+i);
	};

	// define functions
	fShowCase.init = function(){
		//eTimer.attr('title',sTimerTitlePause);
		$('#'+elms[0]+' .story').addClass('currentStory').show();
		$('#'+ctrls[0]).addClass('currentStory');	
		$('#'+imgs[0]).addClass('currentStory');	
		$('#showcaseNav #current').html("1");
	};
	fShowCase.cycle = function(){
		eTimer.css('background-position','0px -'+aBgStates[nCounter]+'px');
		nCounter=nCounter>6?0:nCounter+1;
		nSyncIndex=nCounter==0?1:0;
		if (elmsNo > 1 && nSyncIndex > 0){fShowCase.showNext()};
		bState=1;
		fTimeout=setTimeout(fShowCase.cycle,1000);
	};
	fShowCase.pause = function(){
		eTimer.css('background-position','0px -'+aBgStates[7]+'px');
		clearTimeout(fTimeout);
		nCounter=0;
		bState=0;
	};
	fShowCase.showNext=function(){	
		$('#'+elms[elmCounter++]+' .story').hide().removeClass('currentStory');
		$('#'+elms[elmCounter-1]+'Image').removeClass('currentStory');
		$('#'+imgs[elmCounter-1]).hide();															// hide primary image in The Work section showcase only
		if(elmCounter > elmsNo-1){elmCounter = 0;}													// back to 1 after 6
		$('#'+elms[elmCounter]+' .story').addClass('currentStory').fadeIn();
		$('#'+elms[elmCounter]+'Image').addClass('currentStory');
		$('#'+imgs[elmCounter]).addClass('currentStory');
		$('#showcaseNav #current').html(elmCounter+1);
		$('#'+imgs[elmCounter]).fadeIn();															// show next primary image in The Work section showcase only
	};
	
	fShowCase.showPrev=function(){													// show the next & update list-items' class
		$('#'+elms[elmCounter--]+' .story').hide().removeClass('currentStory');
		$('#'+elms[elmCounter+1]+'Image').removeClass('currentStory');
		$('#'+imgs[elmCounter+1]).hide();															// hide primary image in The Work section showcase only
		if(elmCounter <= -1){elmCounter = elmsNo-1;}			
		$('#'+elms[elmCounter]+' .story').addClass('currentStory').fadeIn();
		$('#'+elms[elmCounter]+'Image').addClass('currentStory');
		$('#'+imgs[elmCounter]).addClass('currentStory');
		$('#showcaseNav #current').html(elmCounter+1);
		$('#'+imgs[elmCounter]).fadeIn();															// show previous primary image in The Work section showcase only
	};

	// event handlers
	for (var i=0;i<ctrls.length;i++){																// bind a click-handler to each control
		$('#'+ctrls[i]).hover(function(){
			if(elmsNo > 1) {
				var elmID=this.id.charAt(liPartID.length);										// the index of the clicked control
				$('#'+rootID).find('.showcaseContent .currentStory').hide().removeClass('currentStory');
				$('#'+rootID).find('.imgContent.currentStory').removeClass('currentStory');
				$('#'+rootID).find('#primaryImage .currentStory').hide().removeClass('currentStory');		// when in the work section only
				$('#'+elms[elmID-1]+' .story').addClass('currentStory').show();
				$('#'+elms[elmID-1]+'Image').addClass('currentStory');
				$('#'+imgs[elmID-1]).addClass('currentStory').show();										// when in the work section only
				elmCounter = elmID-1;	
				$('#showcaseNav #current').html(elmCounter+1);															
				fShowCase.pause();																	// pause the ShowCase
			} 
			return false;
		},
		function(){
			fShowCase.cycle();
			return false;
		}
		);
	};
	
	$('#next a').click(function(){												// next button
		if (elmsNo > 1) {fShowCase.showNext();}
		return false;
	});

	$('#previous a').click(function(){											// previous button
		if (elmsNo > 1) {fShowCase.showPrev();}
		return false;
	});
	
	$('#showcaseNav,.showcaseContent,#primaryImage img').hover(function(){		// #primaryImage img for The Work section only
			fShowCase.pause();
			return false;
		},
		function(){
			fShowCase.cycle();
			return false;
		}
	);
	
	eTimer.click(function(){
		// if the showcase is playing pause it, othw play it
		if(bState){
			fShowCase.pause();
		} else {
			fShowCase.cycle();
		};
	});

	// init
	fShowCase.init();
	fShowCase.cycle();

	// show Network list
	$('div#networkList').hide();
	
	$('#navContent h3 a').toggle(function() {
		$('#navContent div#networkList').show();
	}, function() {
		$('#navContent div#networkList').hide();
	});

});




