//for SEO purposes change title and H1
function setTitleHeading (title, heading) {
	document.title = title;
	$('h1.tab-h1').html(heading);
    if(typeof applyCufon == 'function') {
        Cufon.replace('h1.tab-h1', {hover: true, fontFamily: 'Rockwell'});
    }
}


function homePagePowwownowTab() {
	tabs_deactivate(2);
	tabs_deactivate(3);
	tabs_activate(1);
	
	setTitleHeading(HOMEPAGE_POWWOWNOW_TITLE,HOMEPAGE_POWWOWNOW_H1);
	
	homePageTabs_ShowContentForTab(1);
	
	Google_tracker('/Land_PowwownowAccess');
}

function homePagePlusTab() {
	tabs_deactivate(1);
	tabs_deactivate(3);
	tabs_activate(2);

	setTitleHeading(HOMEPAGE_PLUS_TITLE,HOMEPAGE_PLUS_H1);

	homePageTabs_ShowContentForTab(2);
	
	// Add canonical link element for SEO purposes; check for existence first to avoid duplicates
	if ( $('head link[rel="canonical"]' ).length == 0 ) {
		$('head').append('<link href="'+HOMEPAGE_CANONICAL_URL+'" rel="canonical" />');
	}
	
	
	
	Google_tracker('/Land_PlusAccess');
}

function homePagePremiumTab() {
	tabs_deactivate(1);
	tabs_deactivate(2);
	tabs_activate(3);

	setTitleHeading(HOMEPAGE_PREMIUM_TITLE,HOMEPAGE_PREMIUM_H1);

	homePageTabs_ShowContentForTab(3);
	
	// Add canonical link element for SEO purposes; check for existence first to avoid duplicates
	if ( $('head link[rel="canonical"]' ).length == 0 ) {	
		$('head').append('<link href="'+HOMEPAGE_CANONICAL_URL+'" rel="canonical" />');
	}
	
	Google_tracker('/Land_PremiumAccess');
}


/**
 * Sets up the animation for the homepage tabs
 */
function homePageTabs_Init( top ) {

	if (undefined != top) {
		tabs_setUpTabPositions( top );
	} else {
		tabs_setUpTabPositions();
	}

	tabs_setUpHoverWiggle('1');
	tabs_setUpHoverWiggle('2');
	tabs_setUpHoverWiggle('3');

	// Switch tab on load depending on URL
	switch (window.location.pathname) {
		case HOMEPAGE_PLUS_TAB :
			homePagePlusTab();
			break;
			
		case HOMEPAGE_PREMIUM_TAB :
			homePagePremiumTab();
			break;
	}
	
	

	
	$('#tab-1').click( homePagePowwownowTab );
	$('#tab-2').click( homePagePlusTab );
	$('#tab-3').click( homePagePremiumTab );
	
}

