//tabs on the download and activation page for vSphere
var tabSelected = tabOn = tabFloat = null;
var selectTab = function(event) {
	if (tabOn != null) 
		tabOn.toggleClass('active');
	tabOn = $(this);
	tabOn.toggleClass('active');
	if (tabFloat != null) 
		tabFloat.hide();
	tabFloat = $(this.hash+'_float');
	tabFloat.show();
	//comment for the hash tab to show up in the url
	//event.preventDefault();
}
$(document).ready(function() {	
	var urlhash = null;
	if (window.location.hash != "")
		urlhash = window.location.hash;
	var hashOn = false;
	
    $(".tabhead ul li a").each(function() {
    	//Need help link is a tab but will behave as plain link
    	if ($(this.parentNode).attr('class') != 'needhelp') {
			$(this).click(selectTab);
			if ($(this.parentNode).is(":first-child")) {
				$(this).attr('class','first');
				//if urlhash is not set the select the first tab by default
				if (urlhash == null) {
					tabOn = $(this);
					tabOn.toggleClass('active');
					tabFloat = $(this.hash+'_float');
					tabFloat.show();
				}
			}
			if ($(this.parentNode).is(":last-child")) {
				$(this).attr('class','last');
			}
			//if urlhash is set the check if its one of the tab
			//if yes the select that tab
			if (urlhash != null) {
				if(urlhash == $(this).attr("href")) {
					tabOn = $(this);
					tabOn.toggleClass('active');
					tabFloat = $(this.hash+'_float');
					tabFloat.show();
					hashOn = true;
				}
			}
    	}
    });
    //if urlhash is set but its none of the tabs, then select the first tab
    if(urlhash != null && !hashOn) {
    	tabOn = $(".tabhead ul li a.first");
    	tabOn.toggleClass('active');
    	tabFloat = $($(".tabhead ul li a.first").attr("href")+'_float');    	
		tabFloat.show();
    }
});
