var W3CDOM = (document.createElement && document.getElementsByTagName);

var mouseOver = new Array();
var mouseOut = new Array();
var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

var Slides = new ClassSlides();

String.prototype.ltrim = function () { return this.replace(/^ */,""); }
String.prototype.rtrim = function () { return this.replace(/ *$/,""); }
String.prototype.trim = function () { return this.ltrim().rtrim(); }

var z = 0;

function init() {
	attachjs('menu');
	if(typeof sIFR == "function") {
	// This is the preferred "named argument" syntax
		sIFR.replaceElement("h1", named({sFlashSrc: "gfx/helvetica.swf", sColor: "#009dd4"}));
		sIFR.replaceElement("h2", named({sFlashSrc: "gfx/helvetica.swf", sColor: "#ababab"}));
	};
	
	if (document.getElementById('flash')) {
		var so = new SWFObject("gfx/banner.swf","react","882","361","9","#FFFFFF");
		so.write("flash");
	}
}


function attachjs(element) {
	if (document.getElementById(element) == null) {
		return false;
	}

	var menu = document.getElementById(element);
	var img = menu.getElementsByTagName('img');
	
	for (i=0; i<img.length; i++) {
		if (!img[i].src.match("_over") && !img[i].src.match("seperator")) {
			img[i].onmouseover = function () {swapon(this)};
			img[i].onmouseout = function () {swapoff(this)};
			
			var suffix = img[i].src.substring(img[i].src.lastIndexOf('.'));
			mouseOut[z] = new Image();
			mouseOut[z].src = img[i].src;
			mouseOver[z] = new Image();
			mouseOver[z].src = img[i].src.substring(0,img[i].src.lastIndexOf('.')) + "_over" + suffix;
			img[i].number = z;
			z++;
		}
	}
	/*
	var span = menu.getElementsByTagName('span');	
	for (i=0; i<span.length;i++) {
		if (!span[i].outerHTML.match("_over.")) {
			span[i].onmouseover = function () {swapon(this)};
			span[i].onmouseout = function () {swapoff(this)};
			
			var img = span[i].outerHTML.substring((span[i].outerHTML.indexOf('src=')+5),(span[i].outerHTML.lastIndexOf('.png')+4));
			//var suffix = span[i].outerHTML.substring(span[i].outerHTML.lastIndexOf('.png'));
			mouseOut[z] = new Image();
			mouseOut[z].src=img;
			mouseOver[z] = new Image();
			mouseOver[z].src=img.substring(0,img.lastIndexOf('.')) + "_over" + img.substring(img.lastIndexOf('.'));
			span[i].number = z;
			z++;
		}
	}
	*/
}

function swapon(obj) {
	if (!obj)
		obj = this;
	if ((obj.filters) && (obj.filters.length > 0))
		obj.filters(0).src = mouseOver[obj.number].src;
	else
		obj.src = mouseOver[obj.number].src;
}

function swapoff(obj) {
	if (!obj)
		obj = this;
	if ((obj.filters) && (obj.filters.length > 0))
		obj.filters(0).src = mouseOut[obj.number].src;
	else
		obj.src = mouseOut[obj.number].src;
}

var str = 'uw email adres...';

function empty(obj) {
	if (obj.value == str)
		obj.value = '';
}

function fill(obj) {
	if (((obj.value.trim()).length) == 0)
		obj.value = str;
}

function ClassSlides() {
	this.CurrentImage = 0
	this.steps = 20
	this.timeout = false
	this.DoubleClickUrl = ''

	this.ClickThumb = function(n) {
		/*
		document.getElementById('Thumb'+this.CurrentImage).className = '';
		document.getElementById('Thumb'+n).className = 'on';
		this.CurrentImage = n
		this.From = document.getElementById('fotoscroll').scrollTop;
		this.To = n*83 - 166;
		this.DoStep(0);
		*/
		this.CurrentImage = n;
		document.getElementById('mainpic').src = Photos[n].replace('thumb_', '');
		document.getElementById('count').innerHTML = n+1+' / '+Photos.length;
	}

	this.DoStep = function(step) {
		step++;
		document.getElementById('fotoscroll').scrollTop = this.Factor(step / this.steps) * (this.To - this.From) + this.From;
		if (this.timeout)
			clearTimeout(this.timeout);
		if (step < this.steps) 
			this.timeout = setTimeout('Slides.DoStep(' + step + ')', 10);
	}

	this.Previous = function() {
		var Next = this.CurrentImage - 1;
		if (Next < 0) 
			Next = 0;
		this.ClickThumb(Next)
	}

	this.Next = function() {
		var Next = this.CurrentImage + 1;
		if (Next > Photos.length - 1) 
			Next = Photos.length - 1;
		this.ClickThumb(Next);
	}

	this.Factor = function(f) {
		return .5 - Math.cos(f * Math.PI) * .5;
	}

	this.Initialize = function() {
		if (document.getElementById('fotoscroll')) {
			var sHtml = '';
			for(var i=0; i<Photos.length; i++) {
				sHtml += '<a href="javascript:Slides.ClickThumb(' + i + ')"><img';
				sHtml += ' id="Thumb' + i + '" src="' + Photos[i] + '" alt="Foto"';
				if (i==0)
					sHtml += ' class=on'
				if (i==(Photos.length-1))
					sHtml += ' style="margin-bottom:0px;"';
				sHtml += ' /></a>';
			}
			document.getElementById('fotoscroll').innerHTML = sHtml;
			document.getElementById('mainpic').src = Photos[0].replace('thumb_', '');
			document.getElementById('count').innerHTML = '1 / '+Photos.length;
		} else
			setTimeout('Slides.Initialize()', 250);
	}
}

window.onload = init;