function homePageTabs_ShowContentForTab(tabNumber) {
	switch(tabNumber) {
	case 1:
		$('#tabs-container').stop();
		$('#tabs-container').animate({height: '370px'},'slow');
		$('#tabs-container').animate({width: '710px'}, 'slow',  function() {
			if (jQuery.browser.version != '7.0') {$('#right-sidebar').fadeIn('fast');} 
			if (jQuery.browser.version == '7.0') {$('#right-sidebar').show();} 
			$('#tabs-grid').removeClass('grid_24');
			$('#tabs-grid').addClass('grid_18');  
		});

		$('.content-seperator').show();

		$('#left-content-container').show();
		$('#right-menu-container').show();
		$('#right-content-container').show();
		$('#tabs-container').css('background','#a6cf5a');
		$('#tab-plus').hide();
        $('#tab-plus-register').hide();
		// hide registered form if opened
		$('#tab-pwn-pin-registered').hide();
		
		$('#tab-premium').hide();
		$('#tab-pwn').show();
		break;
	case 2:
		$('#tabs-container').stop();
		$('.content-seperator').show();
		// hide registered form if opened
		$('#tab-pwn-pin-registered').hide();
		
		// hide B testing options
		$('.pwn-registration-option').hide();
		$('.pwn-walletcard-option').hide();
		
		$('#tab-plus .compare-button-container').show();
        $('#tab-plus-register').hide();

		$('#tabs-container').animate({height: '370px'}, 'slow');
		$('#tabs-container').animate({width: '710px'}, 'slow',  function() {
			$('#right-sidebar').fadeIn('fast'); 
			$('#tabs-grid').removeClass('grid_24');
			$('#tabs-grid').addClass('grid_18');  
		});
		$('#left-content-container').show();
		$('#right-menu-container').show();
		$('#right-content-container').show();
		$('#tabs-container').css('background','#7ea2b4');
		$('#tab-pwn').hide();
		$('#tab-premium').hide();
		$('#tab-plus').show();
		$('.divider-container').hide();
	  break;
	case 3:
		
		// hide registered form if opened
		$('#tab-pwn-pin-registered').hide();
		$('.content-seperator').hide();
		$('#left-content-container').hide();
		$('#right-menu-container').hide();
		$('#tabs-container').css('background','#465c63');
		$('#tab-pwn').hide();
		$('#tab-plus').hide();
        $('#tab-plus-register').hide();
		$('#tab-premium').show('slow');
		$('.divider-container').hide();
		$('#right-content-container').hide();
		
		// hide B testing options
		$('.pwn-registration-option').hide();
		$('.pwn-walletcard-option').hide();
		
		if (jQuery.browser.version != '7.0') {
			$('#right-sidebar').fadeOut('fast', function() {
				$('#tabs-grid').removeClass('grid_18');
				$('#tabs-grid').addClass('grid_24');
				$('#tabs-container').stop();
				$('#tabs-container').animate({width: '100%'}, 'slow');
				$('#tabs-container').animate({height: '630px'}, 'slow');
			});
		}

		if (jQuery.browser.version == '7.0') {
			$('#right-sidebar').hide();
			$('#tabs-grid').removeClass('grid_18');
			$('#tabs-grid').addClass('grid_24');
			$('#tabs-container').stop();
			$('#tabs-container').animate({width: '100%'}, 'slow');
			$('#tabs-container').animate({height: '630px'}, 'slow');
		}
	  break;
	case 4:
		$('#tabs-container').stop();
        $('#tabs-container').css('overflow', 'visible');
		$('.content-seperator').show();
		// hide registered form if opened
		$('#tab-pwn-pin-registered').hide();
		
		// hide B testing options
		$('.pwn-registration-option').hide();
		$('.pwn-walletcard-option').hide();
		
		$('#tab-plus .compare-button-container').show();

		$('#left-content-container').show();
		$('#right-menu-container').show();
		$('#right-content-container').show();
		$('#tabs-container').css('background','#7ea2b4');
		$('#tab-pwn').hide();
		$('#tab-premium').hide();
		$('#tab-plus').hide();
		$('.divider-container').hide();
        $('#tab-plus-register').show();
	  break;
	}
}


/**
 * Login Tabs
 */
 
function loginPageLoginTab() {
	$('#tab-1').css('top', '-=20');
	tabs_deactivate(2);
	tabs_activate(1);
	loginPageTabs_ShowContentForTab(1);
}

function loginPageCreateALoginTab() {
	tabs_deactivate(1);
	tabs_activate(2);
	loginPageTabs_ShowContentForTab(2);

	// Add canonical link element for SEO purposes; check for existence first to avoid duplicates
	if ( $('head link[rel="canonical"]' ).length == 0 ) {	
		$('head').append('<link href="'+LOGIN_PAGE_CANONICAL_URL+'" rel="canonical" />');
	}
}

