function addMojoYoutubeTo(youtubecode, divId) {
	var divElem = document.getElementById(divId);	
	if (!pntIsDefined(divElem)) return;
	var autoplay = arguments[2];
	if (!pntIsDefined(autoplay)) autoplay = '1';	
	
	var width = arguments[3];
	if (!pntIsDefined(width)) width = '560';	
	
	var height = arguments[4];
	if (!pntIsDefined(height)) height = '340';	
	
	var strTag = '<object width="'+width+'" height="'+height+'"><param name="movie" value="http://www.youtube.com/v/'+youtubecode+'&hl=nl_NL&fs=1&autoplay='+autoplay+'"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'+youtubecode+'&hl=nl_NL&fs=1&autoplay='+autoplay+'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="'+width+'" height="'+height+'"></embed></object>';
	divElem.innerHTML = strTag;
}
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 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()
{
		window.open(this.href);
		return false;
}

function mojoOpenWindowForHref(href) //niet weer weggooien
{
		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();
	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 pntGetRequestParam(key)
{
	requestData = pntGetRequestData();
	try 
	{
		var value = requestData[key];
	}
	catch (E)
	{
		return '';
	}
	if (value) return value;
	return '';
}

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;
}
pntAppendToInit(mojoAppendEditIconIfNeeded);


var mojoVideos = new Array();

function processVideos() {

	for ( i = 0; i < mojoVideos.length; i++ ) {
		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.stretching  = "fill";
		flashvars.fullscreen  = "true";
		swfobject.embedSWF(pntAppUrl+'flashplayer/player.swf', mojoVideo.id, mojoVideo.width, mojoVideo.height, "9.0.0", pntAppUrl+"flashplayer/expressInstall.swf", flashvars);
	}
}

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( function() { if (typeof(swfobject)!='undefined') {processVideos(); } } );


