// $Id$

var Selection_cookiearray = 0;
var Selection_enabled = 0;
var Selection_disabled = 0;

function Selection_init(itemId, enabled, disabled)
{
	Selection_enabled = new Image
	Selection_disabled = new Image

	Selection_enabled.src = enabled
	Selection_disabled.src = disabled

	var cookiename = getCookie('selection')

	if(cookiename)
		Selection_cookiearray = cookiename.split('.')
	else
		Selection_cookiearray = new Array(0);

	i = Selection_cookiearray.indexOf("I"+itemId)

	anElement = document.getElementById("I"+itemId)

	if(i == -1)
		anElement.src = Selection_disabled.src
	else
		anElement.src = Selection_enabled.src
}

function Selections_init(enabled, disabled)
{
	Selection_enabled = new Image
	Selection_disabled = new Image

	Selection_enabled.src = enabled
	Selection_disabled.src = disabled

	var cookiename = getCookie('selection')

	if(cookiename)
		Selection_cookiearray = cookiename.split('.')
	else
		Selection_cookiearray = new Array(0);

	var ticks = document.getElementsByName('TICK');

	for(var idx = 0; idx < ticks.length; idx++)
	{
		itemId = ticks[idx].id

		i = Selection_cookiearray.indexOf(itemId)

		if(i == -1)
			ticks[idx].src = Selection_disabled.src
		else
			ticks[idx].src = Selection_enabled.src
	}
}

function Selection(me)
{
	var itemId = me.id
	var i = Selection_cookiearray.indexOf(itemId)

	if(i == -1)
	{
		Selection_cookiearray[Selection_cookiearray.length] = itemId;
		me.src = Selection_enabled.src
	}
	else
	{
		Selection_cookiearray.remove(i)
		me.src = Selection_disabled.src
	}

	var cookiestring = Selection_cookiearray.join('.')

	document.cookie = 'selection=' + escape(cookiestring)
}

function SelectionClear()
{
	var ticks = document.getElementsByName('TICK');

	for(var idx = 0; idx < ticks.length; idx++)
	{
		ticks[idx].src = Selection_disabled.src
	}

	Selection_cookiearray = new Array(0);

	document.cookie = 'selection=';

	location.href = 'index.php?a=selections&s=gallery';
}

