//-- getelementbyid wrapper
function $(_id) {
    if (document.getElementById) return document.getElementById(_id);
    if (document.all)            return document.all[_id];
    return false;
}

//-- toggle element display
function toggle(_id) {
    
    obj = $(_id);
    
    if (obj.style.display == "block") {
        obj.style.display = "none";
    } else {
        obj.style.display = "block";
    }
}
    
// onload event coupler
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') { 
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

addLoadEvent(function() {
  //initRollover();
});

function setImage(img) {
	var _path = img.src;
	var el = document.getElementById("image_large");
    el.src = _path;
	
	el.width = img.width;
	el.height = img.height;
}

var currentImageIndex = Array();
function setSlideImage(imageList, imageKey) {
	currentImageIndex[imageList] = imageKey;
	setImage(imageList[imageKey]);			
}

function nextImage(imageList) {
	var currentIndex = currentImageIndex[imageList];
	if(!currentIndex) currentIndex = 0;
	
	currentIndex++;

	// currentIndex = (currentIndex + 1) % imageList.length;
	
	if(currentIndex >= imageList.length) {
		window.location.href = nextUrl;
	} else {
		setSlideImage(imageList,currentIndex);
	}
}

function prevImage(imageList) {
	var currentIndex = currentImageIndex[imageList];
	if(!currentIndex) currentIndex = 0;
		
	currentIndex--;
	//if(currentIndex < 0) currentIndex = imageList.length - 1;
	
	if(currentIndex < 0) {
		window.location.href = prevUrl;
	} else {	
		setSlideImage(imageList,currentIndex);
	}
}

function setLanguage(lang) {
    location.href = location.href.replace( /(\/)(en|nl)(\/?)/, '/' + lang + '/');
    return false;
}
