//preload images
preload_b_6  = new Image();
preload_b_7  = new Image();
preload_b_8  = new Image();
preload_b_9  = new Image();
preload_b_10 = new Image();
preload_b_11 = new Image();
preload_b_12 = new Image();

preload_b_6.src  = 'http://cdn.athleon.com/home/v7/images/index/login_over.png';          
preload_b_7.src  = 'http://cdn.athleon.com/home/v7/images/index/search_go_over.png';      
preload_b_8.src  = 'http://cdn.athleon.com/home/v8/images/index/btn_coaches_over.png';        
preload_b_9.src  = 'http://cdn.athleon.com/home/v8/images/index/btn_players_over.png';        
preload_b_10.src = 'http://cdn.athleon.com/home/v7/images/index/button_signup_over.png';
preload_b_11.src = 'http://cdn.athleon.com/home/v7/images/index/button_learn_over.png';
preload_b_12.src = 'http://cdn.athleon.com/home/v8/images/index/btn_video_over.png';

//global vars
var cur_feature      = 0;
var previous_feature = 0;
var buttons_active   = true;

//functions
function use_search() {
	if ($('searchbox').value == 'Search') {
		$('searchbox').value = '';
	}
} //end function

function sessionID() {
	var cookie = document.cookie;
	var cookieList = cookie.split("; ");
	
	for(var i = 0; i < cookieList.length; i++) {
		if (cookieList[i].indexOf("log=") > -1) {
			return cookieList[i].substr(4);
		}
	}
	
	return null;
} //end function

function product_back() {
	if (buttons_active) {
		buttons_active = false;

		var previous_feature = cur_feature;
		if (cur_feature == 0) {cur_feature = 8;}
		cur_feature--;
	
		//move the arrow
		new Effect.Move('current_feature_arrow', {duration:0.3, x: ((cur_feature - previous_feature) * 109), mode: 'relative' });

		//update the highlight
		$('feature_img_'+ previous_feature).src = 'http://cdn.athleon.com/home/v7/images/index/feature_selector.png';
		$('feature_img_'+ cur_feature).src = 'http://cdn.athleon.com/home/v7/images/index/feature_selector_over.png';

		//change selected item
		product_left();
		record_click(100);
	}
} //end function

function product_next() {
	if (buttons_active) {
		buttons_active = false;

		var previous_feature = cur_feature;
		cur_feature++;
		if (cur_feature == 8) {cur_feature = 0};

		//move the arrow
		new Effect.Move('current_feature_arrow', {duration:0.3, x: ((cur_feature - previous_feature) * 109), mode: 'relative' });

		//update the highlight
		$('feature_img_'+ previous_feature).src = 'http://cdn.athleon.com/home/v7/images/index/feature_selector.png';
		$('feature_img_'+ cur_feature).src = 'http://cdn.athleon.com/home/v7/images/index/feature_selector_over.png';

		//change selected item
		product_left();
		record_click(101);
	}
} //end function

