/* Lightbox */
var lightboxArray = new Array();
var currentPicture = 0;
var totalPictures = 0;

function showLightbox(id) {
	document.getElementById('lightbox').style.display = 'block';
	
	XMLHTTPObject = createHTTPHandler(); 
	XMLHTTPObject.open('GET', rootPath + 'pages/get_lightbox_images.php?id=' + id, true);
	XMLHTTPObject.setRequestHeader("Cache-Control", "no-cache");
	XMLHTTPObject.setRequestHeader("X_USERAGENT", "AJAX_shopmodule");
  	XMLHTTPObject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
 	XMLHTTPObject.setRequestHeader('Connection', 'close');
	XMLHTTPObject.send(null);	
	
	XMLHTTPObject.onreadystatechange=function() {		
		if (XMLHTTPObject.readyState==4) {
			// Get pictures and reset stuff
			tempArray = XMLHTTPObject.responseText.split("|||");
			lightboxArray = tempArray[0].split("||");
			document.getElementById('lightboxTitle').innerHTML = tempArray[1];
			currentPicture = 0;
			totalPictures = lightboxArray.length;
			if (totalPictures > 0) {
				clearLightbox();
				showPicture(0);
			}
		}
	}		
}

function hideLightbox() {
	document.getElementById('lightbox').style.display = 'none';
	clearLightbox();
}

function clearLightbox() {
	//document.getElementById('lightboxTitle').innerHTML = '';
	document.getElementById('lightboxDescription').innerHTML = '';
	document.getElementById('lightboxContentImage').innerHTML = '';	
}

function showPicture(nr) {
	clearLightbox();
	document.getElementById('lightboxContentImage').innerHTML = '<img src="' + lightboxArray[nr]  + '">';
	currentPicture = nr;
	
	// Check if we should hide arrows (when on first or last image)
	if (currentPicture == (totalPictures-1)) { // Last picture
		document.getElementById('lightboxImageNext').style.display = 'none';
	}else{
		document.getElementById('lightboxImageNext').style.display = 'block';
	}
	
	if (currentPicture == 0) { // First picture
		document.getElementById('lightboxImagePrevious').style.display = 'none';
	}else{
		document.getElementById('lightboxImagePrevious').style.display = 'block';
	}
	
	document.getElementById('lightboxDescription').innerHTML = (currentPicture+1) + ' van ' + totalPictures;
}

function goNext() {
	showPicture(currentPicture+1);
}

function goPrevious() {
	showPicture(currentPicture-1);
}

function createHTTPHandler(){
    httphandler = false;
    /*@cc_on @*/
    /*@if (@_jscript_version >= 5)
    // JScript gives us Conditional compilation, we can cope with old IE versions.
    // and security blocked creation of the objects.
    try {
      httphandler = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
       httphandler = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
          httphandler = false;
      }
    }
    @end @*/
    if (!httphandler && typeof XMLHttpRequest!='undefined') {
        httphandler = new XMLHttpRequest();
    }
    return httphandler;
}
	
function createHTTPHandler_tmp(){

	// code for Mozilla, etc.
	if (window.XMLHttpRequest)
	  {
	  xmlhttp=new XMLHttpRequest()
	  }
	// code for IE
	else if (window.ActiveXObject)
	  {
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
	  }
	return xmlhttp;
}

Array.prototype.find = function (s)
{
	for(var i=0;i<this.length;i++)
	if(this[i] == s) return true; 
	return false;
};