var lightboximgs;
var page = 1;
function initLightbox() {
	i = 0;
	num = new Array();
	imageset = Array();
	lightboximgs = new Array();
	lista = document.getElementsByTagName("a");
	ll = lista.length;
	
	for(i = 0 ; i < ll ; i++) {
		if(lista[i].target && lista[i].target.match(/popup/)) {
			tmp = lista[i].rel.match(/popup\[(.*)\]/);
			
			//namelist = tmp[1];
			//if(!lightboximgs[namelist]) {
			//	lightboximgs[namelist] = new Array();
			//	imageset[namelist] = new Array();
			//	num[namelist] = 0;
			//} else {
			//	num[namelist] = num[namelist] + 1;
			//}
			//usenum = num[namelist];
			
			//useI = i;
			//for(j = 0 ; j < imageset[namelist].length; j++) {
			//	if(lista[i].href == imageset[namelist][j][0]) {
			//		useI = imageset[namelist][j][1];
			//	}
			//}
			//imageset[namelist][usenum] = new Array(lista[i].href, i);
			//lista[useI].num = usenum;
			//lista[useI].list = namelist;
			lista[i].onclick = function () {
				doLightbox(this);
				return false;
			}
			//lightboximgs[namelist][usenum] = lista[useI];
		}
	}
}
var activenum = 0, activelist;
var imageContainer, outerImageContainer, lightbox, overlay;
var imgs, theImg;
function doLightbox(who) {
	activetype = who.rel;
	if(typeof(overlay) == "undefined") {
		createLightBox(activetype);
	}
	outerImageContainer.innerHTML = "";
	
	myRE = new RegExp("(jpg|png|gif)", "i")
	if(who.href.match(myRE)) {
		im = document.createElement("img");
		im.src = who.href;
		outerImageContainer.appendChild(im);
		sluiten = createElementAdd("sluiten", "div", outerImageContainer);
		asluiten = createElementAdd("clclclcl", "a", sluiten);
		asluiten.innerHTML = "sluiten";
		asluiten.href = "#";
		asluiten.onclick = function() {
			closeLightbox();
		}
	} else {
		if(who.href.match(/\?/)) {
			ajaxFunction(who.href + "&x=1");
		} else {
			ajaxFunction(who.href + "?x=1");
		}
	}

	if (self.pageYOffset) {
		yScroll2 = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){      // Explorer 6 Strict
		yScroll2 = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll2 = document.body.scrollTop;
	}
	
	lightbox.style.top  = (yScroll2 + 40 + 'px');
	

	overlay.style.display = "block";
	lightbox.style.display = "block";
}


function detectMacXFF2() {
  var userAgent = navigator.userAgent.toLowerCase();
  if (/firefox[\/\s](\d+\.\d+)/.test(userAgent)) {
    var ffversion = new Number(RegExp.$1);
    if (ffversion < 3 && userAgent.indexOf('mac') != -1) {
      return true;
    }
  }
}

var windowWidth, windowHeight;
var xScroll, yScroll;
function getPageSize(){



        if (window.innerHeight && window.scrollMaxY) {
                xScroll = document.body.scrollWidth;
                yScroll = window.innerHeight + window.scrollMaxY;
        } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
                xScroll = document.body.scrollWidth;
                yScroll = document.body.scrollHeight;
        } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
                xScroll = document.body.offsetWidth;
                yScroll = document.body.offsetHeight;
        }


        if (self.innerHeight) { // all except Explorer
                windowWidth = self.innerWidth;
                windowHeight = self.innerHeight;
        } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
                windowWidth = document.documentElement.clientWidth;
                windowHeight = document.documentElement.clientHeight;
        } else if (document.body) { // other Explorers
                windowWidth = document.body.clientWidth;
                windowHeight = document.body.clientHeight;
        }
}


var caption, numberDisplay, nextimage, newsContainer, inlb;
function createLightBox(activetype ) {
	getPageSize();
  inlb = false;
	overlay = createElementAdd("overlay", "div", document.body);
	getPageSize();
	
	
	h = window.outerHeight > document.body.scrollHeight ? window.outerHeight : document.body.scrollHeight;
	windowHeight = yScroll > windowHeight ? yScroll : windowHeight;
	
	overlay.style.height = windowHeight + "px";
	overlay.style.opacity = ".7";
	overlay.style.filter = "alpha(opacity=70)";
	lightbox = createElementAdd("lightbox", "div", document.body);
	
//	lightbox.style.top = "180px";

	outerImageContainer = createElementAdd("outerImageContainer", "div", lightbox);
}

var theImg, imgop;
var imgNew;

function doLImage(ws, t, who) {
	imgNew = ws;
	activeI = document.getElementById('activeImg')	
	prodt = document.getElementById("prod_title");
	prodt.innerHTML = t;	
	activeI.innerHTML = "<img src='/gfx/shim.gif'  id='activeImgSrc' width='300' >";
	setTimeout("setImage()", 39);
	setActiveLink(who);
}
var lbActivelink;
function setActiveLink(who) {
	if(lbActivelink) {
		lbActivelink.style.fontWeight = "normal";
	}
	
	lbActivelink = who;
	who.style.fontWeight = "bold";
}