function loginPageTabs_Init() {
	// Pass in top position of active tab
	tabs_setUpTabPositions( 210 );

	tabs_setUpHoverWiggle('1');
	tabs_setUpHoverWiggle('2');
	
	// Switch tab on load depending on URL
	switch (window.location.pathname) {
		case LOGIN_PAGE_CREATE_A_LOGIN_TAB :
			loginPageCreateALoginTab();
			break;
	}

	$('#tab-1').click( loginPageLoginTab );
	$('#tab-2').click( loginPageCreateALoginTab );
}

function loginPageTabs_ShowContentForTab(tabNumber) {
	switch(tabNumber) {
	case 1:
		$('#tab-mypwn-create-login').fadeOut('slow', function() {
			$('#tab-mypwn-login').show('slow');
		});
		break;
	case 2:
		$('#tab-mypwn-login').fadeOut('slow', function() {
			$('#tab-mypwn-create-login').show('slow');
		});
		break;
	}
}


/**
 * Web Conferencing Tabs
 */

function webConferenceShowtimeTab() {
	setTitleHeading(WEB_CONFERENCING_SHOWTIME_TITLE,WEB_CONFERENCING_SHOWTIME_H1);
	webConferenceTabs_ShowContentForTab(1);
}

function webConferenceDemoTab() {

	setTitleHeading(WEB_CONFERENCING_DEMO_TITLE,WEB_CONFERENCING_DEMO_H1);

	webConferenceTabs_ShowContentForTab(2);
	
	// Add canonical link element for SEO purposes; check for existence first to avoid duplicates
	if ( $('head link[rel="canonical"]' ).length == 0 ) {	
		$('head').append('<link href="'+WEB_CONFERENCING_CANONICAL_URL+'" rel="canonical" />');
	}
}

function webConferenceGetStartedTab() {
	setTitleHeading(WEB_CONFERENCING_GET_STARTED_TITLE,WEB_CONFERENCING_GET_STARTED_H1);
	webConferenceTabs_ShowContentForTab(3);
	
	// Add canonical link element for SEO purposes; check for existence first to avoid duplicates
	if ( $('head link[rel="canonical"]' ).length == 0 ) {	
		$('head').append('<link href="'+WEB_CONFERENCING_CANONICAL_URL+'" rel="canonical" />');
	}
}

function webConferenceTabs_Init() {

	tabs_setUpTabPositions();
	
	tabs_setUpHoverWiggle('1');
	tabs_setUpHoverWiggle('2');
	tabs_setUpHoverWiggle('3');
	
	// Switch tab on load depending on URL
	switch (window.location.pathname) {
		case WEB_CONFERENCING_DEMO_TAB :
			webConferenceDemoTab();
			break;
			
		case WEB_CONFERENCING_GET_STARTED_TAB :
			webConferenceGetStartedTab();
			break;
	}

	// Showtime TAB
	$('#tab-1').click( webConferenceShowtimeTab );

	// Demo TAB
	$('#tab-2').click( webConferenceDemoTab );

	// Get started TAB
	$('#tab-3').click( webConferenceGetStartedTab );

}

/**
 * Note, we have one more content number than we have in 
 * webConferenceTabs_Init(), this is for the download showtime section
 * where we don't have a clickable tab, but is called via other links
 */
