
var background_color = null;
var slideshow_lnk = null;
var slideshow_mode = null;

function reset_color()
{
	set_color(background_color);
}
function try_color(color)
{
	document.body.style.backgroundColor = color;
}
function set_color(color)
{
	background_color = color;
	mss_set_cookie("background_color",color);
	try_color(background_color);

	var div = document.getElementById("background_colors");
	if (div != null)
	{
		var elems = div.children;
		for (var i = 0; i < elems.length; i++)
		{
			elems[i].className = "";
			if (toRGB(elems[i].style.backgroundColor) == toRGB(color))
			{
				elems[i].className = "sel";
			}
		}
	}
}
function toRGB(color)
{
	if (color.indexOf("#") != -1)
	{
		var rgbR = parseInt(color.substring(1,3),16);
		var rgbG = parseInt(color.substring(3,5),16);
		var	rgbB = parseInt(color.substring(5,7),16);
		var	rgb = "rgb(" + rgbR + "," + rgbB + "," + rgbG + ")";
	}
	else
	{
		var rgb = color.replace(/\s/g,"");
	}
	return rgb;
}


function slideshow_run()
{
	document.getElementById("slideshow_off").style.display = "none";
	document.getElementById("slideshow_on").style.display = "block";

	var i = null;
	if (document.getElementById("slideshow_interval"))
	{
		i = document.getElementById("slideshow_interval").value;
	}
	if (!i)
	{
		i = mss_get_cookie("slideshow_interval");
	}
	i = parseInt(i);

	if (!(i > 0))
		i = 5;

	slideshow_lnk = window.setTimeout("slideshow_switch()",i*1000);

	slideshow_mode = 1;
	document.getElementById("slideshow_interval").value = i;
}
function slideshow_stop()
{	
	document.getElementById("slideshow_off").style.display = "block";
	document.getElementById("slideshow_on").style.display = "none";
	window.clearTimeout(slideshow_lnk);
	slideshow_mode = 0;
}
function slideshow_initialize()
{
	if (slideshow_mode == 1)
	{
		slideshow_run();
	}
	else if (slideshow_mode == 0)
	{
		slideshow_stop();
	}
	else if (window.location.toString().indexOf("slph") != -1 || window.location.toString().indexOf("slideshow") != -1)
	{
		slideshow_run();
	}
	else
	{
		slideshow_stop();
	}
}
function slideshow_set_interval()
{
	mss_set_cookie("slideshow_interval",document.getElementById("slideshow_interval").value);
}
function slideshow_switch()
{
	link = document.getElementById("next_photo_link");
	if (link == null)
	{
		link = document.getElementById("first_photo_link");
	}
	if (link != null)
	{
		fireEvent(link,"click");
	}
}
function fireEvent(obj,evt)
{
	var fireOnThis = obj;
	if (document.createEvent)
	{
		var evObj = document.createEvent("MouseEvents");
		evObj.initEvent(evt,true,false);
		fireOnThis.dispatchEvent(evObj);
	}
	else if (document.createEventObject)
	{
		fireOnThis.fireEvent("on"+evt);
	}
}


function single_photo_initialize()
{
	background_color = mss_get_cookie("background_color");	
	reset_color();
	slideshow_initialize();
}

