//global object
var ixf = { 'clock' : null, 'count' : 1 }

//crossfade setup function
function crossfade()
{
	//if the timer is not already going
	if(ixf.clock == null)
	{		
		
		//copy the image object 
		ixf.obj = arguments[0];
		
		ixf.mode = arguments[3];
		
		ixf.callback = arguments[4];
		
		//store the supported form of opacity
		if(typeof ixf.obj.style.opacity != 'undefined')
		{
			//alert('any kind of opacity is supported - w3c');
			ixf.type = 'w3c';
		}
		else if(typeof ixf.obj.style.MozOpacity != 'undefined')
		{
			ixf.type = 'moz';
		}
		else if(typeof ixf.obj.style.KhtmlOpacity != 'undefined')
		{
			ixf.type = 'khtml';
		}
		else if(typeof ixf.obj.filters == 'object')
		{
			//alert('any kind of opacity is supported - OBJECT');
			//weed out win/ie5.0 by testing the length of the filters collection (where filters is an object with no data)
			//then weed out mac/ie5 by testing first the existence of the alpha object (to prevent errors in win/ie5.0)
			//then the returned value type, which should be a number, but in mac/ie5 is an empty string
			ixf.type = (ixf.obj.filters.length > 0 && typeof ixf.obj.filters.alpha == 'object' && typeof ixf.obj.filters.alpha.opacity == 'number') ? 'ie' : 'none';
		}
		else
		{
			ixf.type = 'none';
		}
		
		//if any kind of opacity is supported
		if(ixf.type != 'none')
		{
			//calkowity czas trwania [ms]
			//copy and convert fade duration argument
			ixf.length = parseInt(arguments[2], 10) * 1000;

			//ilosc przejsc
			//create fade resolution argument as 20 steps per transition
			ixf.resolution = parseInt(arguments[2], 10) * 20;
			
			ixf.count =1 - (1 / ixf.resolution)
			
			//interwal = calkowity czas [ms] / ilosc krokow
			//start the timer
			ixf.clock = setInterval('ixf.crossfade()', ixf.length/ixf.resolution);
			
			luma_count = 0;
		}
	}
};


//crossfade timer function
ixf.crossfade = function()
{	
	++luma_count;
	//decrease the counter on a linear scale
	ixf.count -= (1 / ixf.resolution);
	
	if(ixf.count < 1 / ixf.resolution)
		ixf.count = 0;

	if(ixf.mode == 'fadeout')
	{
		ixf.obj.style.opacity = ixf.count;
	    ixf.obj.style.MozOpacity = ixf.count;
	    ixf.obj.style.KhtmlOpacity = ixf.count;
	    ixf.obj.style.filter = "alpha(opacity=" + (ixf.count * 100) + ")";
	}
	else
	{
		ixf.obj.style.opacity = 1-ixf.count;
	    ixf.obj.style.MozOpacity = 1-ixf.count;
	    ixf.obj.style.KhtmlOpacity = 1-ixf.count;
	    ixf.obj.style.filter = "alpha(opacity=" + ((1-ixf.count) * 100) + ")";	
	}
	
	
	//if the counter has reached the bottom
	if(ixf.count < (1 / ixf.resolution))
	{
		//clear the timer
		clearInterval(ixf.clock);
		ixf.clock = null;
		ixf.callback();
	}
};



