d 					= document;
FaderPreLoader		= new Image();   
FadeDir				= '';	// the directory of the data [default = dMS-folder]
debug				= 0;	// show debug info on the canvas
FadeShow			= 0;	// number of images shown on the canvas
FadeValue			= 0;	// initial percentage of the fade
FadeFirst			= 1;	// initialization of the slide-show
FadePaused			= 0;	// the time every image is shown, so far
FadePlay			= 1;	// do not pause the slide-show at default
Interval			= 500;	// interval for time-out settings
TextHide			= 0;	// first textblock to hide

function ShowControls(FadeID,CallerID)
	{
if(CallerID == 1) // when initializing
	{
if(d.getElementById(FadeID+'_controls'))d.getElementById(FadeID+'_controls').style.display 	= 'block';
if(d.getElementById(FadeID+'_start'))	d.getElementById(FadeID+'_start').style.display 	= 'none';	
	}
if(CallerID == 2) // at the end of a show
	{
FadeShow = 0;
if(d.getElementById(FadeID+'_controls'))d.getElementById(FadeID+'_controls').style.display 	= 'none';
if(d.getElementById(FadeID+'_start'))	d.getElementById(FadeID+'_start').style.display 	= 'block';
	}
	}

/////////////////////////////////////////////////////////////////////////////////////
//	CREATE A FADER-SLIDESHOW
/////////////////////////////////////////////////////////////////////////////////////

function dMSfader_initialize(FadeID,FadeExt,FadeNr,FadePause,FadeTime,FadeImages,FadeLoop,FadeType,FaderSlider,FadeWidth,FadeHeight,FadeSteps,FadeReplay)
	{
if((1*FadeNr)<10)FadeNr = '0'+(1*FadeNr);
if(FadeDir == '')FadeDir= "dms/xtra/fader/_data/"+FadeID+"/";
FaderPreLoader.src 		= FadeDir+FadeID+"_"+FadeNr+"."+FadeExt;   
FaderPreLoader.onload	= function(){dMSfader_preload(FadeID,FadeExt,FadeNr,FadePause,FadeTime,FadeImages,FadeLoop,FadeType,FaderSlider,FadeWidth,FadeHeight,FadeSteps,FadeReplay);}
if(FadeShow == FadeImages)ShowControls(FadeID,1);
if(FadeShow == 0)ShowControls(FadeID,1);
	}

/////////////////////////////////////////////////////////////////////////////////////
// show new image, prepare next one
/////////////////////////////////////////////////////////////////////////////////////

function dMSfader_preload(FadeID,FadeExt,FadeNr,FadePause,FadeTime,FadeImages,FadeLoop,FadeType,FaderSlider,FadeWidth,FadeHeight,FadeSteps,FadeReplay)
	{
if((1*FadeNr)<10)FadeNr = '0'+(1*FadeNr);
	
	if(debug)
		{
	d.title = 'next image : '+FadeNr+' ... time to wait : '+FadePause+' ... time elapsed : '+FadePaused;
	d.getElementById("debug").src = FaderPreLoader.src;
		}

// check to see if the new image can be launched
if(FadePaused<FadePause && !FadeFirst)								// still waiting...
	{
setTimeout("dMSfader_preload('"+FadeID+"','"+FadeExt+"','"+FadeNr+"',"+FadePause+","+FadeTime+","+FadeImages+","+FadeLoop+","+FadeType+","+FaderSlider+","+FadeWidth+","+FadeHeight+","+FadeSteps+","+FadeReplay+")",Interval);
if(FadePlay)FadePaused+=Interval;									// expand the time already paused
	}
else																// ready2go...
	{
if(FaderSlider == 1)dMSfader_fade (FadeID,FadeNr,FadeExt,FadeTime,FadeType,FadeImages,FadeReplay);									// show the fader-effect
if(FaderSlider == 2)dMSfader_slide(FadeID,FadeNr,FadeExt,FadeTime,FadeType,FadeImages,FadeWidth,FadeHeight,FadeSteps,FadeReplay);	// show the slider-effect
if(d.getElementById(FadeID+'_text_00'))ShowTXT(FadeID,FadeNr);																		// show the text
if(FadeFirst)ShowControls(FadeID,1)																									// show the controls

	FadeFirst 	= 0;												// reset initialize-status of the slide-show
	FadePaused 	= 0;												// reset pause-status [show the image]
	FadeNr		= (1*FadeNr)+1; 									// the next image to be shown
	FadeShow   += 1;												// images already shown in the slideshow

if(FadeLoop && FadeShow == FadeImages)								// reset images already shown when loop is active
{FadeShow = 0;FadeNr = 1;}

if(FadeShow != FadeImages)dMSfader_initialize(FadeID,FadeExt,FadeNr,FadePause,FadeTime,FadeImages,FadeLoop,FadeType,FaderSlider,FadeWidth,FadeHeight,FadeSteps,FadeReplay)
else{if(!FadeLoop && FadeReplay)ShowControls(FadeID,2);if(debug)d.title = 'done...';}
	}
	}

/////////////////////////////////////////////////////////////////////////////////////
// show the new image, faded-in	
/////////////////////////////////////////////////////////////////////////////////////

