var cur_lyr;
var cur_lyr2;
var cur_lyr3;
var darklite = null;

function getElemRefs(id)
{
	var el = (document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? getLyrRef(id,document): null;
	if (el) el.css = (el.style)? el.style: el;
	return el;
}

// Swap layers

function swapLayers(id)
{
	if (cur_lyr) hideLayer(cur_lyr);
	showLayer(id);
	cur_lyr = id;
}

function swapLayers2(id)
{
	if (cur_lyr2) hideLayer(cur_lyr2);
	showLayer(id);
	cur_lyr2 = id;
}

function showLayer(id)
{
	var lyr = getElemRefs(id);
	if (lyr && lyr.css) lyr.css.visibility = "visible";
}

function hideLayer(id)
{
	var lyr = getElemRefs(id);
	if (lyr && lyr.css) lyr.css.visibility = "hidden";
}

// Swap layers - end

// Actor ------------------------------------------------

// Show/Hide

function showhide(id, idx)
{
	var dl = getElemRefs(darklite);
	
	if (cur_lyr3 != id)
	{
 		if (darklite != null)
		{
			if (darklite.substr(3,2) % 2 != 0)
			{
				dl.css.background = "#000000";
			}
			else
			{
				dl.css.background = "#181515";
			}
		}
		hideLayer2(cur_lyr3);
		showLayer2(id, idx);
		darklite = idx;
		cur_lyr3 = id;
	}
	else if (cur_lyr3 == id)
	{
		 hideLayer2(id)
		 cur_lyr3 = null;
	}
}

function actResetAll()
{
	var dl = getElemRefs(darklite);
	
 		if (darklite != null)
		{
			if (darklite.substr(3,2) % 2 != 0)
			{
				dl.css.background = "#000000";
			}
			else
			{
				dl.css.background = "#181515";
			}
		}
	hideLayer2(cur_lyr3)
	cur_lyr3 = null;
}

function showLayer2(id, idx)
{
	var lyr = getElemRefs(id);
	if (lyr && lyr.css) lyr.css.display = "block";
	document.getElementById(idx).style.background = "#2C2627";
}

function hideLayer2(id)
{
	var lyr = getElemRefs(id);
	if (lyr && lyr.css) lyr.css.display = "none";
}

// Show/Hide - end

// Set background on actor matrix entries

function actorActiveOn(id, idx)
{
	var lyr = getElemRefs(idx);
	
	if (cur_lyr3 != id)
	{
		lyr.css.background = "#2C2627";
	}
}

function actorActiveOff(id, idx)
{
	var lyr = getElemRefs(idx);
	
	if ((cur_lyr3 != id) && (idx.substr(3,2) % 2 != 0))
	{
		lyr.css.background = "#000000";
	}
	else if ((cur_lyr3 != id) && (idx.substr(3,2) % 2 == 0))
	{
		lyr.css.background = "#181515";
	}
}

// Set background on actor matrix entries - end

// Actor end --------------------------------------------

// Film -------------------------------------------------

// Show/Hide

function filmShowhide(id, idx)
{
	var dl = getElemRefs(darklite);
	
	if (cur_lyr3 != id)
	{
 		if (darklite != null)
		{
			if (darklite.substr(3,2) % 2 != 0)
			{
				dl.css.background = "#000000";
			}
			else
			{
				dl.css.background = "";
			}
		}
		filmHideLayer2(cur_lyr3);
		filmShowLayer2(id, idx);
		darklite = idx;
		cur_lyr3 = id;
	}
	else if (cur_lyr3 == id)
	{
		 filmHideLayer2(id)
		 cur_lyr3 = null;
	}
}

function filmResetAll()
{
	var dl = getElemRefs(darklite);
	
 		if (darklite != null)
		{
			if (darklite.substr(3,2) % 2 != 0)
			{
				dl.css.background = "#000000";
			}
			else
			{
				dl.css.background = "#121212";
			}
		}
	filmHideLayer2(cur_lyr3)
	cur_lyr3 = null;
}

function filmShowLayer2(id, idx)
{
	var lyr = getElemRefs(id);
	if (lyr && lyr.css) lyr.css.display = "block";
	document.getElementById(idx).style.background = "#242424";
}

function filmHideLayer2(id)
{
	var lyr = getElemRefs(id);
	if (lyr && lyr.css) lyr.css.display = "none";
}

// Show/Hide - end

// Set background on film matrix entries

function filmActiveOn(id, idx)
{
	var lyr = getElemRefs(idx);
	
	if (cur_lyr3 != id)
	{
		lyr.css.background = "#242424";
	}
}

function filmActiveOff(id, idx)
{
	var lyr = getElemRefs(idx);
	
	if ((cur_lyr3 != id) && (idx.substr(3,2) % 2 != 0))
	{
		lyr.css.background = "#000000";
	}
	else if ((cur_lyr3 != id) && (idx.substr(3,2) % 2 == 0))
	{
		lyr.css.background = "#121212";
	}
}

// Set background on film matrix entries - end

// Film end ---------------------------------------------

// Rezize and center page

function faijzingResize(iW,iH)
{
	window.resizeBy(iW-windowWidth(),iH-windowHeight());
}

function faijzingWindowWidth() {return window.innerWidth != null? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;}

function faijzingWindowHeight() {return  window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;}
 
function faijzingCheckWinSize()
{
	var winh = faijzingWindowHeight();
	var winw = faijzingWindowWidth();

	if (winh < 600 && winw >= 990 )
	{
		document.getElementById("global").style.marginTop = 0;
		document.getElementById("global").style.marginLeft = "-495px";
		document.getElementById("global").style.top = 0;
		document.getElementById("global").style.left = "50%";
	}
	else if (winh >= 600 && winw >= 990)
	{
		document.getElementById("global").style.marginTop = "-300px";
		document.getElementById("global").style.marginLeft = "-495px";
		document.getElementById("global").style.top = "50%";
		document.getElementById("global").style.left = "50%";
	}
	
	else if (winh >= 600 && winw < 990)
	{
		document.getElementById("global").style.marginTop = "-300px";
		document.getElementById("global").style.marginLeft = 0;
		document.getElementById("global").style.top = "50%";
		document.getElementById("global").style.left = 0;
	}
	
	else if (winh < 600 && winw < 990)
	{
		document.getElementById("global").style.marginTop = 0;
		document.getElementById("global").style.marginLeft = 0;
		document.getElementById("global").style.top = 0;
		document.getElementById("global").style.left = 0;
	}
}

// Rezize and center page - end

// Set active tab on actor/film menu

function setActiveTabAct(id)
{
	var ida = id + "a";
	var currTabElem = document.getElementById(id);
	var currTabElemA = document.getElementById(ida);
	var menuTabs = ["acft", "acte", "acri", "ackf", "acut"];
	var menuTabsA = ["acfta", "actea", "acria", "ackfa", "acuta"];
	var currTabElemNew = [5];
	var currTabElemNewA = [5];
 	var i = 0;

	currTabElem.setAttribute("class", "actorMenuActive");
	currTabElem.setAttribute("className", "actorMenuActive");
	currTabElemA.setAttribute("class", "lank_actorA");
	currTabElemA.setAttribute("className", "lank_actorA");

	for (i = 0; i < 5; i++)
	{
		if (menuTabs[i] != id)
		{
			currTabElemNew[i] = document.getElementById(menuTabs[i]);
			currTabElemNew[i].setAttribute("class", "actorMenu");
			currTabElemNew[i].setAttribute("className", "actorMenu");			
			currTabElemNewA[i] = document.getElementById(menuTabsA[i]);
			currTabElemNewA[i].setAttribute("class", "lank_actor");
			currTabElemNewA[i].setAttribute("className", "lank_actor");
		}
	}
}

function setActiveTabVid(id)
{
	var ida = id + "a";
	var currTabElemA = document.getElementById(ida);
	var menuTabsA = ["vifta", "vitea", "viria"];
	var currTabElemNewA = [3];
 	var i = 0;

	currTabElemA.setAttribute("class", "lank_actorA");
	currTabElemA.setAttribute("className", "lank_actorA");

	for (i = 0; i < 3; i++)
	{
		if (menuTabsA[i] != ida)
		{
			currTabElemNewA[i] = document.getElementById(menuTabsA[i]);
			currTabElemNewA[i].setAttribute("class", "lank_actor");
			currTabElemNewA[i].setAttribute("className", "lank_actor");
		}
	}
}

function setActiveTabFi(id)
{
	var ida = id + "a";
	var currTabElem = document.getElementById(id);
	var currTabElemA = document.getElementById(ida);
	var menuTabs = ["fifi", "fiut"];
	var menuTabsA = ["fifia", "fiuta"];
	var currTabElemNew = [2];
	var currTabElemNewA = [2];
 	var i = 0;
	
	currTabElem.setAttribute("class", "filmMenuActive");
	currTabElem.setAttribute("className", "filmMenuActive");
	currTabElemA.setAttribute("class", "lank_filmA");
	currTabElemA.setAttribute("className", "lank_filmA");

	for (i = 0; i < 2; i++)
	{
		if (menuTabs[i] != id)
		{
			currTabElemNew[i] = document.getElementById(menuTabs[i]);
			currTabElemNew[i].setAttribute("class", "filmMenu");
			currTabElemNew[i].setAttribute("className", "filmMenu");
			currTabElemNewA[i] = document.getElementById(menuTabsA[i]);
			currTabElemNewA[i].setAttribute("class", "lank_filmNotA");
			currTabElemNewA[i].setAttribute("className", "lank_filmNotA");
		}
	}
}

// Set active tab on actor/film menu - end

// External links

// Open External Links as Blank Targets via Unobtrusive JavaScript
// http://perishablepress.com/press/2007/11/20/open-external-links-as-blank-targets-via-unobtrusive-javascript/

function externalLinks()
{
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++)
	{
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && (anchor.getAttribute("rel") == "external" || anchor.getAttribute("rel") == "external nofollow" || anchor.getAttribute("rel") == "nofollow external"))
		{
			anchor.target = "_blank";
		}
	}
}

