/*== Prototypes ==*/
String.prototype.rev = function()
{
	return this.split('').reverse().join('');
};


/*= replaceLast(string,'to replace','to replace with'); =*/
function replaceLast(s,from,to)
{
	return s.rev().replace(new RegExp(from.rev()),to.rev()).rev();
};
/*= =*/

/*== ==*/

/*== Check undefineds==*/
if (!timeOut)
{
	var timeOut = false;
}
if (!googleMapsAvailable)
{
	var googleMapsAvailable = false;
}
if (!language)
{
	var language = "Nederlands";
}
if (!themeId)
{
	var themeId = "";
}
if (!themeName)
{
	var themeName = "";
}
if (!crumbPath_themeIds)
{
	var crumbPath_themeIds = "";
}
if (!crumbPath_themeNames)
{
	var crumbPath_themeNames = "";
}
if (!pageId)
{
	var pageId = "";
}
if (!pageName)
{
	var pageName = "";
}
/*== ==*/

/*== Cookie scripts ==*/
function createCookie( name, value, expires, path, domain, secure )
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	
	/*
	if the expires variable is set, make the correct
	expires time, the current script below will set
	it for x number of days, to make it for hours,
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )
	{
	expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	
	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
	( ( path ) ? ";path=" + path : "" ) +
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

// this fixes an issue with the old method, ambiguous values
// with this test document.cookie.indexOf( name + "=" );
function readCookie( check_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 == check_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;
	}
}
/*== ==*/

/*== HideEmptyImages ==*/
function HideEmptyImages()
{	
	var regex_1 = new RegExp("(shownoimg)\.gif$");
	var regex_2 = new RegExp("(spacer)\.gif$");
	var regex_3 = new RegExp("(dot)\.gif$");
	
	for (var i=0; i < document.images.length; i++)
	{
		if (regex_1.test(document.images[i].src) || regex_2.test(document.images[i].src) || regex_3.test(document.images[i].src))
		{
			document.images[i].style.display = "none";
		}
	}
}
/*== ==*/