function dMSfader_fade(FadeID,FadeNr,FadeExt,FadeTime,FadeType,FadeImages,FadeReplay)
	{
if(FadeValue == 0){d.getElementById(FadeID+'_fader').style.backgroundImage = 'url("'+FaderPreLoader.src+'")';FaderBack = FaderPreLoader.src;}

// ie-browser(s)
if(d.body.filters)d.getElementById(FadeID+'_fader').style.filter  = 'alpha(opacity='+(FadeValue*10/2)+');';
// non-ie-browsers
else			 {d.getElementById(FadeID+'_fader').style.opacity = FadeValue/10/2;}

FadeValue += 1;
if(FadeValue<21)  setTimeout("dMSfader_fade('"+FadeID+"','"+FadeNr+"','"+FadeExt+"',"+FadeTime+","+FadeType+","+FadeImages+","+FadeReplay+")",FadeTime);
if(FadeValue==21){FadeValue = 0;if(FadeType == 2)d.getElementById(FadeID+'_container').style.backgroundImage = 'url("'+FaderBack+'")';}
	}

/////////////////////////////////////////////////////////////////////////////////////
// show the new image, slided-in	
/////////////////////////////////////////////////////////////////////////////////////

function dMSfader_slide(FadeID,FadeNr,FadeExt,FadeTime,FadeType,FadeImages,FadeWidth,FadeHeight,FadeSteps,FadeReplay)
	{

if(FadeValue == 0)
	{
d.getElementById(FadeID+'_fader').style.backgroundImage 	= 'url("'+FaderPreLoader.src+'")';FaderBack = FaderPreLoader.src;
/* 0 : color slide 	 */	if(FadeType == 0)NewPosition 		= '-'+FadeWidth+'px 0';
/* 1 : top to bottom */	if(FadeType == 1)NewPosition 		= '0 '+FadeWidth+'px';
/* 2 : right to left */	if(FadeType == 2)NewPosition 		= FadeWidth+'px 0';
/* 3 : bottom to top */	if(FadeType == 3)NewPosition 		= '0 '+'-'+FadeWidth+'px';
/* 4 : left to right */	if(FadeType == 4)NewPosition 		= '-'+FadeWidth+'px 0';
	}
else
	{
/* 0 : color slide 	 */ if(FadeType == 0)NewPosition 		= (FadeValue-FadeWidth)+'px 0';
/* 1 : top to bottom */	if(FadeType == 1)NewPosition 		= '0 '+(FadeValue-FadeWidth)+'px';
/* 2 : right to left */	if(FadeType == 2)NewPosition 		= (FadeWidth-FadeValue)+'px 0';
/* 3 : bottom to top */	if(FadeType == 3)NewPosition 		= '0 '+(FadeWidth-FadeValue)+'px';
/* 4 : left to right */ if(FadeType == 4)NewPosition 		= (FadeValue-FadeWidth)+'px 0';	
	}

d.getElementById(FadeID+'_fader').style.backgroundPosition = NewPosition;
FadeValue += FadeSteps;
if(FadeValue<(FadeWidth+FadeSteps))  setTimeout("dMSfader_slide('"+FadeID+"','"+FadeNr+"','"+FadeExt+"',"+FadeTime+","+FadeType+","+FadeImages+","+FadeWidth+","+FadeHeight+","+FadeSteps+","+FadeReplay+")",FadeTime);
if(FadeValue==(FadeWidth)+FadeSteps){FadeValue = 0;if(FadeType!=0)d.getElementById(FadeID+'_container').style.backgroundImage = 'url("'+FaderBack+'")';}
	}
	
/////////////////////////////////////////////////////////////////////////////////////
//	SHOW | HIDE TEXT BELOW THE SLIDES...
/////////////////////////////////////////////////////////////////////////////////////

function ShowTXT(TextID,TextShow)
	{
if((1*TextHide)<10)TextHide = '0'+(1*TextHide);
if(d.getElementById(TextID+'_text_'+TextHide))d.getElementById(TextID+'_text_'+TextHide).style.display = 'none';
if(d.getElementById(TextID+'_text_'+TextShow))d.getElementById(TextID+'_text_'+TextShow).style.display = 'block';
TextHide = TextShow;
	}
	
/////////////////////////////////////////////////////////////////////////////////////
//	PLAY | PAUSE THE SLIDE-SHOW
/////////////////////////////////////////////////////////////////////////////////////

function PlayPause(ControlID,CallerID,ControlWidth,ControlHeight)
	{

if(CallerID == 1){													// click-action
if(FadePlay == 1)													// switch to pause-status
	{
FadePlay = 0;
d.getElementById(ControlID+'_controls').style.backgroundPosition = '-'+ControlWidth+'px 0';
	}
else																// switch to play-status
	{
FadePlay = 1;
d.getElementById(ControlID+'_controls').style.backgroundPosition = '0 0';
	}}
	
/////////////////////////////////////////////////////////////////////////////////////\

if(CallerID == 2){													// mouse-over-action
if(FadePlay == 1)ControlsCoords = '0 -'+ControlHeight+'px';			// when playing
else{ControlsCoords = '-'+ControlWidth+'px -'+ControlHeight+'px';}}	// when pausing


/////////////////////////////////////////////////////////////////////////////////////	

if(CallerID == 3){													// mouse-out-action
if(FadePlay == 1)ControlsCoords = '0 0';							// when playing
else{ControlsCoords = '-'+ControlWidth+'px 0';}}					// when pausing

if(CallerID!=1)d.getElementById(ControlID+'_controls').style.backgroundPosition = ControlsCoords;

	}
