/**
 * Plegamatic web source code
 * Copyright (C) 2011 by:
 * Jaume Bellet <mauge@bixo.org>
 * Urgell Maquinaria Agricola SA -Plegamatic-
 *
*/
  
var images = new Array ();
var index=0;
var timer_id;
var timer_start;
var transition = 15;


inits[inits.length] = function ()
{
	$('#flier').find('img').each (function (){ 
		
		images[images.length] = this;
		$(this).css ('z-index',index);
		index++;
	});
	index = index - 1;
	
	timer_start = setTimeout("flier_start()", 20);
};



function flier_start ()
{
	$('#flier img').removeClass ('hidden');

	/*start timer*/
	timer_id = setTimeout("fTimer()", transition)
}

var c =0;
function fTimer() 
{
	act = images[index];
	if (c==200)
	{
		$(act).fadeOut (2000, function () {
			index--;
			
			$('#flier').find('img').each (function ()
			{ 
				z = Number($(this).css ('z-index')) +1;
				$(this).css ('z-index',z);
			});
	
			z = Number($(this).css ('z-index')) - images.length;
			$(this).css ('z-index',z);
			$(this).fadeTo ("0","1");
			if (index <0) index=images.length-1;
			c =0;
		});
	}
	
	timer_id = setTimeout("fTimer()", transition);
	c++;
}