// External links - end

// Gallery

function initScrollLayer()
{
	var wndo = new dw_scrollObj('wn', 'lyr1', 't1');
}

function faijzing_rollover(bildplats,bildattvisa)
{
	if(document.images)
	{
		document.images[bildplats].src=bild[bildattvisa].src 
	}
}

function faijzing_incCurCol()
{
	if (curCols != cols)
	{
		newCurCols = curCols + 1;
		hideLayer('sceneNavM' + (curCols));
		showLayer('sceneNavM' + newCurCols);
		curCols++;
	}

	if (curCols == cols)
	{
		document.getElementById("pilh").style.cursor = "";
	}
	else
	{
		document.getElementById("pilh").style.cursor = "pointer";
		
	}

	if (curCols == 1)
	{
		document.getElementById("pilv").style.cursor = "";
	}
	else
	{
		document.getElementById("pilv").style.cursor = "pointer";
	}
}

function faijzing_decCurCol()
{
	if (curCols != 1)
	{
		newCurCols = curCols - 1;
		hideLayer('sceneNavM' + (curCols));
		showLayer('sceneNavM' + newCurCols);
		curCols--;
	}

	if (curCols == cols)
	{
		document.getElementById("pilh").style.cursor = "";
	}
	else
	{
		document.getElementById("pilh").style.cursor = "pointer";
	}

	if (curCols == 1)
	{
		document.getElementById("pilv").style.cursor = "";
	}
	else
	{
		document.getElementById("pilv").style.cursor = "pointer";
	}
}

function faijzing_ArrowInL(id)
{
	if (curCols != 1)
	{
		faijzing_rollover('pilv',3);
	}
}

function faijzing_ArrowInR(id)
{
	if (curCols != cols)
	{
		faijzing_rollover('pilh',1);
	}
}

// Gallery - end

window.onresize = faijzingCheckWinSize;

