var slideshowNextUrl = null;
var slideshowDelay = null;
var slideshowState = false;

function slideshowInit( state, nextUrl, delay )
{
	slideshowState = state;
	slideshowNextUrl = nextUrl;
	slideshowDelay = delay;
	
	if( slideshowState )
	{
		window.setTimeout( "slideshowShowNext()", slideshowDelay * 1000 );
	}
}

function slideshowToggleState()
{
	slideshowState = !slideshowState;

	if( slideshowState ) slideshowStart(); else slideshowStop();
}

function slideshowSetLabelString( string )
{
	if( document.getElementById )
	{
		if( node = document.getElementById( "ToggleSlideshowState" ) )
		{
			node.replaceChild( document.createTextNode( string ), node.firstChild );
		}
	}
}

function slideshowStart()
{
	slideshowState = true;
	
	var expires = new Date();
	
	expires.setYear( expires.getFullYear() + 1 );

	setCookie( "SlideshowState", "1", expires, false, false, false ); 
	
	slideshowSetLabelString( "Stop diasshow" );
	
	slideshowShowNext();
}

function slideshowStop()
{
	var expires = new Date();
	
	expires.setYear( expires.getFullYear() + 1 );

	setCookie( "SlideshowState", "0", expires, false, false, false ); 

	slideshowSetLabelString( "Start diasshow" );

	slideshowState = false;
}

function slideshowShowNext()
{
	if( slideshowState ) document.location.href = slideshowNextUrl;
}

function setCookie(name, value, expires, path, domain, secure) { 
 var curCookie = name + "=" + escape(value) + 
	((expires) ? "; expires=" + expires.toGMTString() : "") + 
	((path) ? "; path=" + path : "") + 
	((domain) ? "; domain=" + domain : "") + 
	((secure) ? "; secure" : "");
		
	document.cookie = curCookie; 
}
