function pntAppendToInit(appendFunc)
{
	var orgFunc;
	orgFunc = pntExtraInitFunctions;
	var anomFunction = function()
	{		
		orgFunc.call();
		appendFunc.call();		
	};
	pntExtraInitFunctions = anomFunction;
}

function pntExtraInitFunctions() {
	// attach additional functions by using: pntAppendToInit(funcName); in your scripts.
}

function pntAddToClassName(elem, strClassName)
{
	if (!elem) return;
	var classNames = elem.className.split(' ');
	classNames[classNames.length] = strClassName;
	elem.className = classNames.join(' ');	
}

function pntRemoveFromClassName(elem, strClassName)
{
	if (!elem) return;
	var classNames = elem.className.split(' ');
	var newClassNames = new Array();
	for (var i in classNames)
	{
		var className = classNames[i];
		if (className!=strClassName) newClassNames[newClassNames.length] = className;
	}	
	elem.className = newClassNames.join(' ');	
}

function pntAppendElementEventHandler(elem,eventName,eventHandler)
{	
	var thisScope = arguments[3];
	var currentEventHandler = elem[eventName];
	if (!currentEventHandler) {
		elem[eventName] = eventHandler;
		return;
	}
	var anomFunction = function()
	{		
		currentEventHandler.call(elem);
		if (!pntIsDefined(thisScope)) thisScope = elem;
		eventHandler.call(thisScope);
	}
	elem[eventName] = anomFunction;
}




document.getElementsByClassName = function (needle) 
{ 
    if (typeof(needle)!='string') return new Array();    
    var s = [document.documentElement || document.body], i = 0, r = [], l = 0, e; 
    var re = new RegExp('(^|\\s)' + needle + '(\\s|$)'); 

    do 
    { 
        e = s[i]; 

        while (e) 
        { 
            if (e.nodeType == 1) 
            { 
                if (e.className && re.test(e.className)) r[l++] = e; 

                s[i++] = e.firstChild; 
            } 

            e = e.nextSibling; 
        } 
    } 
    while (i--); 
		r.reverse();
    return r; 
}

function processVideos() {
	for (var i in mojoVideos)
	{
		var mojoVideo = mojoVideos[i];
		var flashvars = {};
		flashvars.file = mojoVideo.file;
		flashvars.image = mojoVideo.image;
		flashvars.width = mojoVideo.width;
		flashvars.height = mojoVideo.height;
		flashvars.bufferlength = 3;
		flashvars.fullscreen  = "true";
		
		swfobject.embedSWF(pntAppUrl+'bf/flashplayer/player.swf', mojoVideo.id, mojoVideo.width, mojoVideo.height, "9.0.0", pntAppUrl+"bf/flashplayer/expressInstall.swf", flashvars);
	}
}

pntAppendToInit( function() { if (typeof(swfobject)!='undefined') {processVideos(); } } );



function pntFlip(obj) {
	if (obj.className.match('active')) {
		pntRemoveFromClassName(obj, 'active');
	} else {
		pntAddToClassName(obj,'active');
	}
}

function pntFlipOut()
{
	if (typeof(pntFlip)=='undefined') return;
	if (this.mouzed) pntFlip(this);
}

function pntFlipOver()
{
		if (typeof(pntFlip)=='undefined') return;
		this.mouzed = true;
		pntFlip(this);	
}
function pntInitFlips()
{
	pntFlips = document.getElementsByClassName("pntFlip"); 
	
	for(var i=0;i<pntFlips.length;i++) {
		pntFlips[i].onmouseover = pntFlipOver;
		pntFlips[i].onmouseout = pntFlipOut;
	}		
}

pntAppendToInit( pntInitFlips );



function pntAddStyleSheetToHead(strUrl)
{

		var pntCssLink;
		pntCssLink = document.createElement('link');
		pntCssLink.type = "text/css";
		pntCssLink.rel = "stylesheet";		
		pntCssLink.href=strUrl;
		pntCssLink.media = "screen";		
		
		var firstHeadElem = document.getElementsByTagName("head")[0];
		if (!pntIsDefined(firstHeadElem)) return;	
		
		firstHeadElem.appendChild(pntCssLink);
		
	
}