function doLfilm(ws, t, who) {
	imgNew = ws;
	var film;
	activeI = document.getElementById("activeImg");
	prodt = document.getElementById("prod_title");
	
	film ="";	
	film += '<object type="application/x-shockwave-flash" data="/flash_new/FlowPlayerLight.swf" width="550" height="330" id="FlowPlayer" alt="">';
	film += '<param name="allowScriptAccess" value="always" />';
	film += '<param name="movie" value="/flash_new/FlowPlayerLight.swf" />';
	film += '<param name="quality" value="high" />';
	film += '<param name="scaleMode" value="showAll" />';
	film += '<param name="allowfullscreen" value="true" />';
	film += '<param name="wmode" value="opaque" />';
	film += '<param name="bgcolor" value="111111" />';
	film += '<param name="allowNetworking" value="all" />';
	film += '<param name="flashvars" value="config={ ';
	
	film += 'autoPlay: true, ';
	film += 'showMenu: false,';
	film += 'loop: false, ';
	film += 'initialScale: \'scale\',';
	film += 'showLoopButton: false,';
	film += 'splashImageFile: false,';
	film += 'showPlayListButtons: false,';
	film += 'fullScreenScriptURL: false,';
	
	film += 'showStopButton: false,'; 
	film += 'showScrubber: false,';
	film += 'showVolumeSlider: false,';
	film += 'showMuteVolumeButton: false,'; 
	film += 'showFullScreenButton: false,'; 
	film += 'showMenu: false,'; 
	film += "controlsOverVideo: 'locked',";
	film += 'controlBarBackgroundColor: -1,';
	film += "controlBarGloss: 'none',";
	
	film += 'playList: [';
	film += '{ url: \'' +  ws + '\' },';
	film += ']';
	film += '}" />';
	
	prodt.innerHTML = t;	
	activeI.innerHTML = film;	

	setActiveLink(who);
}



function lbNext() {
    var nextElem = document.getElementById('lb-' + (page + 1)) || false;
    if(nextElem) {
        page = page + 1;
        nextElem.onclick();
    }
}

function lbReset() {
    page = 1;
    var nextElem = document.getElementById('lb-1') || false;
    if(nextElem) {
        nextElem.onclick();
    }
}

function lbPrev() {
    var prevElem = document.getElementById('lb-' + (page - 1)) || false;
    if(prevElem) {
        page = page - 1;
        prevElem.onclick();
    }
}


function setImage() {
	activeI.innerHTML = "<img src='" + imgNew + "'  id='activeImgSrc' alt=''>";
	theImg = document.getElementById('activeImgSrc')
	theImg.style.opacity = 0;
	theImg.style.filter = "alpha(opacity=0)";	
	showImage();
}

function setImageSize() {
	listimg = document.getElementsByTagName("img");
	ll = listimg.length;

	for(i = 0 ; i < ll ; i++) {
	 	if(listimg[i].id.indexOf("resize") > -1 || listimg[i].id == "mainimage"){
			imgop = 99;
			listimg[i].style.opacity = imgop / 100;
			listimg[i].style.filter = "alpha(opacity=" + imgop + ")";
		}
	}
	
}

function showImage() {
	
	imgop = parseInt(theImg.style.opacity * 100);
	imgop = imgop + 10;
	if(imgop >= 100) {
		imgop = 99;
		return;
	} else {
		setTimeout("showImage()", 39);
	}
	theImg.style.opacity = imgop / 100;
	theImg.style.filter = "alpha(opacity=" + imgop + ")";
}

function hideImage() {

	imgop = parseInt(theImg.style.opacity * 100);
	if (imgop =="") {
		imgop  =99;
	}
	imgop = imgop - 10;
	if(imgop <= 0) {
		imgop = 0;
		setImage();
	} else {
		setTimeout("hideImage()", 39);
	}
	theImg.style.opacity = imgop / 100;
	theImg.style.filter = "alpha(opacity=" + imgop + ")";
}


function closeLightbox() {
	overlay.style.display = "none";
	lightbox.style.display = "none";
	outerImageContainer.innerHTML = "";
	
	return false;
}
function createElementAdd(who, what, where) {
	itm = document.createElement(what);
	itm.id = who;
	where.appendChild(itm);
	return itm;
}
var ajaxRequest;
function ajaxFunction(what){
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	
    // Create a function that will receive data sent from the server
    ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
    	outerImageContainer.innerHTML = ajaxRequest.responseText;
    	initProds();
			if(activetype && activetype.match(/maps/)) {
				initialize();
			} else if(activetype == "news") {
				// dit moet nog aangezet worden maar geeft conflict in IE
				$(function() {
					// this initialises the demo scollpanes on the page.
					$('#newspane').jScrollPane({scrollbarWidth: 10});
				});
			} else {
				
				if(theImg) {
					
					theImg = document.getElementById('activeImgSrc')
					theImg.style.opacity = 0;
					theImg.style.filter = "alpha(opacity=0)";	
					showImage();
					lbReset();
				}
				setTimeout("setImageSize()",3000);
			}
		}
	}
	ajaxRequest.open("GET", what, true);
	ajaxRequest.send(null); 
}
