/**********************
 * - www.umedia.nl    *
 **********************
 Dit document bevat JavaScript codering. 
 */

function str_replace (search, replace, subject, count) {
    // Replaces all occurrences of search in haystack with replace  
    // 
    // version: 909.322
    // discuss at: http://phpjs.org/functions/str_replace    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Gabriel Paderni
    // +   improved by: Philip Peterson
    // +   improved by: Simon Willison (http://simonwillison.net)
    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)    // +   bugfixed by: Anton Ongson
    // +      input by: Onno Marsman
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +    tweaked by: Onno Marsman
    // +      input by: Brett Zamir (http://brett-zamir.me)    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   input by: Oleg Eremeev
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Oleg Eremeev
    // %          note 1: The count parameter must be passed as a string in order    // %          note 1:  to find a global variable in which the result will be given
    // *     example 1: str_replace(' ', '.', 'Kevin van Zonneveld');
    // *     returns 1: 'Kevin.van.Zonneveld'
    // *     example 2: str_replace(['{name}', 'l'], ['hello', 'm'], '{name}, lars');
    // *     returns 2: 'hemmo, mars'    var i = 0, j = 0, temp = '', repl = '', sl = 0, fl = 0,
            f = [].concat(search),
            r = [].concat(replace),
            s = subject,
            ra = r instanceof Array, sa = s instanceof Array;    s = [].concat(s);
    if (count) {
        this.window[count] = 0;
    }
     for (i=0, sl=s.length; i < sl; i++) {
        if (s[i] === '') {
            continue;
        }
        for (j=0, fl=f.length; j < fl; j++) {            temp = s[i]+'';
            repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
            s[i] = (temp).split(f[j]).join(repl);
            if (count && s[i] !== temp) {
                this.window[count] += (temp.length-s[i].length)/f[j].length;}        }
    }
    return sa ? s : s[0];
}

// Document ready
$(document).ready(function()
{
	// jQuery toepassing voor het realiseren van het screen effect
    $("#header .screen").hide();
	$("#header .led").hide();
    $("#header .alignment").bind("mouseenter",function()
	{
		$("#header .screen").fadeIn(500);
		$("#header .led").fadeIn(500);
    }).bind("mouseleave",function()
	{
		$("#header .screen").fadeOut(500);
		$("#header .led").fadeOut(500);
    });
	
	// Geef de LIs van domeinnamen een classnaam
	$("#container #content .right .domains li:even").addClass("even");
	$("#container #content .right .domains li:odd").addClass("odd");
	
	// Geef de TD van een table een classname
	$("#container table tr:even").addClass("even");
	$("#container table tr:odd").addClass("odd");
	
	// Scrollt de browser rustig naar boven bij het klikken op de 'top' class
	$("#container #footer a.top").click(function()
	{
		$('html, body').animate({scrollTop:0}, 800);
	});	
	// E-mail protection
	$('a.jMail').each(function()
	{
		e = this.rel.replace('/','@');
		this.href = 'mailto:' + e;
		$(this).text(e);
	});
	
	// Bij een mouseenter schuift het bekijken clip in
    $("#container #content .left .item").bind("mouseenter",function()
	{
		$("#container #content .left .box.portfolio #" + $(this).attr('id') + "_clip").slideUp(200);
    }).bind("mouseleave",function()
	{
		$("#container #content .left .box.portfolio #" + $(this).attr('id') + "_clip").slideDown(150);
    });
	// We weergeven het identifier element die aangeeft wat er met het paneel moet gebeuren
	$("#container #identifier").show();
	$("#container #colorpallet").show();
	$("#container #colorpallet .text.opened").hide();
	// Wanneer er op de tekst van de paneel wordt geklikt
	$("#container #colorpallet .text").click(function()
	{
		// Als de identifier visible is
		if($("#container #identifier").is(":visible"))
		{
			$("#container #colorpallet .text.opened").show();
			$("#container #colorpallet .text.closed").hide();
			// Paneel open schuiven
			$("#container #identifier").hide();
			$("#container #colorpallet").animate({ 
			top: "40px"
			}, 800);
		// Als identifier hidden is
		} else if($("#container #identifier").is(":hidden"))
		{
			$("#container #colorpallet .text.opened").hide();
			$("#container #colorpallet .text.closed").show();
			// Paneel dicht schuiven
			$("#container #identifier").show();
			$("#container #colorpallet").animate({ 
			top: "-39px"
			}, 400);
		}
	});
	// Wanneer er wordt geklikt op een kleur example
	$("#container #colorpallet ul li img").click(function()
	{
		// URL voor kleur opslaan in de database
		var url = '../../ajax/ajax_savecolor.php?color=' + $(this).attr("alt") + '';
		
		// Kleur doormiddel van AJAX opslaan in de database
		xmlhttp.open("GET", "" + url + "",true);
		xmlhttp.onreadystatechange=function()
		{
			if(xmlhttp.readyState==4)
			{
				// Controleren of response text OK is
				if(xmlhttp.responseText == 'OK')
				{
				}
			}
		}
		xmlhttp.send(null);
		// Het content vak snel out faden en weer omlaag laten sliden
		$('html, body').animate({scrollTop:0}, 100);
		$("#container #content").fadeOut(100).slideDown(1000);
		$("#color").attr({ 
			href: "" + $(this).attr("title") + "/layout/colors/" + $(this).attr("alt") + "/style/stylesheet.css"
		});
	});
	// Message box contact formulier
	$("#container #content .left .messagebox").show();
	$("#container #messageboxidentifier").hide();
	$("#container #messageboxidentifier2").hide();
	// Wanneer er geklikt wordt op een input of textarea op de contact pagina
	$("#container .left .contact input, #container .left .contact textarea").focus(function()
	{
		// Als de identifier visible is
		if($("#container #messageboxidentifier").is(":visible"))
		{
			var subjectmessage = '';
			$("#container #content .left .messagebox p").hide().html(str_replace('[', '<span>', str_replace(']', ',</span>', $(this).attr('title')))).slideDown(400);
		// Als identifier hidden is
		} else if($("#container #messageboxidentifier").is(":hidden"))
		{
			$("#container #content .left .messagebox p").html(str_replace('[', '<span>', str_replace(']', ',</span>', $(this).attr('title'))));
			$("#container #content .left .messagebox").animate({
			left: "380px",
			top: "45px"
			}, 900);
			$("#container #messageboxidentifier").show();
			$("#container #messageboxidentifier2").hide();
		}
	});
	// Wanneer er geklikt wordt op een input of textarea op de contact pagina
	$("#container .left .callmeback input, #container .left .callmeback textarea").focus(function()
	{
		// Als de identifier visible is
		if($("#container #messageboxidentifier2").is(":visible"))
		{
			var subjectmessage = '';
			$("#container #content .left .messagebox p").hide().html(str_replace('[', '<span>', str_replace(']', ',</span>', $(this).attr('title')))).slideDown(400);
		// Als identifier hidden is
		} else if($("#container #messageboxidentifier2").is(":hidden"))
		{
			$("#container #content .left .messagebox p").html(str_replace('[', '<span>', str_replace(']', ',</span>', $(this).attr('title'))));
			$("#container #content .left .messagebox").animate({
			left: "380px",
			top: "580px"
			}, 900);
			$("#container #messageboxidentifier2").show();
			$("#container #messageboxidentifier").hide();
		}
	});
	// Wanner er geklikt wordt om de lightbox te openen
	$("#container .openlightbox").click(function()
	{
		$("#container #lightbox").fadeIn(600);
		$('html, body').animate({scrollTop:100}, 600);
	});
	
	// Captcha renew
	$('#container #content .captchaimg').mouseover(function() {
		// Captcha renew
		$('#container #content .captchaimg .renew').click(function()
		{
			$('#container #content .captchaimg').html('<a class="renew"></a><img src="/captcha/newcode.png?nocache=' + timestamp() + '" alt="Captcha code" />');
		});
	});
	$('#container .example input').attr('rel', '- tekens -');
	// Controleren of .example voorkomt
	if($('#container .example input').is(':visible'))
	{
		$('#container .example input').example(function()
		{
		  return $(this).attr('rel');
		});
	}

});

