var imagePages = new Array
(
	"tigerbrand",
		"tigerbrand_detalj1",
	"seasick_sailors_shore",
	"langs_floden_1",
	"langs_floden_2",
	"langs_floden_3",
	"langs_floden_4",
	"langs_floden_5",
	"vedbarerskans_hus",
	"koja_1",
	"grans_6",
	"grans_4",
	"ur_marlows_dagbok_6",
	"ur_marlows_dagbok_5",
	"ur_marlows_dagbok_4",
	"ur_marlows_dagbok_3",
	"ur_marlows_dagbok_2",
		"ur_marlows_dagbok_2_detalj1",
	"ur_marlows_dagbok_1",
	"idiot_wind",
		"idiot_wind_detalj1",
	"communio",
	"spinalonga_1",
	"libera_me",
	"agnus_dei",
		"agnus_dei_detalj1",
		"agnus_dei_detalj2",
	"kyrie_eleison",
	"langsam_hemkomst",
	"glesbyggd_2",
	"marionett",
	"san_lorentzo_natt",
	"gelsominas_trumpet",
	"cirkusbild_5",
		"cirkusbild_5_detalj1",
		"cirkusbild_5_detalj2",
	"cirkusbild_4"
)

var textPages = new Array
(
	"intro",
	"ake"
)

var infoPages = new Array
(
	"verk",
	"utstallningar",
	"priser",
	"kontakt",
	"web"
)

var indexImages = new Array
(
	"index1", 
	"index2" , 
	"index3", 
	"index4", 
	"index5",
	"index6",
	"index7",
	"index8"
) 
	
var indexImageTexts = new Array
(
	"Detalj från Vedbärerskans hus, 2005", 
	"Detalj från ur Marlows dagbok 3, 1998", 
	"Detalj från Idiot Wind, 1997", 
	"Detalj från Gräns 5, 2002", 
	"Detalj från Längs floden 3, 2006",
	"Detalj från Gelsominas trumpet, 1985",
	"Detalj från Libera me, 1995",
	"Detalj från Tigerbrand, 2007"
) 

function init()
{
	element = getElement("title")
	if (element != null)
		document.title = document.title + " - " + element.innerHTML
}

function randomImageById(elementId)
{
	randomImage(getElement(elementId));
}

function randomImage(img)
{
	current = getPageFromURL(img.src)
	do
	{
		i = Math.floor(Math.random(23) * indexImages.length);
	} while (indexImages[i] == current);
	img.src = indexImages[i] + ".jpg";
	img.title = indexImageTexts[i];
}

function initLinks(pages)
{
    initLink(pages, "prevlink", -1)
    initLink(pages, "nextlink", 1)
}

function initLink(pages, elementId, step)
{
    element = getElement(elementId)
    if (element != null)
    {
    	page = getRelativePage(pages, step);
    	if (page != null)
    		element.href = page + ".html"
    	else
    		element.style.visibility = "hidden"
    }
}

function getRelativePage(pages, step)
{
    page = getPageFromURL(document.URL)
	index = getIndex(pages, page)
	index += step
	if (index >= 0 && index < pages.length)
		return pages[index]
	if (pages == textPages && index == pages.length)
		return "../info/" + infoPages[0]
	if (pages == infoPages && index == -1)
		return "../texter/" + textPages[textPages.length - 1]
	return null
}

function getPageFromURL(url)
{
	parts = url.split("\\")
	page = parts[parts.length-1]
	parts = page.split("/")
	page = parts[parts.length-1]
	return page.split(".")[0]
}

function getIndex(array, element)
{
	for (i = 0; i < array.length; ++i) 
		if (array[i] == element) 
			return i
	return -10
}

function whiteBorder(element)
{
	element.style.borderColor="white";
}

function grayBorder(element)
{
	element.style.borderColor="gray";
}

function selectedImage(img)
{
	image = getPageFromURL(img.src)
	path = img.src.substring(0, img.src.length - image.length - 4)
	img.src = path + image + "_sel.gif"
}

function unselectedImage(img)
{
	image = getPageFromURL(img.src)
	path = img.src.substring(0, img.src.length - image.length - 4)
	img.src = path + image.substring(0, image.length - 4) + ".gif"
}

function getElement(id)
{
	if (document.getElementById)
		return document.getElementById(id);
	if (document.all)
		return document.all[id];
	return null;
}

function goto_first(pages)
{
	if (pages == infoPages)
		location = "../texter/" + textPages[0] + ".html"
	else
		location = pages[0] + ".html"
}

function goto_prev(pages)
{
   	page = getRelativePage(pages, -1);
   	if (page != null)
		location = page + ".html"
}

function goto_next(pages)
{
   	page = getRelativePage(pages, 1);
   	if (page != null)
		location = page + ".html"
}

function goto_last(pages)
{
	if (pages == textPages)
		location = "../info/" + infoPages[infoPages.length - 1] + ".html"
	else
		location = pages[pages.length - 1] + ".html"
}

