window.onload = function(){
	var img;
	if (/#\d+/.test(document.location.hash)) {
		img = parseInt(/#(\d+)/.exec(document.location.hash)[1]) - 1;
		modifyimage('dynloadarea', img);
	}
};

//Preload images ("yes" or "no"):
var preloadimg="no"
var nextImg = 0;

//Optionally, change 1.0 and 0.7 below to affect Wipe gradient size and duration in seconds in IE5.5+:
var filterstring="progid:DXImageTransform.Microsoft.GradientWipe(GradientSize=1.0 Duration=1.6)"

if (preloadimg=="yes"){
	for (x=0; x<dynimages.length; x++){
		var myimage=new Image()
		myimage.src=dynimages[x][0]
	}
}

function returnimgcode(theimg,index){
	var imghtml=""
	var imgAntal = dynimages.length
	if (index == 0) {
		nextImg = index + 1;
		prevImg = imgAntal - 1;
	} else if (index < (imgAntal-1)) {
		nextImg = index + 1;
		prevImg = index - 1;
	} else {
		nextImg = 0;
		prevImg = index - 1;
	}
	if (theimg[1]!="")
	imghtml+='<div class="left"><div id="featured"><p id="featured-image"><a href="javascript:void(0)" onclick="modifyimage(\'dynloadarea\', ' + nextImg + '); return false;"><img src="'+theimg[0]+'" title="'+titleimages[index]+'" border="0" id="bilden" /></a></p></div></div><div class="right"><div id="right-feature"><div id="altbildNr">Bild 1 av <script type="text/javascript">document.write(dynimages.length)</script></div><div id="altbildText"></div><p><a href="javascript:void(0)" onclick="modifyimage(\'dynloadarea\', ' + prevImg + '); return false;"><< F&ouml;reg&aring;ende</a> &nbsp; &nbsp; &nbsp; <a href="javascript:void(0)" onclick="modifyimage(\'dynloadarea\', ' + nextImg + '); return false;">N&auml;sta >></a></p><p><a href="/">Tillbaka till albumen</a></p></div></div>'
	return imghtml
}

function modifyimage(loadarea, imgindex){
	if (document.getElementById){
		var imgobj=document.getElementById(loadarea)
		if (imgobj.filters && window.createPopup){
			imgobj.style.filter=filterstring
			imgobj.filters[0].Apply()
		}
		imgobj.innerHTML=returnimgcode(dynimages[imgindex],imgindex)
		document.getElementById('altbildText').innerHTML=(document.getElementById("bilden").getAttribute("title"));
		document.getElementById('altbildNr').innerHTML=("bild "+(imgindex+1)+" av " +dynimages.length);

		if (imgobj.filters && window.createPopup)
		imgobj.filters[0].Play()
		document.location.hash = imgindex + 1;
		return false
	}
}
function arrowBrowse(key) {
	//right
	if(key==39) {
		return modifyimage('dynloadarea', nextImg);

	}
	//left
	if(key==37) {
		nextImg = nextImg-2;
		return modifyimage('dynloadarea', nextImg);

	}
	//right mouse
	if(button==2) {
		nextImg = nextImg-2;
		return modifyimage('dynloadarea', nextImg);
	}	
}