var current_slideshow_location = -1;

start_slideshow();
add_onclicks_to_embeds();

function change_main(new_id) {
	jQuery(".front_feature_main_div").css('display', 'none');
	jQuery("#feature_" + new_id).css('display', '')
	
	jQuery("li.story").attr('class', 'story');
	jQuery("#feature_summary_" + new_id).attr('class', 'story highlight')
	
	current_slideshow_location = new_id
}

function next_slide() {
	current_slideshow_location = current_slideshow_location + 1;
	if(current_slideshow_location > (jQuery("li.story").length - 1)){
		current_slideshow_location = 0;
		stop_slideshow();
	}
	jQuery("#prog_image").attr("src", "/images/layout/carousel-progress-bar.gif?" + Math.floor(Math.random()*11000000));
	change_main(current_slideshow_location);
}


function auto_change(local_keep_changing_key){
	if(keep_changing == true && local_keep_changing_key == keep_changing_key){
		next_slide();
		setTimeout("auto_change(" + local_keep_changing_key + ")",10000);
	}
}


function toggle_slideshow(){
	if(keep_changing == true) {
		stop_slideshow();
	} else {
		start_slideshow();
	}
}

function stop_slideshow(){
	keep_changing = false;
	jQuery("#controls").attr("class", 'pause')
}

function start_slideshow(){
	keep_changing = true;
	keep_changing_key = Math.floor(Math.random()*1100);
	jQuery("#controls").attr("class", 'play')
	auto_change(keep_changing_key);
}

function add_onclicks_to_embeds(){
	jQuery("#Player").attr('onclick', 'stop_slideshow()')
}