function show_product(leftright) {
	switch(cur_feature) {
		case 0: 
			$('current_feature_title').src = 'http://cdn.athleon.com/home/v7/images/index/text/playbooks.png';
			$('current_feature').src = 'http://cdn.athleon.com/home/v7/images/index/screens/playbooks.jpg';
			$('current_feature_text').innerHTML = "<div style='padding-bottom:15px'>Athletes are visual learners, and using the Athleon playbook creator will help you teach your players like never before.</div><div>Leave all the paper, binders, and photocopies at home.</div>";
			break;
		case 1:
			$('current_feature_title').src = 'http://cdn.athleon.com/home/v7/images/index/text/alerts.png';
			$('current_feature').src = 'http://cdn.athleon.com/home/v7/images/index/screens/event.jpg';
			$('current_feature_text').innerHTML = "<div style='padding-bottom:15px'>No more last minute e-mails asking about game day specifics.  Your Athleon hub has a centralized calendar with automatic nightly reminders.</div><div>Get all players and parents on the same page.</div>";
			break;
		case 2: 
			$('current_feature_title').src = 'http://cdn.athleon.com/home/v7/images/index/text/stats.png';
			$('current_feature').src = 'http://cdn.athleon.com/home/v7/images/index/screens/stats_tracking.jpg';
			$('current_feature_text').innerHTML = "<div style='padding-bottom:15px'>A wealth of information is hidden in your stats books.  Let our system do all the hard work for you, with on-line tools such as game summaries, player reports, and leaderboards.</div><div>Forget about penciled-in score sheets.</div>";
			break;
		case 3:
			$('current_feature_title').src = 'http://cdn.athleon.com/home/v7/images/index/text/text.png';
			$('current_feature').src = 'http://cdn.athleon.com/home/v7/images/index/screens/text_messaging.jpg';
			$('current_feature_text').innerHTML = "<div style='padding-bottom:15px'>The cell phone is the default communication method for today's young athletes.    Reach your players more effectively with point and click text messaging.</div><div>Ready for instant communication?</div>";
			break;
		case 4:
			$('current_feature_title').src = 'http://cdn.athleon.com/home/v7/images/index/text/film.png';
			$('current_feature').src = 'http://cdn.athleon.com/home/v7/images/index/screens/gamefilm.jpg';
			$('current_feature_text').innerHTML = "<div style='padding-bottom:15px'>Game film is only an effective teaching aid if players can watch it.  Now they can watch, anywhere and anytime.</div><div>No longer waste time or money burning DVDs.</div>";
			break;
		case 5:
			$('current_feature_title').src = 'http://cdn.athleon.com/home/v7/images/index/text/photo.png';
			$('current_feature').src = 'http://cdn.athleon.com/home/v7/images/index/screens/photo_albums.png';
			$('current_feature_text').innerHTML = "<div style='padding-bottom:15px'>20 parents, 20 different cameras, and no way to share photos after the game?  Not anymore.</div><div>Forget about emailing photos back and forth.</div>";
			break;
		case 6:
			$('current_feature_title').src = 'http://cdn.athleon.com/home/v7/images/index/text/practice.png';
			$('current_feature').src = 'http://cdn.athleon.com/home/v7/images/index/screens/practice_plans.jpg';
			$('current_feature_text').innerHTML = "<div style='padding-bottom:15px'>Practice time is precious, and a structured plan shared with your coaching staff is the first step to getting the most from each practice.</div><div>Get all your coaches on the same page today.</div>";
			break;
		case 7:
			$('current_feature_title').src = 'http://cdn.athleon.com/home/v7/images/index/text/workouts.png';
			$('current_feature').src = 'http://cdn.athleon.com/home/v7/images/index/screens/workout_tracking.jpg';
			$('current_feature_text').innerHTML = "<div style='padding-bottom:15px'>Weightlifting and conditioning programs only work when players put the time in at the gym.  Now their progress can be tracked on Athleon.</div><div>the season starts in the weight room.</div>";
			break;
	}

	//move it
	new Effect.Move('current_feature', {duration: 0, x: leftright * 330, y: 0, mode: 'relative'});

	//display the new product
	new Effect.Appear('current_feature_line', {duration:0.2});
	new Effect.Appear('current_feature_title', {duration:0.2});
	new Effect.Appear('current_feature', {duration:0.2});
	new Effect.Appear('current_feature_buttons', {duration: 0.2});
	new Effect.Appear('current_feature_text', {duration:0.3, afterFinish: function() {buttons_active = true}});
} //end function

function product_left() {
	//move-fade right
	new Effect.Fade('current_feature', {duration: 0.3});
	new Effect.Move('current_feature', {duration: 0.4, x: 330, y: 0, mode: 'relative', afterFinish: function() {show_product(-1)}});

	//hide the text
	new Effect.Fade('current_feature_title', {duration: 0.3});
	new Effect.Fade('current_feature_line', {duration: 0.3});
	new Effect.Fade('current_feature_text', {duration: 0.3});
	new Effect.Fade('current_feature_buttons', {duration: 0.3});
} //end function

function product_right() {
	//move-fade left
	new Effect.Fade('current_feature', {duration: 0.3});
	new Effect.Move('current_feature', {duration: 0.4, x: -330, y: 0, mode: 'relative', afterFinish: function() {show_product(1)}});

	//hide the text
	new Effect.Fade('current_feature_title', {duration: 0.3});
	new Effect.Fade('current_feature_line', {duration: 0.3});
	new Effect.Fade('current_feature_text', {duration: 0.3});
	new Effect.Fade('current_feature_buttons', {duration: 0.3});
} //end function

function go_feature(feature_number) {
	if (buttons_active) {
		buttons_active = false;
		var previous_feature = cur_feature;
		cur_feature = feature_number;

		//move the arrow
		new Effect.Move('current_feature_arrow', {duration:0.3, x: ((cur_feature - previous_feature) * 109), mode: 'relative' });

		//update the highlight
		$('feature_img_'+ previous_feature).src = 'http://cdn.athleon.com/home/v7/images/index/feature_selector.png';
		$('feature_img_'+ cur_feature).src = 'http://cdn.athleon.com/home/v7/images/index/feature_selector_over.png';

		//change selected item
		if (cur_feature > previous_feature) {
			product_right();
		} else if (cur_feature < previous_feature) {
			product_left();
		} else {
			buttons_active = true;
		}
		
		record_click(feature_number);
	}
} //end function

function record_click(id) { //log the clicks, no action on success or fail
	new Ajax.Request('/cgi-bin/homepage_feature_log.cgi', { method:'POST', parameters: {feature_id: id} } );
} //end function

function feature_link() {
	switch(cur_feature) {
		case 0: window.location = '/features/playbooks'; break;
		case 1: window.location = '/features/eventalerts'; break;
		case 2: window.location = '/features/stats'; break;
		case 3: window.location = '/features/text'; break;
		case 4: window.location = '/features/gamefilm'; break;
		case 5: window.location = '/features/photos'; break;
		case 6: window.location = '/features/practiceplans'; break;
		case 7: window.location = '/features/workouts'; break;
	}
} //end function

function show_video() {
	Lightbox.showBoxByID( $('video_container') , 550, 485);
}

function hide_video() {
	Lightbox.hideBox();
}