(function($) {


	/**********************************************************/
	var showDiaporama = function(){

		var elements_length = $("#head_slideshow_nav a").length;
		var current_el = init_slide;
		$(window).everyTime(4000, "showDiaporama", function() {

			current_el = current_el + 1;
			if( current_el >= elements_length ){
				current_el = 0;
			}

		    $("#head_slideshow_nav a:eq(" + current_el + ")").trigger('click', true);

		});

	};

	var hideDiaporama = function(){
		$(window).stopTime("showDiaporama");
	};
	/**********************************************************/


	/**********************************************************/
	var img_loading = false;
	var block_show = 'head_slideshow_block' + ( init_slide + 1 ) ;
	$("#head_slideshow_nav a").click(function( event, eventTrigger ){

		if( typeof(eventTrigger) == 'undefined' || eventTrigger != true ){
			hideDiaporama();
		}

		var block_link = $(this).attr('rel');

		if( img_loading == true || block_link == block_show ){
			return false;
		}

		img_loading = true;

		$("#head_slideshow_nav a.on").removeClass('on');
		$(this).addClass('on');

		$("#head_slideshow_mask").fadeIn(500, function(){
			$("#" + block_show).hide();
			block_show = block_link;
			$("#" + block_link).show();
			$(this).oneTime(50, "showDiaporama_home", function() {
				$("#head_slideshow_mask").fadeOut(500, function(){
					img_loading = false;
				});
			});
		});


		$(this).trigger('blur');

		return false;
	});
	/**********************************************************/

	/**********************************************************/
	$( window ).load(function () {

		$(this).oneTime(400, "showDiaporama_home", function() {
			showDiaporama();
		});

	});
	/**********************************************************/

})(jQuery);


