var deskWO = document.getElementById('deskWO');
var deskW  = document.getElementById('deskW');
var type = 'none';
var length = 1000;
var resolution = 20;
var modeShow = false;
var timer = null;
var pos = 0;


//store the supported form of opacity
if (typeof deskW.style.opacity != 'undefined')
{
	type = 'w3c';
}
else if (typeof deskW.style.MozOpacity != 'undefined')
{
	type = 'moz';
}
else if (typeof deskW.style.KhtmlOpacity != 'undefined')
{
	type = 'khtml';
}
else if (typeof deskW.filters == 'object' && 
		 deskW.filters.length > 0 && 
		 typeof deskW.filters.alpha == 'object' && 
		 typeof deskW.filters.alpha.opacity == 'number')
{
	type = 'ie';
}




function showHide()
{
	modeShow = ~modeShow;
	softShowHide();
}


function hardShowHide()
{
	if (modeShow)
	{
		deskW.style.visibility = 'visible';
		deskWO.style.visibility = 'hidden';
	}
	else
	{
		deskWO.style.visibility = 'visible';
		deskW.style.visibility = 'hidden';
	}
}


function softShowHide()
{
	if (type != 'none')
	{
		
		if (timer == null)
		{
			crossfade();
			timer = setInterval('crossfade()', length / resolution);
		}
	}
	else
		hardShowHide();
}




//crossfade timer function
crossfade = function()
{
	pos += modeShow ? 1 : -1;

	var opacity  = pos / resolution;
	
	//set new opacity value on both elements
	//using whatever method is supported
	switch(type)
	{
		case 'ie' :
			deskW.filters.alpha.opacity = opacity * 100;
			//ixf.newimg.filters.alpha.opacity = (1 - ixf.count) * 100;
			break;
			
		case 'khtml' :
			deskW.style.KhtmlOpacity = opacity;
			//ixf.newimg.style.KhtmlOpacity = (1 - ixf.count);
			break;
			
		case 'moz' : 
			//restrict max opacity to prevent a visual popping effect in firefox
			deskW.style.MozOpacity = (opacity == 1 ? 0.9999999 : opacity);
			//ixf.newimg.style.MozOpacity = (1 - ixf.count);
			break;
			
		default : 
			//restrict max opacity to prevent a visual popping effect in firefox
			deskW.style.opacity = (opacity == 1 ? 0.9999999 : opacity);
			//ixf.newimg.style.opacity = (1 - ixf.count);
	}
	
	//now that we've gone through one fade iteration 
	//we can show the image that's fading in
	deskWO.style.visibility = 'visible';
	deskW.style.visibility = 'visible';

	//if the counter has reached the bottom
	if (pos == 0 || pos == resolution)
	{
		//clear the timer
		clearInterval(timer);
		timer = null;

		hardShowHide();
	}
}