smilies_tag = new Array(':)', ';)', ':D', ';D', '>:(', ':(', ':o', '8)', '???', '::)', ':P', ':-[', ':-X', ':-*', ':huilen:', ':lol:');
smilies_name = new Array('smiley', 'wink', 'cheesy', 'grin', 'angry', 'sad', 'shocked', 'cool', 'huh', 'rolleyes', 'tongue', 'embarassed', 'lipsrsealed', 'kiss', 'cry', 'laugh');
smilies_filled = false;

function Focus()
{
	document.gastenboek.bericht.focus();
}

function Selectie()
{
	return document.selection.createRange();
}

function Doel(t)
{
	if(t) return document.getElementById(t);
	else return document.gastenboek.bericht;
}

function zet_tag(v)
{
	if (document.selection == null)
	{
		Doel().value += "[" + v + "][/" + v + "]";
		return;
	}
	str = Selectie().text;
	Focus();
	sel = Selectie();
	sel.text = "[" + v + "]" + str + "[/" + v + "]";
	return;
}

function zet_url()
{
	if (document.selection == null)
	{
		url = prompt("Naar welke site wil je linken? Voer de URL hieronder in.", "http://");
		str = prompt("Welke tekst wil je in plaats van de link laten zien?", "");
		Doel().value += "[url=" + url + "]" + str + "[/url]";
		return;
	}
	str = Selectie().text;
	Focus();
	url = prompt("Naar welke site wil je linken? Voer de URL hieronder in.", "http://");
	if (url != null)
	{
		sel = Selectie();
		if (str == '')
		{
			str = prompt("Welke tekst wil je in plaats van de link laten zien?", "");
		}
		sel.text = "[url=" + url + "]" + str + "[/url]";
	}
}

function zet_img()
{
	if (document.selection == null)
	{
		url = prompt("Voer de URL van het plaatje hieronder in.", "http://");
		Doel().value += "[img]" + url + "[/img]";
		return;
	}
	Focus();
	url = prompt("Voer de URL van het plaatje hieronder in.", "http://");
	if (url != null)
	{
		sel = Selectie();
		sel.text = "[img]" + url + "[/img]";
	}
}

function toondialoog(val)
{
	toondialoog[val] = (toondialoog[val]) ? false : true;
	Doel(val).style.visibility = (toondialoog[val]) ? 'visible' : 'hidden';
}

function toon_smilies()
{
	zet_smilies();
	toondialoog('kies_smiley');
}

function zet_smilies() 
{
	if(!smilies_filled)
	{
		for(var i=0;i<smilies_tag.length;i++) 
		{
			Doel('kies_smiley').innerHTML += '<a href="#" onClick="voegsmileyin(\''+smilies_tag[i]+'\');"><img src="'+smiliesurl+smilies_name[i]+'.gif" border="0" style="padding:2px;"/></a>';
		}
	}
	return smilies_filled = true;
}

function voegsmileyin(id)
{
	toondialoog('kies_smiley');
	if (document.selection == null)
	{
		Doel().value += id;
		return;
	}
	Focus();
	Selectie().text = id;
	return;
}

if((/MSIE 5.0/.test(navigator.userAgent)))
	isIe5 = true;
else
	isIe5 = false;

Function.prototype.bind = function(obj)
{
	var o = this;
	return function()
	{
		return o.apply(obj, arguments);
	}
}
var fx = new Object();
fx.trans = function() {}
fx.trans.prototype =
{
	init: function(el, options)
	{
		this.el = document.getElementById(el);
		this.el.style.overflow = "hidden";
		this.iniWidth = this.el.offsetWidth;
		this.iniHeight = this.el.offsetHeight;
		this.options = options;
	},
	increase: function()
	{
		this.el.style.height = this.now + "px";
	},
	toggle: function()
	{
		if (this.el.offsetHeight > 0)
			this.custom(this.el.offsetHeight, 0);
		else
			this.custom(0, this.el.scrollHeight);
		return false;
	},
	step: function()
	{
		var time  = (new Date).getTime();
		if (time >= this.options.duration+this.startTime)
		{
			this.now = this.to;
			clearInterval (this.timer);
			this.timer = null;
		}
		else
		{
			var Tpos = (time - this.startTime) / (this.options.duration);
			this.now = ((-Math.cos(Tpos*Math.PI)/2) + 0.5) * (this.to-this.from) + this.from;
		}
		this.increase();
	},
	custom: function(from, to)
	{
		if (this.timer != null) return;
		this.from = from;
		this.to = to;
		this.startTime = (new Date).getTime();
		this.timer = setInterval (this.step.bind(this), 13);
		},
	hide: function()
	{
		if(!document.getElementById('error')) {
		this.now = 0;
		this.increase();
	}
	},
	clearTimer: function()
	{
		clearInterval(this.timer);
		this.timer = null;
	}
}

function init()
{
	if(isIe5) return;
	ib = new fx.trans();
	ib.init('berichtlayer',{duration:500});
	ib.hide();
}