function pntAddScriptToHead(strUrl)
{
	
	var pntScriptSrc;
	pntScriptSrc = document.createElement('script');
	pntScriptSrc.type = "text/javascript";
	pntScriptSrc.src= strUrl;
	
	var firstHeadElem = document.getElementsByTagName("head")[0];
	if (!pntIsDefined(firstHeadElem)) return;	
	firstHeadElem.appendChild(pntScriptSrc);
}

function pntIsDefined(elem)
{
	if ((!elem) || (typeof(elem)=="undefined")) return false;
	return true;
}



function init() {		
	mojoFixExternalLinks();
	pntExtraInitFunctions();
	mojoDoStat();
}


if (document.addEventListener) {
	document.addEventListener("DOMContentLoaded", init, false);
} else {
  document.onreadystatechange = function() {
  	if (this.readyState == "complete") {
			init();
  	}
 	}
}


function mojoFixExternalLinks()
{
	var elems = document.getElementsByClassName('mojo-extern-link');
	for (var i in elems)
	{
		var elem = elems[i];			
		if ((typeof(elem)=='object') && (elem.tagName) && (elem.tagName.toLowerCase() == 'a')) 	{			
			elem.onclick = mojoOpenHrefInNewWindow;
		}
	}
}

function mojoOpenHrefInNewWindow()
{		
		mojoOpenWindowForHref(this.href)
		return false;
}

function mojoOpenWindowForHref(href)
{
		window.open(href);
		return; //return geen window obj, zodat deze functie vanuit links aangeklikt kan worden
}


function mojoDoStat()
{
	if (pntGetRequestParam('offset') > 0) return;
	
	var ref = encodeURIComponent(document.referrer);
	var ua = encodeURIComponent(navigator.userAgent);
	var strUrl = pntAppUrl+'index.php?pntType=MojoStatHit&pntHandler=RegisterAction';
	var zoeken = pntGetRequestParam('zoeken');
			
	strUrl+= '&referrer='+ref;
	strUrl+= '&ua='+ua;
	strUrl+= '&mojoObjectId='+mojoObjectId;
	strUrl+= '&'+ new Date().getTime();
	if (pntIsDefined(zoeken)) strUrl+= '&zoeken='+zoeken;
	
	var img = document.createElement('img');
	img.src = strUrl;	
	img.style.display='none';
	document.body.appendChild(img);
}


function pntGetRequestData()
{	
  FORM_DATA = new Object();
    // The Object ("Array") where our data will be stored.
  separator = ',';
    // The token used to separate data from multi-select inputs
  query = '' + this.location;
  qu = query
    // Get the current URL so we can parse out the data.
    // Adding a null-string '' forces an implicit type cast
    // from property to string, for NS2 compatibility.
  query = query.substring((query.indexOf('?')) + 1);
    // Keep everything after the question mark '?'.
  if (query.length < 1) { return false; }  // Perhaps we got some bad data?
  keypairs = new Object();
  numKP = 1;
    // Local vars used to store and keep track of name/value pairs
    // as we parse them back into a usable form.
  while (query.indexOf('&') > -1) {
    keypairs[numKP] = query.substring(0,query.indexOf('&'));
    query = query.substring((query.indexOf('&')) + 1);
    numKP++;
      // Split the query string at each '&', storing the left-hand side
      // of the split in a new keypairs[] holder, and chopping the query
      // so that it gets the value of the right-hand string.
  }
  keypairs[numKP] = query;
    // Store what's left in the query string as the final keypairs[] data.<
  for (i in keypairs) {
    keyName = keypairs[i].substring(0,keypairs[i].indexOf('='));
      // Left of '=' is name.
    keyValue = keypairs[i].substring((keypairs[i].indexOf('=')) + 1);
      // Right of '=' is value.
    while (keyValue.indexOf('+') > -1) {
      keyValue = keyValue.substring(0,keyValue.indexOf('+')) + ' ' + keyValue.substring(keyValue.indexOf('+') + 1);
        // Replace each '+' in data string with a space.
    }
    keyValue = unescape(keyValue);
      // Unescape non-alphanumerics
    if (FORM_DATA[keyName]) {
      FORM_DATA[keyName] = FORM_DATA[keyName] + separator + keyValue;
        // Object already exists, it is probably a multi-select input,
        // and we need to generate a separator-delimited string
        // by appending to what we already have stored.
    } else {
      FORM_DATA[keyName] = keyValue;
        // Normal case: name gets value.
    }
  }
  return FORM_DATA;
}
function pntInspect(what) {
    var output = '';
    for (var i in what)
        output += i+ ' = ' + what[i] + '\r\n';
    return(output);
}
function pntGetRequestParam(key)
{
	requestData = pntGetRequestData();
	try 
	{
		var value = requestData[key];
	}
	catch (E)
	{
		return null;
	}
	if (value) return value;
	return null;
}

