// body onload
$(function(){
	// load the history script for tracking the loaded tab
	$.getScript('/scripts/jquery.history.js', function(){
		$.historyInit(function(hash){
			$('#tabs-area').tabs('select',hash + '-tab');
			fitToScreen();
		});
		// add tab, content, or side link clicks to the history
		$("#tabs-area a,#side a").click(function(e){
			// if this is a reference to a link on the same page, just switch the tab
			var hash_regexp = new RegExp(decodeURI(this.hash).replace('?','\\?')+'.*');
			if (this.hash && decodeURI(document.URL).indexOf(decodeURI(this.href).replace(hash_regexp,'')) > -1){
				// check if it is a tab link or a regular hash link (named anchor, popup, etc)
				if ($(this.hash.split('?')[0].replace('-tab','')+'-tab').length){
					$.historyLoad(this.hash.replace('#','').replace('-tab',''));
				}
				// set webinar if available
				var webinar = this.href.substring(this.href.lastIndexOf('?')+1);
				$('#webinarDateAndLocation').val(decodeURI(webinar));
				return false;
			}
		});
	});
	// initialize the tabs area and focus any form elements
	$('#tabs-area').tabs({
		selected: -1,
		show: function(e,ui){
			$(ui.tab.hash+" :text:visible:first").focus();
			// send Omniture tracking data
			s.pageName = ui.tab.hash;
			var s_code=s.t();
			if(s_code){
				document.write(s_code);
			}
		}
	}).tabs('select',window.location.hash+'-tab');
});