var is_slideshow = true;
var slideshow_interval = 5000;
var animate_speed = 1000;

var start_pos = 27;
var option_height = 84;
var bubble_spot = 27;
var current_spot = 1;

var bubble_elem = '#option-holder #right #bubble';
var content_shown = '';

var interval_id = 0;
var post_run = false;

function show_red(){
	$(bubble_elem).css('background', 'url(images/bubble-red.png) top left no-repeat');
}

function show_content(num){
	var clicked_elem = $('#cont-' + num);
	if(content_shown != clicked_elem){
		$('#content li').fadeOut("slow");
		clicked_elem.fadeIn();
		content_shown = clicked_elem;
	}
}

function move_bubble(num){
	$(bubble_elem).fadeIn();
	if(num == 1){
		var new_spot = start_pos;
		$(bubble_elem).animate({top: new_spot}, animate_speed);
		bubble_spot = new_spot;
	}
	else{
		var new_spot = start_pos + (--num * option_height);
		$(bubble_elem).animate({top: new_spot}, animate_speed);
		bubble_spot = new_spot;
	}
	
}

function go_to(num){
	move_bubble(num);
	show_content(num);
	
	$('#option-holder #right ul li span').css(
		'color', 'black'
	);
	$('.special span').css('color', 'white');
	$('#opt-' + num + ' span').css(
		'color', 'white'
	);
	
	if(num == 5){
		current_spot = 1;
		show_red();
		setTimeout( "$('#feature').hide()", animate_speed);
	}
	else{
		current_spot == num;
		$(bubble_elem).css('background', 'url(images/bubble-blue.png) top left no-repeat');
		$('#feature').show();
	}
}

function posted(){
	post_run = true;
}

$(document).ready(function(){
	if( post_run ){
		$('#demoInfo_win').show();
		$('#signup-form').hide();
		go_to(5);
	} else{
		//let's kick this thing off right
		go_to(current_spot);
		current_spot++;
		
		//do the actual moving
		interval_id = setInterval("go_to(current_spot++)", slideshow_interval);
	}
	
	//clickidy-clack
	$('#option-holder #right ul li').click(function(){
		is_slideshow = false;
		clearInterval(interval_id);
		
		var id = $(this).attr("id");		
		id = (id.substring(4, id.length) ) * 1;
		
		go_to(id);
	});
	
	$('#signup-form').validate();
	$('#submit-button').click(function(){
		$('#signup-form').validate();
	});
});
