// WARNING: THIS SCRIPT CRASHES THE BROWSER WHEN iSlide IS CALLED BEFORE THE DOM IS LOADED: CALL IT AFTER WINDOW.ONLOAD OR PLACE OUTSIDE BODY TAGS
function iSlide(){
	var d = new Date();
	this.id = "iSlide"+d.getMinutes()+d.getSeconds();
	var w = document.createElement('div');
	w.slideshow = this;
	this.sA(w,'id',this.id);
	this.setClass(w,"iSlide");
	var bg = this.aNC(w,"div");this.setClass(bg,"bg");
	var nx = this.aNC(w,"a");this.sA(nx,"id",this.id+"_next");this.setClass(nx,"next");
	var pr = this.aNC(w,"a");this.sA(pr,"id",this.id+"_prev");this.setClass(pr,"prev");
	var cl = this.aNC(w,"a");this.sA(cl,this.id+"_close");this.setClass(cl,"close");
	var ml = this.aNC(w,"a");this.sA(ml,"id","mail_link");this.setClass(ml,"mail_link");
	eval("cl.onclick = function(){ this.parentNode.slideshow.hide(); }");
	var ho = this.aNC(w,"div");this.setClass(ho,"horizon");
	this.aC(document.getElementById('container-wrapper'),w);
	this.wrapper = w;
	this.op = new Opacity(this.wrapper);
	this.timer = null;
	this.photos = null;
}
iSlide.prototype.popup = function(){
	this.op.setOpacity(100);
};
iSlide.prototype.hide = function(){
	this.op.setOpacity(0);
};
iSlide.prototype.remove = function(){
	var w = document.getElementById(this.id);
	w.parentNode.removeChild(w);
};
iSlide.prototype.loadPhotos = function(arr){
	this.photos = null;this.photos = new Array();this.iterator = 0;
	for(var i=0;i<arr.length;i++){
		var media = arr[i];
		if(media.mime=='image/jpeg'){
			this.photos.push(media);
		}
	}
};
iSlide.prototype.display = function(n){
	if(n<0) n = this.photos.length-1;
	if(n>=this.photos.length) n = 0;
	var photo = this.photos[n];
	var horizon = this.wrapper.lastChild;
	var img = document.createElement('img');
	this.sA(img,'src',photo.src);this.sA(img,'alt',photo.name);
	window.scroll(0,0);
	//var h3 = document.createElement('h3');
	//this.aC(h3,document.createTextNode((photo.title||"Naamloos")+" - "+this.formatDate(photo.date)));
	//var span = document.createElement('span');this.aC(span,document.createTextNode(photo.desc));
	while(horizon.getElementsByTagName('img').length>0){ 
		var oldImg = horizon.getElementsByTagName('img')[0];
		oldImg.parentNode.removeChild(oldImg);
	}
	this.aC(horizon,img);//var div = this.aNC(field,'div');this.aC(div,h3);this.aC(div,span);
	if(img.offsetHeight>0 && img.offsetWidth){
		img.style.marginTop = "-"+(img.offsetHeight/2)+"px";
		img.style.marginLeft = "-"+(img.offsetWidth/2)+"px";
	}else{
		img.style.marginTop = "-"+(500/2)+"px";
		img.style.marginLeft = "-"+(700/2)+"px";
	}
	var pr = document.getElementById(this.id+"_prev");
	eval("pr.onclick = function(){ this.parentNode.slideshow.display("+(n-1)+"); }");
	var nx = document.getElementById(this.id+"_next");
	eval("nx.onclick = function(){ this.parentNode.slideshow.display("+(n+1)+"); }");
	var ml = document.getElementById("mail_link");
	var subject = escape("Foto's van "+photo.name);
	var href = escape("http://media.excelsior-woerden.nl/?alb="+mc.collections[mc.currentlvl-1].key+"&pnr="+n);
	eval("ml.href = 'mailto:?subject="+subject+"&body="+href+"'");
	eval("ml.title = 'Stuur een link naar deze foto naar familie en vrienden.'");
};
// Text limiting functions
iSlide.prototype.sA = function(o,a,v){
	o.setAttribute(a,v);
};
iSlide.prototype.aNC = function(p,t){
	return p.appendChild(document.createElement(t));
};
iSlide.prototype.aC = function(p,c){
	return p.appendChild(c);
};
iSlide.prototype.setClass = function(o,c){
	o.className=c;
};
iSlide.prototype.rC = function(p){
	while(p.firstChild) p.removeChild(p.firstChild);
};
iSlide.prototype.formatDate = function(d){
	return d.getDate()+"-"+(d.getMonth()+1)+"-"+(1900+d.getYear());
}