function pntGetCookie (name) {
   // first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

function mojoAppendEditIconIfNeeded()
{
	if (!pntIsDefined(mojoObjectId)) return;
	if (!pntIsDefined(pntAppUrl)) return;
	
	var cookieName = 'mojoLoggedOn-'+pntAppUrl.replace(/\/site\//, '/beheer/');	

	var cookieValue = pntGetCookie(cookieName);	
	if (!pntIsDefined(cookieValue)) return;	
	var editDiv = mojoGetEditDiv();
	if (!pntIsDefined('editDiv')) return;
	
	var bodies = document.getElementsByTagName('body');
	var body = bodies[0];
	body.appendChild(editDiv);
}

function mojoGetEditDiv()
{
	if (!pntIsDefined(pntAppUrl)) return;
	if (!pntIsDefined(mojoObjectId)) return;
	var editDiv = document.createElement('div');
	var strUrl  = pntAppUrl.replace(/\/site\//, '/beheer/')+'index.php?pntType=MojoObject&pntHandler=EditDetailsPage&id='+mojoObjectId;	
	editDiv.id = 'mojoEditDiv';
	editDiv.innerHTML = '<a href="javascript:mojoOpenWindowForHref(\''+strUrl+'\');" title="Bewerk deze pagina in Mojo CMS"></a>';	
	return editDiv;
}

String.prototype.ucfirst = function()
{   
    var f = this.charAt(0).toUpperCase();
    return f + this.substr(1);
}

String.prototype.ucwords = function()
{   
	return (this+'').replace(/^(.)|\s(.)/g, function ( $1 ) { return $1.toUpperCase ( ); } );
}

String.prototype.trim = function()
{
	var l=0; var r=this.length -1;
	while(l < this.length && this[l] == ' ')
	{	l++; }
	while(r > l && this[r] == ' ')
	{	r-=1;	}
	return this.substring(l, r+1);
}


pntAppendToInit(mojoAppendEditIconIfNeeded);

function swapAdvTripText(blockname, type){
	titel = document.getElementById(blockname+'Titel');
	titelHover = document.getElementById(blockname+'TitelHover');
	leesverder = document.getElementById(blockname+'Leesverder');
	leesverderHover = document.getElementById(blockname+'LeesverderHover');
	if(type=='over') {
		titel.style.display = 'none';
		leesverder.style.display = 'none';
		titelHover.style.display = 'block';
		leesverderHover.style.display = 'block';
	} else {
		titel.style.display = 'block';
		leesverder.style.display = 'block';
		titelHover.style.display = 'none';
		leesverderHover.style.display = 'none';
	}	
}
function activateImage(div) {
	imgs = div.getElementsByTagName('img');
	if (imgs[0].src.match("icongroot")) return;
	imgs[0].src =  imgs[0].src.replace("icon", "icongroot");
	imgs[imgs.length-1].src =  imgs[imgs.length-1].src.replace("leesverder", "leesverder-active");
}

function deActivateImage(div) {
	imgs = div.getElementsByTagName('img');
	imgs[0].src =  imgs[0].src.replace("icongroot", "icon");
	imgs[imgs.length-1].src =  imgs[imgs.length-1].src.replace("leesverder-active","leesverder");
}

function getDatum(hoursPlus) {
	var str = "";
	var d = new Date()
	var h = d.getHours();
	d.setHours(h+hoursPlus);
		
	var h = d.getHours();
	if (h<10) str += '0';
	str += h;
	str += ".";
	var min = d.getMinutes();
	if (min<10) str += '0';
	str += d.getMinutes();
	str += ' uur, ';
	
	var n = d.getDate();
	if (n<10) str += '0';
	str += n;
	
	str += "-";
	
	var m = d.getMonth() + 1;
	if (m<10) str += '0';
	str += m;
	
	str += "-";
	var y = d.getFullYear().toString();
	var short = y.substr(2,2);
	str += short;
	return str;
}

function showDates() {
	document.getElementById('tijd1').innerHTML = getDatum(0);
	document.getElementById('tijd2').innerHTML = getDatum(-6);
	document.getElementById('tijd3').innerHTML = getDatum(+1);
	document.getElementById('tijd4').innerHTML = getDatum(+7);
}
pntAppendToInit(showDates);var oMarquees = [], oMrunning,
	oMInterv =        7,     //interval between increments
	oMStep =          1,      //number of pixels to move between increments
	oStopMAfter =     0,     //how many seconds should marquees run (0 for no limit)
	oResetMWhenStop = false;  //set to true to allow linewrapping when stopping



function doMStop() {
	clearInterval(oMrunning);
	for( var i = 0; i < oMarquees.length; i++ ) {
		oDiv = oMarquees[i];
		oDiv.mchild.style.left = '0px';
		if( oResetMWhenStop ) {
			oDiv.mchild.style.cssText = oDiv.mchild.style.cssText.replace(/;white-space:nowrap;/g,'');
			oDiv.mchild.style.whiteSpace = '';
			oDiv.style.height = '';
			oDiv.style.overflow = '';
			oDiv.style.position = '';
			oDiv.mchild.style.position = '';
			oDiv.mchild.style.top = '';
		}
	}
	oMarquees = [];
}
function doDMarquee() {
	if( oMarquees.length || !document.getElementsByTagName ) { return; }
	var oDivs = document.getElementsByTagName('div');
	for( var i = 0, oDiv; i < oDivs.length; i++ ) {
		oDiv = oDivs[i];
		if( oDiv.className && oDiv.className.match(/\bdmarquee\b/) ) {
			if( !( oDiv = oDiv.getElementsByTagName('div')[0] ) ) { continue; }
			if( !( oDiv.mchild = oDiv.getElementsByTagName('div')[0] ) ) { continue; }
			oDiv.mchild.style.cssText += ';white-space:nowrap;';
			oDiv.mchild.style.whiteSpace = 'nowrap';
			oDiv.style.height = oDiv.offsetHeight + 'px';
			oDiv.style.overflow = 'hidden';
			oDiv.style.position = 'relative';
			oDiv.mchild.style.position = 'absolute';
			oDiv.mchild.style.top = '0px';
			oDiv.mchild.style.left = oDiv.offsetWidth + 'px';
			oMarquees[oMarquees.length] = oDiv;
			i += 2;
		}
	}
	oMrunning = setInterval('aniMarquee()',oMInterv);
	if( oStopMAfter ) { setTimeout('doMStop()',oStopMAfter*1000); }
}
function aniMarquee() {
	var oDiv, oPos;
	for( var i = 0; i < oMarquees.length; i++ ) {
		oDiv = oMarquees[i].mchild;
		oPos = parseInt(oDiv.style.left);
		if( oPos <= -1 * oDiv.offsetWidth ) {
			oDiv.style.left = oMarquees[i].offsetWidth + 'px';
		} else {
			oDiv.style.left = ( oPos - oMStep ) + 'px';
		}
	}
}
if( window.addEventListener ) {
	window.addEventListener('load',doDMarquee,false);
} else if( document.addEventListener ) {
	document.addEventListener('load',doDMarquee,false);
} else if( window.attachEvent ) {
	window.attachEvent('onload',doDMarquee);
}


