// body onload
$(function(){
	if ($('#tabs-area').is(':visible')){
		// 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 true;
				}
			});
		});
		// 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;
				s.t();
				// send Eloqua tracking data
				setTimeout("elqFCS(location.href.replace('#',''))",500);
			}
		}).tabs('select',window.location.hash+'-tab');
	} else {
		var currentPage = document.URL.substring(document.URL.lastIndexOf('/'));
		$('#secondary-nav a').each(function(){
		    var checkPage = this.href.substring(this.href.lastIndexOf('/'));
		    if(checkPage==currentPage){
		    		$(this).parent('li').addClass('highlight');
		        if($(this).parents('li.has-children')){
		            $(this).parents('li.has-children').addClass('expanded').children('ul').show();
		        }
		        return false;
		    }
		});
		$('div.promo').click(function(){
		    window.location=$(this).children('a:first').attr('href');
		});
	}
});
