var iconselected = 0;
var menusel = 0;
var menuselected = '';

// Blendover functionality
var speed = 5;
var imageid = "billede";
var bgimageid = "bgbillede";
var inc = 2;
var opac = 0;
var imgno = 0;
var lastimgno = 0;
var imageurl = "";
var timerId = 0;
var interval = 10;

// slide in/out functionality
var current_iconmenu = "";
var new_iconmenu = "";
var newMrg = 180;
var startInt;

function menuselect(thismenu) {	
if (menuselected != '') document.getElementById(menuselected).className = 'menupunkt';
if (thismenu != '') {
menuselected = thismenu;
document.getElementById(menuselected).className = 'menupunktsel';
document.getElementById(menuselected).blur();
}
}

// *** Imagecaching functionality ***
function cacheIkons(ino) {
if (ikons.length > ino) {
this._tmpImgIkon = new Image();
_tmpImgIkon.src = ikons[ino];
document.getElementById('ikon' + ino).src = ikons[ino];
_tmpImgIkon.onLoad = setTimeout('cacheIkons(' + (ino + 1) + ')', 0);
}
else cacheImages(0);
}

function cacheImages(no) {
if (images.length > no) {
this._tmpImg = new Image();
_tmpImg.src = images[no];
_tmpImg.onLoad = setTimeout('cacheImages(' + (no + 1) + ')', 0);
}
}

// *** Blendover functionality ***
function changeOpac(opacity, id) {
var object = document.getElementById(id).style; 
object.opacity = (opacity / 100);
object.MozOpacity = (opacity / 100);
object.KhtmlOpacity = (opacity / 100);
object.filter = "alpha(opacity=" + opacity + ")";
}

function prepareNext() {
if(timerId) {
clearTimeout(timerId);
timerId = 0;
}
if (!((parseInt(iconPos[parseInt(iconselected) + 1]) === 0) || !(iconPos[parseInt(iconselected) + 1])))
timerId = setTimeout('nextPic()', (interval * 1000));
}

function blendimage(imagefile, selikon) {
setSubText(imagefile.substring((imagefile.lastIndexOf("/") + 5), (imagefile.length - 4)));
this.tmpImg = new Image();
tmpImg.src = imagefile;
setSelectedIcon(selikon);
var tmptst = imagefile.split('forside');
if (tmptst.length == 1) prepareNext();
tmpImg.onLoad = readyToBlend(imagefile);
}

function readyToBlend(imgFile) {
if (imgFile == "billeder/trns.gif") document.getElementById('kontaktramme').style.visibility = 'visible';
else document.getElementById('kontaktramme').style.visibility = 'hidden';
opac = 0;
imgno += 1;
document.getElementById(imageid).src = imgFile;
fadeIn();
}

