////////// wisselende kleuren

var palet1 = new Array('#FC3604','#FCBE04','#FC3604','#FCBE04','#FC3604');
var palet2 = new Array('#2A1C0E','#372511','#472F15','#000');
var palet3 = new Array('#E93010','#F54423');
var palet4 = new Array('#2A1C0E','#372511','#472F15');


for (i=1;i<=4;i++){ // aanpassen aan aantal vlakken
	eval('kleurdiv' + i + ' = document.body.appendChild(document.createElement("div"))'); // maak
	eval('kleurdiv' + i + '.className = "kleur k' + i + '"'); // geef class (voor css)
	eval('kleurdiv' + i + '.id = "kd' + i + '"');
	eval('nuK' + i + ' = 1');
	eval('paletnuK' + i + ' = 1');
}
loopK();


function loopK(){
	timer1 = window.setInterval('doeK(1)', 6000); // wisselfrequentie: 500 = 1 sec.
	timer2 = window.setInterval('doeK(2)', 4000);
	timer3 = window.setInterval('doeK(3)', 2000);
	timer4 = window.setInterval('doeK(4)', 8000);
}


function doeK(welke){
	eval('nuK' + welke + '++');
	eval('if (nuK' + welke + '== palet' + welke + '.length) nuK' + welke + ' = 0');
	eval('kleurdiv' + welke + '.style.background = palet' + welke + '[nuK' + welke + ']');
}








////////// statische foto's rechts (random per pagina)

var fotoosro = new Array('big1.jpg','big2.jpg','big3.jpg','big4.jpg','big5.jpg','big6.jpg','big7.jpg','big8.jpg');
var randomF = Math.floor(Math.random() * fotoosro.length); // random foto uit array
staticF = document.body.appendChild(document.createElement('img'));
staticF.className = 'staticfoto';
staticF.src = path + '/src/cycle/' + fotoosro[randomF];







////////// wisselende foto's links, schakelen

var fotoos = new Array('cycle.jpg','cycle1.jpg','cycle2.jpg','cycle3.jpg','cycle4.jpg','cycle5.jpg','cycle6.jpg','cycle7.jpg');
var fotoL  = new Array();


function bewaar(waarde){ // set cookie
	var date = new Date();
	date.setTime(date.getTime()+(100*24*60*60*1000));
	var verloopt = '; verloopt = ' + date.toGMTString();
	document.cookie = 'LP = ' + waarde + verloopt + '; path=' + path;
}

function vervolgF(){ // get cookie
	var NuF = 'LP' + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i<ca.length;i++){
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(NuF) == 0) return c.substring(NuF.length,c.length);
	}
	return null;
}

function startF(){
	cookieNum = 0;
	nuF = 0;
	if (vervolgF()) nuF = vervolgF(); // ga verder waar gebleven, indien mogelijk
	wisselF = document.body.appendChild(document.createElement('img'));
	wisselF.className = 'wisselfoto';
	wisselF.src = path + '/src/cycle/' + fotoos[nuF];
	timer4 = window.setInterval('doeF()', 5000); // wisselfrequentie
}

function doeF(welke){ // wisselt foto
	nuF++;
	if (nuF == fotoos.length) nuF = 0;
	wisselF.src = path + '/src/cycle/' + fotoos[nuF];

	if (!fotoL[nuF] != 1){ // laadt alvast de volgende foto
		if (nuF < fotoos.length){
			pic = new Image(150,300);
			pic = path + '/src/cycle/' + fotoos[nuF+1];
		}
		fotoL[nuF] = 1;
	}

	bewaar(nuF); // bewaart laatste foto in cookie
}

startF();





////////// textopmaak <textarea>

function storeCursor(el){
	if (document.all && el.createTextRange) el.cursorPos = document.selection.createRange().duplicate();
}


function addt(text,desc){

	var target = document.getElementById('textarea');

	var selectxt = '';

	if (desc != ''){

		if (!document.all && typeof target.selectionStart != 'undefined'){
			var sel0 = target.selectionStart;
			var sel1 = target.selectionEnd;
			selectxt = target.value.substr(sel0,sel1-sel0);
		}

		else if (window.getSelection) selectxt = window.getSelection();
		else if (document.getSelection) selectxt = document.getSelection();
		else if (document.selection) selectxt = document.selection.createRange().text;

		if (text.indexOf('http://') != -1){
			var url = prompt('Vul de URL in.\n\n','http://');
			if (!url) url = 'http://';
			text = text.replace('http://',url);

			if (!selectxt) var custom = prompt('Vul de omschrijving in.\n\n',url);
			else var custom = prompt('Vul de omschrijving in.\n\n',selectxt);
			if (!custom) custom = '';
			text = text.replace('omschrijving',custom);
		}

		else {
			var custom = prompt('Vul de tekst in die ' + desc + ' moet worden.\n\n',selectxt);
			if (!custom) custom = '';
			text = text.replace('text',custom);
		}

	}

	if (target){
		if (document.all && target.cursorPos){
			var cursorPos = target.cursorPos;
			cursorPos.text = cursorPos.text.charAt(cursorPos.text.length - 1) == ' ' ? text + ' ' : text;
		}

		else if (typeof target.selectionStart != 'undefined'){
			var sStart = target.selectionStart;
			var sEnd = target.selectionEnd;
			target.value = target.value.substr(0, sStart) + text + target.value.substr(sEnd, target.value.length);
			target.selectionStart = sStart == sEnd ? sStart + text.length : sStart;
			target.selectionEnd = sStart + text.length;
		}

		else target.value += text;
		target.focus();
	}
}

////////// no spam mail
function nospam(host,user){
	host = host.substr(5,host.length-5);
	window.open('mailto:'+user+'@'+host);
}

////////// popup
window.onload = popupfunc;
function popupfunc(){
	var x = document.getElementsByTagName('a');
	for (var i=0;i<x.length;i++){
		if (x[i].getAttribute('rel') == 'popup'){
			x[i].onclick = function(){
				return doepop(this.href)
			}
			x[i].title = 'popup';
		}
	}

	function doepop(url){
		newwindow = window.open(url,'mp3','toolbar=0,scrollbars=0,location=0,statusbar=1,menubar=0,resizable=1,width=400,height=300,left=212,top=159');
		if (window.focus) newwindow.focus();
		return false;
	}

}