// Written 2011 by Frank Blechschmitt, FBIS
//
function s2d_antispam_decode(text) {
	var dtxt=''; var txtc=0; var txtl=text.length;
	for(var i=0; i<txtl; i+=2) {
		txtc=parseInt(text.substr(i,2),16);
		dtxt+=String.fromCharCode(txtc);
	}
	return dtxt;
}
function OpenWindow(url, title, win_width, win_height) {
	var x,y;
	
	if(win_width==0) {
		win_width = 800;
	}
	if(win_height==0) {
		win_height = 600;
	}
	x = (screen.width / 2) - (win_width / 2);
	y = (screen.height / 2) - (win_height / 2);

	window.open(url,title,'resizable,width='+win_width+',height='+win_height+',top='+y+',left='+x+',toolbar=no,status=no');
}
function OpenWindowWithScrollbar(url, title, win_width, win_height) {
	var x,y;
	
	if(win_width==0) {
		win_width = 800;
	}
	if(win_height==0) {
		win_height = 600;
	}
	x = (screen.width / 2) - (win_width / 2);
	y = (screen.height / 2) - (win_height / 2);

	myWindow = window.open(url,title,"resizable,width="+win_width+",height="+win_height+",top="+y+",left="+x+",toolbars=no,scrollbars=yes,status=no");
}
function s2d_gallery_slideshow(elementId, imagelist, width, height, speed) {
	this.delay = 0; // Seconds
	this.elementId = elementId;
	this.imagelist = imagelist;
	this.imagelistid = 0;
	this.speed = speed;
	var myObject = this;

	this.init = function(delay) {
		this.delay = delay;
		myObject.fader();
	}
	
	this.fader = function() {
		var element = document.getElementById(this.elementId);
		if(element.children.length > 1) {
			element.removeChild(element.firstChild);
		}
		el = document.createElement('img');
		with(el) {
			setAttribute('id', 's2d_slideshow_img'+this.imagelistid);
			setAttribute('src', this.imagelist[this.imagelistid]);
			setAttribute('alt', 'img'+this.imagelistid);
		}
		with(el.style) {
			position = 'absolute';
			top = '0px';
			left = '0px';
			width = element.style.width;
			height = element.style.height;
			filter = 'alpha(opacity:'+(element.children.length==0 ? 1 : 0)+')';
			KHTMLOpacity = (element.children.length==0 ? 1 : 0);
			MozOpacity = (element.children.length==0 ? 1 : 0);
			opacity = (element.children.length==0 ? 1 : 0);
		}
		element.appendChild(el);
		if(element.children.length > 1) { myObject.fadeIn(el,0); }
		if(this.imagelistid < this.imagelist.length-1) {
			this.imagelistid++;
			var preload = new Image();
			preload.src = this.imagelist[this.imagelistid];
		} else {
			this.imagelistid = 0;
		}
		window.setTimeout( function() { myObject.fader(); }, this.delay);
	}
	
	this.fadeIn = function(obj,opacity) {
		if(opacity <= 100) {
			opacity = (opacity > 100)?100:opacity;
			obj.style.filter = "alpha(opacity:"+opacity+")";
			obj.style.KHTMLOpacity = opacity/100;
			obj.style.MozOpacity = opacity/100;
			obj.style.opacity = opacity/100;
			opacity += 1;
			window.setTimeout( function() { myObject.fadeIn(obj,opacity); }, this.speed);
		}
	}
}