function fadeIn() {
if ((imgno == (lastimgno + 1)) && (document.getElementById(bgimageid).src != document.getElementById(imageid).src)) {
if (opac < 100) {
	   imageurl = document.getElementById(imageid).src;
	   changeOpac(opac, 'billedramme');
	   opac += inc;
	   setTimeout('fadeIn()',speed);
	   }
	   else {
	   document.getElementById(bgimageid).src = imageurl;
	   if (imageurl.substring((imageurl.lastIndexOf("/") + 1), imageurl.length) == "trns.gif") document.getElementById('kontaktrammebg').style.visibility = 'visible';
	   else document.getElementById('kontaktrammebg').style.visibility = 'hidden';
	   changeOpac(100, 'bgbilledramme');
	   setTimeout("changeOpac(0, 'billedramme')",speed);
	   opac = 0;
	   lastimgno = imgno;
	   }
	   }
	   else {
	   document.getElementById(bgimageid).src = imageurl;
	   if (imageurl.substring((imageurl.lastIndexOf("/") + 1), imageurl.length) == "trns.gif") document.getElementById('kontaktrammebg').style.visibility = 'visible';
	   else document.getElementById('kontaktrammebg').style.visibility = 'hidden';
	   changeOpac(100, 'bgbilledramme');
	   changeOpac(0, 'billedramme');
	   opac = 0;
	   lastimgno += 1;
	   }
	   }
	   
	   // *** Slide in/out functionality ***
	   function slideIn(obj_name) {
	   new_iconmenu = document.getElementById(obj_name).style;
	   new_iconmenu.zIndex = 7;
	   if (current_iconmenu != "") {
	   current_iconmenu.zIndex = 6;
	   slideUp(0);
	   }
	   document.getElementById('arrowbox').style.visibility = 'visible';
	   slideDown(50, obj_name);
	   //current_iconmenu = new_iconmenu;
	   }
	   
	   function slideDown(btm, menunamez) {
	   if (btm > 10) btm -= 5;
	else if (btm == 10) btm = 5;
	else if (btm == 5) btm = 2;
	else if (btm == 2) btm = 1;
	else if (btm == 1) btm = 0;
	new_iconmenu.bottom = (btm + "px");
	document.getElementById('arrowbox').style.bottom = ((btm + 37) + 'px');
	if (btm > 0) setTimeout("slideDown(" + btm + ", '" + menunamez + "')", 10);
	else {
	current_iconmenu = new_iconmenu;
	menusel = menucommands[menunamez]['menu'];
	blendimage(menucommands[menunamez]['load'], menucommands[menunamez]['select']);
	//setSelectedIcon(menucommands[menunamez]['select']);
	}
	}
	
	function slideUp(btm) {
	if (btm < 40) btm += 10;
		  else if (btm ==40) btm = 45;
		  else if (btm == 45) btm = 48;
		  else if (btm == 48) btm = 49;
		  else if (btm == 49) btm = 50;
		  current_iconmenu.bottom = (btm + "px");
		  if (btm < 50) setTimeout("slideUp(" + btm + ")", 5);
			    else {
			    if (iconselected == '') current_iconmenu = '';
			    }
			    }
			    
			    function startMenu() {
			    blendimage('billeder/forside/000_.jpg', 0);
			    startInt = setInterval(function() {if (lastimgno == imgno) slideMenu();}, 1);
			    cacheIkons(0);
			    }
			    
			    function forside() {
			    blendimage('billeder/forside/000_.jpg', 0);
			    if (current_iconmenu != "") {
			    current_iconmenu.zIndex = 6;
			    document.getElementById('arrowbox').style.bottom = ('100px');
			    document.getElementById('arrowbox').style.visibility = 'hidden';
			    slideUp(0);
			    }
			    if(timerId) {
			    clearTimeout(timerId);
			    timerId = 0;
			    }
			    iconselected = '';
			    menusel = 0;
			    }
			    
			    function kontakt() {
			    kontaktview = "visible";
			    blendimage('billeder/trns.gif', 0);
			    if (current_iconmenu != "") {
			    current_iconmenu.zIndex = 6;
			    document.getElementById('arrowbox').style.bottom = ('100px');
			    document.getElementById('arrowbox').style.visibility = 'hidden';
			    slideUp(0);
			    }
			    if(timerId) {
			    clearTimeout(timerId);
			    timerId = 0;
			    }
			    iconselected = '';
			    menusel = 0;
			    }
			    
			    function slideMenu() {
			    clearInterval(startInt);
			    menuStyle = document.getElementById('menu').style;
			    if (newMrg > 10) newMrg -= 10;
			  else if (newMrg == 10) newMrg = 5;
			  else if (newMrg == 5) newMrg = 2;
			  else if (newMrg == 2) newMrg = 1;
			  else if (newMrg == 1) newMrg = 0;
			  minus = "";
			  if (newMrg > 0) minus = "-";
			  menuStyle.marginRight = (minus + newMrg + "px");
			  if (newMrg > 0) setTimeout(slideMenu, 1);
			  else blendimage('billeder/forside/000_.jpg', 0);
			  }
			  
			  // *** Change subtext ***
			  function setSubText(newText) {
			  var space = "";
			  if (newText != "") space = "\u00A0\u00A0\u00A0\u00A0";
			  var divBilledtekst = document.getElementById("billedtekst");
			  var copyright = ("\u00A9 Hanne Loop");
			  newText = decodeURIComponent(newText);
			  divBilledtekst.childNodes[0].nodeValue = (newText + space + copyright);
			  }
			  
			  // *** Iconmenu ***
			  function setSelectedIcon(thisIcon) {
			  if (iconselected != '') document.getElementById('ikonlink' + iconselected).className = 'ikonlink';
			  if (thisIcon >= 0) {
			  iconselected = thisIcon;
			  document.getElementById('ikonlink' + iconselected).className = 'ikonlinkselected';
			  }
			  if ((parseInt(iconPos[parseInt(iconselected) + 1]) === 0) || !(iconPos[parseInt(iconselected) + 1])) document.getElementById('rightarrow' + menusel).style.visibility = 'hidden';
			  else document.getElementById('rightarrow' + menusel).style.visibility = 'visible';
			  if ((parseInt(iconPos[parseInt(iconselected) - 1]) > iconPos[parseInt(iconselected)]) || !(iconPos[parseInt(iconselected) - 1])) document.getElementById('leftarrow' + menusel).style.visibility = 'hidden';
			  else document.getElementById('leftarrow' + menusel).style.visibility = 'visible';
			  
			  scrollmenu = document.getElementById('r_' + menusel).style;
			  leftpos = scrollmenu.marginLeft;
			  leftpos = leftpos.substring(0, (leftpos.length - 2));
			  if (leftpos == "") leftpos = 0;
			  
			  if ((parseInt(iconPos[parseInt(iconselected) + 1]) === 0) || !(iconPos[parseInt(iconselected) + 1]))
			  newpos = (873 - (parseInt(leftpos) + parseInt(iconPos[parseInt(iconselected)]) + 40));
			  else newpos = (873 - (parseInt(leftpos) + parseInt(iconPos[parseInt(iconselected) + 1])));
			  if (newpos < 0) scrollmenu.marginLeft = (parseInt(leftpos) + newpos);
				       else {
				       newpos = (parseInt(leftpos) + parseInt(iconPos[parseInt(iconselected)]));
				       if (newpos < 0) scrollmenu.marginLeft = (parseInt(leftpos) + (newpos - (newpos * 2)) - 1);
						    }
						    }
						    
						    // *** Scroll iconmenu ***
						    function scroll_left() {
						    scrollmenu = document.getElementById('r_' + menusel).style;
						    leftpos = scrollmenu.marginLeft;
						    leftpos = leftpos.substring(0, (leftpos.length - 2));
						    if (leftpos == "") leftpos = 0;
						    scrollmenu.marginLeft = (parseInt(leftpos) - 1);
						    scroller = setTimeout('scroll_left()', 5);
						    }
						    
						    function scroll_right() {
						    scrollmenu = document.getElementById('r_' + menusel).style;
						    rightpos = scrollmenu.marginLeft;
						    rightpos = rightpos.substring(0, (rightpos.length - 2));
						    if (rightpos == "") rightpos = 0;
						    scrollmenu.marginLeft = (parseInt(rightpos) + 1);
						    scroller = setTimeout('scroll_right()', 5);
						    }
						    
						    function nextPic() {
						    var nextHref = document.getElementById('ikonlink' + ((iconselected * 1) + 1)).href;
						    var nhArr = new Array();
						    nhArr = nextHref.split(',');
						    blendimage(nextHref.substring(23, (nhArr[0].length - 1)), (iconselected * 1) + 1);
						    }
						    
						    function prevPic(obj) {
						    var nextHref = document.getElementById('ikonlink' + ((iconselected * 1) - 1)).href;
						    var nhArr = new Array();
						    nhArr = nextHref.split(',');
						    blendimage(nextHref.substring(23, (nhArr[0].length - 1)), (iconselected * 1) - 1);
						    }
						    
						    function scroll_stop() {
						    if (scroller) clearTimeout(scroller);
	}