// Ajax HTTP request
var xmlhttp=false;
if (!xmlhttp && typeof XMLHttpRequest!='undefined')
{
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}

// Functie zorgt voor het sorteren van de rijen
function sorteerportfolio(id)
{
	// Request url
	var url = '../../ajax/ajax_portfolio_sortatie.php?id=' + id + '';
	
	// HTTPRequest
	xmlhttp.open("GET", "" + url + "",true);
	xmlhttp.onreadystatechange=function() {
		if(xmlhttp.readyState==4)
		{
			// Controleren of response text OK is
			if(xmlhttp.responseText == 'OK')
			{
				renewcontentportfolio();
			} else 
			{
				alert('Fout: Ajax request failed to give an OK');
			}
		}
	}
	xmlhttp.send(null);
}

// Vernieuwd het content op de admin pagina bij een onmouseup
function renewcontentportfolio()
{
	// Nieuwe inhoud in DIV plaatsen
	// Request url
	var url = '../../ajax/ajax_portfolio_parse-table.php';
	
	// HTTPRequest
	xmlhttp.open("GET", "" + url + "",true);
	xmlhttp.onreadystatechange=function() {
		if(xmlhttp.readyState==4)
		{
			document.getElementById('portfoliotable').innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(null);
}

// Functie zorgt voor het sorteren van de rijen
function sorteerdomeinen(id)
{
	// Request url
	var url = '../../ajax/ajax_domeinen_sortatie.php?id=' + id + '';
	
	// HTTPRequest
	xmlhttp.open("GET", "" + url + "",true);
	xmlhttp.onreadystatechange=function() {
		if(xmlhttp.readyState==4)
		{
			// Controleren of response text OK is
			if(xmlhttp.responseText == 'OK')
			{
				renewcontentdomeinen();
			} else 
			{
				alert('Fout: Ajax request failed to give an OK');
			}
		}
	}
	xmlhttp.send(null);
}

// Vernieuwd het content op de admin pagina bij een onmouseup
function renewcontentdomeinen()
{
	// Nieuwe inhoud in DIV plaatsen
	// Request url
	var url = '../../ajax/ajax_domeinen_parse-table.php';
	
	// HTTPRequest
	xmlhttp.open("GET", "" + url + "",true);
	xmlhttp.onreadystatechange=function() {
		if(xmlhttp.readyState==4)
		{
			document.getElementById('domaintable').innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(null);
}

// Functie localiseert je naar een locatie
function locatie(url)
{
	window.location.href = url;	
}

// Opslaan van een nieuwe view
function newview(id)
{
	// Nieuwe inhoud in DIV plaatsen
	// Request url
	var url = '/ajax/ajax_newview.php?id=' + id + '';
	
	// HTTPRequest
	xmlhttp.open("GET", "" + url + "",true);
	xmlhttp.onreadystatechange=function() {
		if(xmlhttp.readyState==4)
		{
		}
	}
	xmlhttp.send(null);
}

// Geeft als output een timestamp
function timestamp()
{
  return Math.round(new Date().getTime() / 1000) + 1;
}