/*== Kruimelpad script (Vanaf Updater 9 SP3 en hoger)  indien lager, dit script uitcommentariseren==*/
function createCrumbPathAt(id)
{
	if (document.getElementById(id) && crumbPath_themeNames && crumbPath_themeIds && themeName && pageName && pageId)
	{
		crumbPath_themeNames = crumbPath_themeNames.replace(/[ ][(]NIET VERWIJDEREN[)]/g,"");
		pageName = pageName.replace(/[ ][(]NIET VERWIJDEREN[)]/g,"");
		themeName = themeName.replace(/[ ][(]NIET VERWIJDEREN[)]/g,"");
		
		crumbPath_themeNames = crumbPath_themeNames.replace(/\* Modules/g,"");
		pageName = pageName.replace(/\* Modules/g,"");
		themeName = themeName.replace(/\* Modules/g,"");
		
		crumbPath_themeNames = crumbPath_themeNames.replace(/^~/,"");
		crumbPath_themeNames = crumbPath_themeNames.replace(/~$/,"");
		
		crumbPath_themeIds = crumbPath_themeIds.replace(/^~/,"");
		crumbPath_themeIds = crumbPath_themeIds.replace(/~$/,"");
		
		var printableNavigation = '';
		var objectToPlaceCrumbpath = document.getElementById(id);
		
		var crumbPath_themeIds_Array = crumbPath_themeIds.replace(/^~/,"");
		crumbPath_themeIds_Array = crumbPath_themeIds.replace(/~$/,"");
		
		var crumbPath_themeIds_Array = crumbPath_themeIds.split(/~/);
		var crumbPath_themeNames_Array = crumbPath_themeNames.split(/~/);
		
		for (var i=0; i<crumbPath_themeIds_Array.length; i++)
		{
			if (crumbPath_themeIds_Array[i] == "")
			{
				crumbPath_themeNames_Array.splice(i,1);
				crumbPath_themeIds_Array.splice(i,1);
			}
			if (crumbPath_themeNames_Array[i-1] && crumbPath_themeNames_Array[i])
			{
				if (crumbPath_themeNames_Array[i-1] == crumbPath_themeNames_Array[i])
				{
					crumbPath_themeNames_Array.splice(i,1);
					crumbPath_themeIds_Array.splice(i,1);
				}
			}
			if (crumbPath_themeNames_Array[i])
			{
				if (crumbPath_themeNames_Array[i] == "")
				{
					crumbPath_themeNames_Array.splice(i,1);
					crumbPath_themeIds_Array.splice(i,1);
				}
				else if (crumbPath_themeNames_Array[i].match(/#/) || crumbPath_themeNames_Array[i].match(/Home/))
				{
					crumbPath_themeNames_Array.splice(i,1);
					crumbPath_themeIds_Array.splice(i,1);
				}
			}
		}
		
		printableNavigation += '<a class="first" href="/">Home</a>';
		
		for (var j=0; j<crumbPath_themeNames_Array.length; j++)
		{
			if (j == 0)
			{
				crumbPath_themeNames_Array[j] = crumbPath_themeNames_Array[j].replace(/NEW/,"CaseWare");
				
				// Voeg alle (sub) thema's toe aan een verzameling met links, evt. opbouw kan hier worden gewijzigd
				printableNavigation += '<a href="/cms/publish/content/showpage.asp?themeid='+crumbPath_themeIds_Array[j]+'">'+crumbPath_themeNames_Array[j]+'</a>';
			}
			else if (j == crumbPath_themeNames_Array.length-1)
			{
				if (pageName == themeName && themeId == crumbPath_themeIds_Array[crumbPath_themeIds_Array.length-1])
				{
					// Voeg alle (sub) thema's toe aan een verzameling met links, evt. opbouw kan hier worden gewijzigd
					printableNavigation += '<a class="last" href="/cms/publish/content/showpage.asp?themeid='+crumbPath_themeIds_Array[j]+'"><strong>'+crumbPath_themeNames_Array[j]+'</strong></a>';
				}
				else
				{
					// Voeg alle (sub) thema's toe aan een verzameling met links, evt. opbouw kan hier worden gewijzigd
					printableNavigation += '<a href="/cms/publish/content/showpage.asp?themeid='+crumbPath_themeIds_Array[j]+'">'+crumbPath_themeNames_Array[j]+'</a>';
				}
			}
			else
			{
				// Voeg alle (sub) thema's toe aan een verzameling met links, evt. opbouw kan hier worden gewijzigd
				printableNavigation += '<a href="/cms/publish/content/showpage.asp?themeid='+crumbPath_themeIds_Array[j]+'">'+crumbPath_themeNames_Array[j]+'</a>';
				
			}
			
		}
		
		if (pageName.toLowerCase().indexOf(themeName.toLowerCase()) != -1 && themeId == crumbPath_themeIds_Array[crumbPath_themeIds_Array.length-1])
		{
			// Als het themeId waar we op ons bevinden gelijk is aan het laatste themeId in het kruimelpad en de naam van de pagina gelijk is aan het thema naam, hoeft er geen pagina link toegevoegd te worden
			printableNavigation = replaceLast(printableNavigation,'<a ','<a class="last" ');
		}
		else
		{
			// Hier wordt de paginatitel als laatste link toegevoegd, evt. opbouw kan hier worden gewijzigd
			printableNavigation += '<a class="last" href="/cms/publish/content/showpage.asp?pageid='+pageId+'"><strong>'+pageName+'</strong></a>';
		}
		
		// Plaats het samengestelde kruimelpad in het element met het opgegeven ID
		objectToPlaceCrumbpath.innerHTML = printableNavigation;
	}
}
/*== ==*/

/*== setPreviousSearchedKeywords ==*/
function setPreviousSearchedKeywords(inputObject)
{
	if (inputObject)
	{
		if (readCookie("BINK_PreviousSearchedKeywords"))
		{
			inputObject.value = readCookie("BINK_PreviousSearchedKeywords");
		}
	}
}
/*== ==*/

/*== openClose ==*/
function openClose(elementLink, elementLinkCurrentClassName, elementToOpen, elementToOpenCurrentClassName)
{
	if (elementLink && elementToOpen)
	{
		if (elementLink.className.match(/active/) && elementToOpen.className.match(/active/))
		{
			elementLink.className = elementLinkCurrentClassName;
			elementToOpen.className = elementToOpenCurrentClassName;
		}
		else
		{
			elementLink.className = elementLinkCurrentClassName + ' active';
			elementToOpen.className = elementToOpenCurrentClassName + ' active';
		}
	}
}
/*== ==*/

/*== Body onload (jQuery) ==*/
$(document).ready(function()
{
	HideEmptyImages();
	createCrumbPathAt("crumb_trail");
	setPreviousSearchedKeywords(document.forms['frmMultisearchCustom'].elements['fld_metzoektermen']);
	createCookie("BINK_PreviousSearchedKeywords","",-1,"/","","");
});
/*== ==*/

/*== Body onunload (jQuery) ==*/
/*$(window).unload(function()
{
	createCookie("BINK_PreviousSearchedKeywords","",-1,"/","","");
});*/
/*== ==*/

/*== BINK FlowPlayer Unobtrusive ==*/
$(document).ready(addPlayers);

function addPlayers() {
  if ( typeof flowplayer == 'function' )  {
	  var defaultPlayerOptions = { 
		  clip:  { 
			  autoPlay: false,
			  autoBuffering: false,
			  scaling: 'fit',
			  accelerated: true
		  } 
	  }
	  
	  flowplayer( "a.flash-video"
				, "/flash/flowplayer-3.1.5.swf"
				, defaultPlayerOptions);
  }
}

/*== BINK Gallery Unobtrusive ==*/
$(document).ready(addGalleries);

function addGalleries() {
	if(typeof prettyPhoto=='function') {
		$("a[rel^='prettyPhoto']").prettyPhoto();
	}
}