/** * Fallback if console.log() does not exist - http://ajax-prototype.blogspot.com/2006/12/workaround-to-make-firebug-consolelog.html * */try { console.log('init console... done'); } catch(e) { console = { log: function(str) {	$('#debug').append(str+'<br/>');} } }$(document).ready( function(){
	
	initiateGamebookTour();
		//Testimonial hovers		$('.testimonialBlock').hover( function () {	    $('.testimonial' ,$(this)).show();	  }, 	  function () {	    $('.testimonial' ,$(this)).hide();	  }	);	//Login	$('a.clublogin').mouseover( function(){		$('#login').css('width', '410px');		$('#login').css('height', '100px');	});		$('#login').mouseleave( function() {		$('#login').css('width', '0px');		$('#login').css('height', '0px');	});		//Game formats - click	$('#gameFormatsNav a').click( function() {		var clickedId = $(this).attr('id').split('-');		clickedId = clickedId[1];				//Show correct game format		$('.gameFormatInner').hide();		$('#gfi-'+clickedId).show();				//Highligh correct link		$('#gameFormatsNav a').removeClass('current');		$(this).addClass('current');				return false;	});		//Show first game format and set nav	$('.gameFormatInner:first').show();	$('#gameFormatsNav a:first').addClass('current');		//Game formats - hover	$("#gameFormatsNav a").hover(      function () {      	var hoverId = $(this).attr('id').split('-');      	hoverId = hoverId[1];              //Show hovered format		$('.gameFormatInner').hide();		$('#gfi-'+hoverId).show();				//Highligh correct link		$('#gameFormatsNav a').removeClass('current');		$(this).addClass('current');      },       function () {        //Do nothing      }    );        		//Expanded text section for game formats	$('#moreGames').click( function(){		if( $(this).hasClass('closed') ){			$('#extendedGames').show(500);			$(this).removeClass('closed');		}		else{			$('#extendedGames').hide(500);			$(this).addClass('closed');		}				return false;	});		//Device tabs	$('.tab:first', $('#deviceTabsContainer')).show();		//Click on primary tab	$('.primaryTabNav a').click( function(){		$('#'+$(this).parent().parent().parent().attr('id')).hide();		$('#'+$(this).attr('class')+'1').show();				return false;	});		//Click on secondary tab	$('.secondaryTabNav a').click( function(){		var stab = $(this).attr('class').split('-')[1];		$('#'+$(this).parent().parent().parent().attr('id')).hide();		$('#tab-'+$(this).parent().parent().parent().attr('id').split('-')[1].substr(0,1)+''+stab).show();		return false;	});			//first last (alpha/omega) classes to testimonials	$('.col-style-2:last', $('#testimonials')).addClass('omega');		//Fancybox	$('a#corporateBlockLink').fancybox({	 	'hideOnContentClick': false,	 	//'centerOnScroll': false,	 	'frameWidth': 500,	 	'frameHeight': 500	});		$("a#videoplay").fancybox({	 	'hideOnContentClick': false,	 	'frameWidth': 1063,	 	'frameHeight': 505	});
	
	$('a.iframepdf').fancybox({	 	'hideOnContentClick': false,	 	//'centerOnScroll': false,	 	'frameWidth': 940,	 	'frameHeight': 650	});		$("a#subVideoPlayLink1").click( function() {		$('a#videoplay').trigger('click');		$('#videoNavigator a#vpk-0').trigger('click');				return false;	});		$("a#subVideoPlayLink2").click( function() {		$('a#videoplay').trigger('click');		$('#videoNavigator a#vpk-1').trigger('click');				return false;	});		//Video nav	$('#videoNavigator a').live('click', function() {		//hide all video players		$('.videoPlayer').hide();				//Remove and add current class		$('#videoNavigator a').removeClass('current');		$(this).addClass('current');		//Show correct video player		$('#fancy_div #vp-'+$(this).attr('id').split('-')[1]).show();				return false;	});		//Page load first video	$('#videoNavigator a:first').addClass('current');	$('.videoPlayer:first').show();		//If SIFR fails set text color	setTimeout( function(){		$('h1').css('color', '#9ad227');		$('.clickToTry').css('color', '#9ad227');		$('h3').css('color', '#000000');		$('.tagline').css('color', '#9ad227');		$('.testimonialPerson').css('color', '#9ad227');	}, 4000);});


//////////////////////////////////////
//					 
//	 GAMEBOOK TOUR
//					 
//////////////////////////////////////

var gtSettings = {
		useFade : false,		// if set to true, bubbles are shown one by one
		fadeInTime : 2000,		// time the bubble takes to fade in
		delayTime : 3500,		// time the bubble is shown
		fadeOutTime : 500,		// time the bubble takes to fade out
		showAfter : true		// if set to true, all bubbles are shown after the animations have completed
	}

/*
 * Initiates the Gamebook Tour
 */
function initiateGamebookTour() {
		
	var slides = $('#gamebookTourSlides').children();
	
	// Slide Indicators
	for(var i = 0; i < slides.length; i++) {
		$('#gamebookTour #slide-navi .indicators').append('<span class="ind">&bull;</span>');	
	}
	
	var indicators = $('#gamebookTour #slide-navi .indicators').children();
	
	// Activate the first slide
	$(slides[0]).addClass('active').show();
	$(indicators[0]).addClass('active');
	
	
	//	
	// Navigation
	//
	
	// Next tour slide button
	$('#gamebookTour #slide-navi #next').live('click', function() {
		var current = $('#gamebookTourSlides .active');
		var ind = $('#gamebookTour #slide-navi .indicators .active');

		if( current.attr('id') !=  $(slides[slides.length - 1]).attr('id') ) {
			$(current).removeClass('active').hide().next().addClass('active').show();
			$(ind).removeClass('active').next().addClass('active');
			
			slideChange( $(current), $(current).next() );
			
		}
		
		return false;
	});

	// Previous tour slide button
	$('#gamebookTour #slide-navi #prev').live('click', function() {
		var current = $('#gamebookTourSlides .active');
		var ind = $('#gamebookTour #slide-navi .indicators .active');
		
		if( current.attr('id') !=  $(slides[0]).attr('id') ) {
			$(current).removeClass('active').hide().prev().addClass('active').show();
			$(ind).removeClass('active').prev().addClass('active');
			
			slideChange( $(current), $(current).prev() );
		}

		return false;
	});
	
	showMessage($(slides[0]), 150, 50, "This is the crappy message");
			
}

/*
 * Opens and start's the tour
 */
function openGamebookTour() {
	var slides = $('#gamebookTourSlides').children();
	var indicators = $('#gamebookTour #slide-navi .indicators').children();
	var current = $('#gamebookTourSlides .active');
	
	$(current).removeClass('active').hide().prev().addClass('active').show();
	$(slides[0]).addClass('active').show();
	
	$(indicators).removeClass('active');
	$(indicators[0]).addClass('active');
	
	jQuery.facebox({ div: '#gamebookTour' });
	slideChange($(slides[0]), $(slides[0]));

}

/*
 * Shows the bubble on slide
 */
function showMessage(slide, x, y, msg) {
	var bubble = $('<div class="bubbleContainer"><div class="arrow"></div><div class="bubble"></div></div>');
	var inner = $(bubble).children()[1];

	$(inner).html(msg);
	$(bubble).filter('.bubble').html(msg);
	$(slide).append(bubble);
	$(bubble).css({left: x, top: y }).hide();
	
	return $(bubble);
}

/*
 * Handles the slide changing
 */
function slideChange(oldSlide, newSlide) {
	// Clear bubbles from old slide
	$(oldSlide).children('.bubbleContainer').remove();
	
	// Change slide title
	$('#gamebookTour #slideTitle').html($(newSlide).attr('title'));
	
	animateBubbles( 'slide' + $(newSlide).attr('id').split('-')[2], $(newSlide), 1 );
	
}

/*
 * Animates all bubbles within slide
 */
function animateBubbles(name, slide, nr) {

	var bubble = slideBubbles[name][nr];
	var max = 0;
	$.each(slideBubbles[name], function(key, params) {
		max++;
	});
	
	var current = '';

	// Show bubbles on by one if fade is used. After all are shown once, make all visible.
	if(gtSettings.useFade) {
		current = showMessage( $(slide), bubble.x, bubble.y, bubble.msg );
		$(current).fadeIn(gtSettings.fadeInTime).delay(gtSettings.delayTime).fadeOut(gtSettings.fadeOutTime, function() {
			$(this).remove();
			if(nr + 1 <= max) { 
				animateBubbles(name, slide, nr + 1);
			} else if (gtSettings.showAfter) {
				$.each(slideBubbles[name], function(key, params) {
					current = showMessage( $(slide), params.x, params.y, params.msg );
					current.show();
				});
			}
		});
		
	} else {

		// Show all bubbles at once
		$.each(slideBubbles[name], function(key, params) {
					current = showMessage( $(slide), params.x, params.y, params.msg );
					current.fadeIn(gtSettings.fadeInTime);
				});
	}
		
}

function recursiveAnimate(current, next) {
}

/*
 * Bubble settings
 */
var slideBubbles = {
		slide1 : {
				1 : {					
					x : 120,
					y : 45,
					msg : 'This is the Clubhouse home page.'
				},
				
				2 : {					
					x : 0,
					y : 250,
					msg : 'Your friends who are on the course right now! Click a friend to see their game (scorecard).'
				},
				
				3 : {					
					x : 300,
					y : 450,
					msg : 'Comment on your friend’s rounds here. They will see them on the course as they play!'
				}

			},
			
		slide2 : {
				1 : {					
					x : 190,
					y : 45,
					msg : 'This is your personal profile page.'
				},
				
				2 : {					
					x : 400,
					y : 145,
					msg : 'On your profile page, you can view all your comments to your friends, and also view and edit your golf gear info.'
				},
				
				3 : {					
					x : 330,
					y : 400,
					msg : 'Here you change your personal details, turn on game statistics collection, etc.'
				}

			},

		slide3 : {
				1 : {					
					x : 265,
					y : 45,
					msg : 'The Friends page allows you to see your friends and their games'
				},
				
				2 : {					
					x : 110,
					y : 120,
					msg : 'Search for people you know by name.'
				},
				
				3 : {					
					x : 430,
					y : 475,
					msg : 'Invite friends to the Clubhouse by email.'
				}

			},

		slide4 : {
				1 : {					
					x : 350,
					y : 45,
					msg : 'The Games page shows all the games you’ve played.'
				},
				
				2 : {					
					x : 480,
					y : 120,
					msg : 'You can also see all the different game formats that GameBook supports.'
				},
				
				3 : {					
					x : 420,
					y : 310,
					msg : 'View the results (scorecard, leaderboard, etc.) of games you’ve played.'
				},
				
				4 : {					
					x : 150,
					y : 420,
					msg : 'Past games can be added to your list of games.'
				}

			},

		slide5 : {
				1 : {					
					x : 0,
					y : 230,
					msg : 'Game details shows the scorecard, primary and side game leaderboards, contests, wagers, etc.'
				},
				
				2 : {					
					x : 285,
					y : 495,
					msg : 'You can also both print and email the game information from this page.'
				}

			},

		slide6 : {
				1 : {					
					x : 425,
					y : 45,
					msg : 'On the Stats page you can view your personal stats and compare them against your friends.'
				},
				
				2 : {					
					x : 240,
					y : 450,
					msg : 'When your mouse is over a bar, the round’s stats is shown below.'
				},
				
				3 : {					
					x : 520,
					y : 300,
					msg : 'The bars represent each played round. The red one is the season’s best. Click on the bar to see the scorecard.'
				}

			},

		slide7 : {
				1 : {					
					x : 450,
					y : 120,
					msg : '“Compare Rounds” allows you to see round details and compare yourself against friends.'
				},
				
				2 : {					
					x : 205,
					y : 250,
					msg : 'The “Rank” column shows your rank compared to your friends for the given stat (rounds, shots, eagles, birdies, etc.).'
				}

			},

		slide8 : {
				1 : {					
					x : 500,
					y : 45,
					msg : 'Course information page.'
				},
				
				2 : {					
					x : 130,
					y : 220,
					msg : 'Click the course name to see the course scorecard, pictures and course comments.'
				},
				
				3 : {					
					x : 255,
					y : 500,
					msg : 'Search for courses here.'
				},
				
				4 : {					
					x : 555,
					y : 500,
					msg : 'Add a new course here.'
				}

			}
	}



