
jQuery(document).ready(function()
{
	step = 0;
	prev_step = diapo_uid.length - 1;
	next_step = 1;
	is_playing = true;
	transition_time = 8 * 1000; /* in milliseconds */
	effect_time = 1 * 1000; /* in milliseconds */
	my_start_thread = "";
	jQuery(".image_dropzone_hidden").addClass("hide");
	
	load_image = function(tab, my_step)
	{
		var text_zone = jQuery("#text_zone");
		text_zone.addClass("hide");
		var text_zone_h3 = text_zone.children('h3:first');
		text_zone_h3.children('span:first').text(tab.title.toString());
		text_zone_h3.children('a:first').text(tab.subtitle.toString());
		text_zone_h3.children('a:first').attr('href', tab.linkpage);
		text_zone.children('p:first').text(tab.date_text.toString());
		var img_zone = jQuery('#image_zone img:first');
		img_zone.parent().attr('href', tab.linkpage);
		img_zone.parent().attr('title', tab.title.toString()+', '+tab.subtitle.toString());
		clean_vignette_over();
		jQuery('#img_'+diapo_uid[my_step]).attr('src', vignette_over);
		jQuery('#img_'+diapo_uid[my_step]).parent().addClass("on");
		img_zone.attr('src', tab.image.toString()).css('display', 'none').fadeIn(effect_time, function(){text_zone.removeClass("hide")});
		if (my_step == 0)
		{
			prev_step = diapo_uid.length - 1;
		}
		else
		{
			prev_step = my_step - 1;
		}
		step = my_step;
		if (my_step >= (diapo_uid.length - 1))
		{
			next_step = 0;
		}
		else
		{
			next_step = my_step + 1;
		}
		
		player_set_next_text(list_images[diapo_uid[next_step]]);
		player_set_prev_text(list_images[diapo_uid[prev_step]]);
	}
	
	clean_vignette_over = function()
	{
		for (uid in diapo_uid)
		{
			jQuery('#img_'+diapo_uid[uid].toString()).attr('src', list_images[diapo_uid[uid].toString()]['image']);
			jQuery('div.nav_affiche ul li').removeClass("on");
		}
	}
	
	start_diapo = function()
	{
		load_image(list_images[diapo_uid[step]], step);
		step++;
		if (step >= diapo_uid.length) step = 0;
		my_start_thread = setTimeout("start_diapo()", transition_time);
	}
	
	player_play = function()
	{ 
		if (!is_playing)
		{
			player_set_pause(diapo_uid[step]);
			start_diapo();
			is_playing = true;
		}
	}
	
	player_pause = function()
	{
		if (is_playing)
		{
			player_set_play(diapo_uid[step]);
			clearTimeout(my_start_thread);
			is_playing = false;
		}
	}
	
	player_prev = function()
	{
		if (is_playing) player_pause();
		clean_vignette_over();
		player_show(prev_step);
	}
	
	player_next = function()
	{
		if (is_playing) player_pause();
		clean_vignette_over();
		player_show(next_step);
	}
	
	player_playpause = function()
	{
		if (is_playing)
		{
			player_pause();
			player_set_play();
		}
		else
		{
			player_play();
			player_set_pause();
		}
	}
	
	player_set_play = function()
	{
		var elt = jQuery('#player_img_playpause');
		elt.attr('src', data_player_img_play);
		elt.attr('alt', data_player_text_play);
		elt.attr('title', data_player_text_play);
		elt = jQuery('#player_link_playpause');
		elt.attr('alt', data_player_text_play);
		elt.attr('title', data_player_text_play);
	}
	
	player_set_pause = function()
	{
		var elt = jQuery('#player_img_playpause');
		elt.attr('src', data_player_img_pause);
		elt.attr('alt', data_player_text_pause);
		elt.attr('title', data_player_text_pause);
		elt = jQuery('#player_link_playpause');
		elt.attr('alt', data_player_text_pause);
		elt.attr('title', data_player_text_pause);
	}
	
	player_show = function(my_step)
	{
		if (is_playing) player_set_pause();
		load_image(list_images[diapo_uid[my_step]], my_step);
	}
	
	player_set_next_text = function (tab)
	{
                var elt = jQuery('#player_link_next img');
                elt.attr('alt', data_player_text_next + ', ' + tab.subtitle);
                elt.attr('title', data_player_text_next + ', ' + tab.subtitle);
        }
        
        player_set_prev_text = function (tab)
	{
                var elt = jQuery('#player_link_prev img');
                elt.attr('alt', data_player_text_prev + ', ' + tab.subtitle);
                elt.attr('title', data_player_text_prev + ', ' + tab.subtitle);
        }
	
	start_diapo();
});