function webConferenceTabs_ShowContentForTab(tabNumber) {
		

	switch(tabNumber) {
	case 1:
		tabs_deactivate(2);
		tabs_deactivate(3);
		tabs_activate(1);
		$('#tab-1').addClass('tab-1-green');
		$('#tab-1').removeClass('tab-1-grey');

		$('#tab-2').removeClass('tab-2-green');
		$('#tab-2').addClass('tab-2-grey');
		$('#tab-3').removeClass('tab-3-green');
		$('#tab-3').addClass('tab-3-grey');

		$('#tab-web-conferencing-get-started').hide();
		$('#tab-web-conferencing-demo').hide();
		$('#tab-web-conferencing-download').hide();
		$('#tab-web-conferencing-showtime').show();
		break;
	case 2:
		tabs_deactivate(1);
		tabs_deactivate(3);
		tabs_activate(2);
		$('#tab-2').addClass('tab-2-green');
		$('#tab-2').removeClass('tab-2-grey');

		$('#tab-1').removeClass('tab-1-green');
		$('#tab-1').addClass('tab-1-grey');
		$('#tab-3').removeClass('tab-3-green');
		$('#tab-3').addClass('tab-3-grey');
		
		$('#tab-web-conferencing-get-started').hide();
		$('#tab-web-conferencing-showtime').hide();
		$('#tab-web-conferencing-download').hide();
		$('#tab-web-conferencing-demo').show();
	  break;
	case 3:
		tabs_deactivate(1);
		tabs_deactivate(2);
		tabs_activate(3);
		$('#tab-3').addClass('tab-3-green');
		$('#tab-3').removeClass('tab-3-grey');

		$('#tab-1').removeClass('tab-1-green');
		$('#tab-1').addClass('tab-1-grey');
		$('#tab-2').removeClass('tab-2-green');
		$('#tab-2').addClass('tab-2-grey');

		$('#tab-web-conferencing-demo').hide();
		$('#tab-web-conferencing-showtime').hide();
		$('#tab-web-conferencing-download').hide();
		$('#tab-web-conferencing-get-started').show();
	  break;
	case 4:
		$('#tab-4').removeClass('tab-3-grey');
		$('#tab-4').addClass('tab-4-green');
		$('#tab-web-conferencing-demo').hide();
		$('#tab-web-conferencing-showtime').hide();
		$('#tab-web-conferencing-get-started').hide();
		$('#tab-web-conferencing-download').show();
	  break;
	}
}

function tabs_setUpTabPositions(top) {
	// IE fix for positioning tabs animation
	tab_active_position       = top || 71;
	tab_active_position_jump  = tab_active_position - 3;
	tab_passive_position      = tab_active_position + 37;
	tab_passive_position_jump = tab_passive_position - 3;

	if ((jQuery.browser.version == '6.0')||(jQuery.browser.version == '7.0')) {
		tab_active_position       = (top + 6) || 77;
		tab_active_position_jump  = tab_active_position - 3;
		tab_passive_position      = tab_active_position + 33;
		tab_passive_position_jump = tab_passive_position - 3;
	}

	if (jQuery.browser.version == '8.0') {
		tab_active_position       = (top + 1) || 74;
		tab_active_position_jump  = tab_active_position - 3;
		tab_passive_position      = tab_active_position + 36;
		tab_passive_position_jump = tab_passive_position - 3;
	}
}

function tabs_setUpHoverWiggle(tabNum) {
	$('#tab-' + tabNum).mouseenter(function() {
		//alert(jQuery.browser.version);
		$('#tab-' + tabNum + ':not(.active)').animate({
			top: tab_passive_position_jump + 'px'
		}, 300, function() {
			// Animation complete.
		});
	});

	$('#tab-' + tabNum).mouseleave(function() {
		$('#tab-' + tabNum + ':not(.active)').animate({
			top: tab_passive_position + 'px'
		}, 300, function() {
			$('#tab-' + tabNum + ' .tab-shadow').show();
		});
	});
}

/**
 * Returns the specified tab to the unactive position
 */
function tabs_deactivate(tabNum) {
	$('#tab-' + tabNum).stop();
	$('#tab-' + tabNum).removeClass('active');
	$('#tab-' + tabNum + ':not(.active)').animate({
		top: tab_passive_position + 'px'
	}, 300, function() {
		$('#tab-' + tabNum + ' .tab-shadow').show();
	});
}

/**
 * Puts a tab in the active position
 */
function tabs_activate(tabNum) {
	$('#tab-' + tabNum).addClass('active');
	$('#tab-' + tabNum + ' .tab-shadow').hide();
	$('#tab-' + tabNum).animate({
		top: tab_active_position_jump + 'px'
	}, 300, function() {
		$('#tab-' + tabNum).animate({
			top: tab_active_position + 'px'
		});
		$('#tab-' + tabNum).removeClass('passive');
	});
}

