// tabs history functionality
$(function(){  
  // Get the change in # value and apply the tabs-selected class to the corresponding tab
  $(window).bind( 'hashchange', function(){
    var hash = location.hash;    
	var firstTabLinkValue = $('ul.tabs li:first a').attr('href');
    // loop through all tabs, apply the tabs-selected class to the selected tab
    $('ul.tabs li a').each(function(){
      var that = $(this);
      that[ that.attr( 'href' ) === hash ? 'addClass' : 'removeClass' ]( 'tabs-selected' );	  
    });
	
	$('#centerColumnContent > div').each(function(){
      $(this).hide();	
    });
	// if the url does not have a # value or has a lone # on initial page load tab update, then select the first tab by default	
	// selecting the first tab must also select the first content div displaying tab1 content
	if (hash == '' || hash == '#') {
	  $('ul.tabs li:first a').addClass('tabs-selected');
	  $('#centerColumnContent div.centerColumnTabContent:first').show();	  
	}
	// if the url does have a # value ie. #this_is_a_value, then show the corresponding content for that value
	// in order for the content to show as expected, the relevant centerColumnTabContent div must have an id to match the corresponding 	
	// tab href with the suffix _tabcontent ie. <div class="centerColumnTabContent" id="key_feature_tabcontent">
	else {
	  $(hash + "_tabcontent").show();	
	}
	// run tracking update to send hit to omniture
	setHashToProp(hash,firstTabLinkValue);
  })
  // when another tab is clicked, or the page is loaded, fire the update
  $(window).trigger( 'hashchange' );
  //alert(location.hash);  
});

//tracking update where the hash value is bound to a prop(props are custom omniture variables) and sent to omniture
function setHashToProp(hashreader,firstTabLinkValueReader) {
  // BEFORE SENDING THE HASH VALUE TO OMNITURE, RUN CHECK TO SEE WHAT THE HASH VALUE IS
  // THIS IS A CLEANUP TO ENSURE THAT IF URL HAS THE SOLE VALUE OF "#" THEN CHANGE THE VALUE SENT TO OMNITURE TO BLANK SO AS NOT TO CREATE A NEW ENTRY FOR "#"
  // IF THE VALUE IS EQUAL TO THE HREF OF THE FIRST TAB, THEN THE USER IS OBVIOUSLY VIEWING TAB 1, THEREFORE SET THE VALUE AGAIN TO BLANK FOR THE SAME REASON
  // DOING THIS PREVENTS RESULTS APPEARING IN THE TRACKING FOR A "#" OR "FIRST_TAB_HREF_VALUE" SO ONLY SHOWING THE ACTUAL TABS
  if (hashreader == "#" || hashreader == firstTabLinkValueReader) {
	  hashreader = "";
	  //alert("EQUALS A HASH");
	  //alert(hashreader);
	  var s=s_gi('ybschelsea');
	  s.linkTrackVars='prop1';
	  s.linkTrackEvents='event1';
	  s.prop1 = s.pageName + hashreader;
	  s.tl(this,'o','Hashed Link');	
  }
  else {
	  //alert("OTHER VALUE");
	  var s=s_gi('ybschelsea');
	  s.linkTrackVars='prop1';
	  s.linkTrackEvents='event1';
	  s.prop1 = s.pageName + hashreader;
	  s.tl(this,'o','Hashed Link');	  
  }
  //alert(s.prop1);
};