/*********************** FUNCTIES VOOR HET LADEN VAN PAGINA'S VIA AJAX **************************/
function iFrameAutoHeight(id)
{
  var the_height = document.getElementById(id).contentWindow.document.body.scrollHeight;
  document.getElementById(id).height = the_height;
}
function switchPage(url)
{
	var succes_actions = function(html)
	{
		jQuery("#content").html(html);
		loadFonts();
		
		try{
			Shadowbox.clearCache();
			Shadowbox.setup();
		} catch(e){};
	}
			
	jQuery.ajax({
		url		: url,
		type	: "post",
		success	: succes_actions
	});
}
	
/*
function switchPage(url)
{
	if(url == "/content/103/alle_websites.html"){
		location.href = "/content/8/alle_websites.html";
	} else {
		var succes_actions = function(transport)
		{
			var responseText = transport.responseText;
		
			$("content").innerHTML = responseText;
			
			loadFonts();
			
			executeJS(responseText);
		};
		
		new Ajax.Request(url,{ onSuccess : succes_actions });
	}
}
*/

function debug(arg)
{
	if(typeof(arg) == 'object')
	{
		if(arg.constructor == Array)
		{
			var array = arg;
			arg = '';
			
			var iL = array.length;
			for(var i=0; i<iL; i++)
			{
				var v = array[i];
				arg += i +': '+ v +'<br>';
			}
		}
	}
	
	var d = document.getElementById('debug');
		d.innerHTML = arg +'<hr>'+ d.innerHTML; 
}

function executeJS(contents)
{
	contents = contents.replace(/\n/g, ' ');
	contents = contents.replace(/\r/g, ' ');
	
	var regExp = new RegExp(/(<script type="text\/javascript"(>(.*)| src="([\/:a-zA-Z0-9_\-\.\?=&%#]*)">)<\/script>)/gm);
	
	while(result = regExp.exec(contents))
	{
		if(result[3] != undefined && result[3] != '')
		{
			eval(result[3]);
		}
		else if(result[4] != undefined && result[4] != '') 
		{
			var success = function(transport)
			{
				var responseText = transport.responseText;
				eval(responseText);
			};
			
			new Ajax.Request("/cmsfiles/operators/call.php?file="+ result[4],
			{ 
				onSuccess: success
			});
		}
	}
}

function showcase()
{
	var succes_actions = function(html)
	{
		jQuery("#home_showcase").html(html);		
	}
	
	jQuery.ajax({
		url		: "/cmsfiles/templates/content/showcase.php",
		type	: "post",
		data	: {ajax : 1},
		success	: succes_actions
	});
}


isBusy = false;

function showcase_MEUK()
{
	var contentDiv 	= 'home_showcase';
	var duration	= 0.1;
	var fps			= 30;
	var freezeTime	= 0;

	if(!isBusy)
	{
		isBusy = true;
		extraparams = false;
		title = 'showcase';
		// fade out
		new Effect.Opacity(contentDiv,
		{
			duration:	duration,
			fps:		fps,
			from:		1,
			to:			0,
			
			beforeStart: function()
			{
				$(contentDiv).setOpacity(1);
			},
			
			afterFinish: function()
			{
				var data =
				{
					type:	'page',
					id:		0
				}
				var params =
				{
					projectId:	0
				}
				
				if(extraparams != undefined){
					params = 0;
				}
				
				if(params == null) var params = {};
				params.ajax = 1;
				
				new Ajax.Request('/cmsfiles/templates/content/showcase.php',
				{
					method:			'post',
					parameters:		params,
					
					onSuccess: function(transport)
					{
						//data.response = transport.responseText;
				//		HistoryManager.add(title, data);
						//showShowcase(data);
						
						$(contentDiv).innerHTML = transport.responseText;
					}
				});
			}
		});
	}

}

function dvReset()
{
	loadFonts();
}

function loadFonts()
{
	Cufon.replace('h1, .content_title_grijs, .content_title_red, h4, #submenu_top', {'fontFamily': 'OfficinaSansBlack'});
	Cufon.replace('#menu_items a', {'fontFamily': 'OfficinaSansBold'});
	Cufon.replace('h2', {'fontFamily': 'OfficinaSansMedium'});
}

jQuery(document).ready(function(){
	Cufon.replace('#footer span, #footer a');
	loadFonts();
});

Shadowbox.init({
	handleOversize:     'drag',
	resizeDuration:		0.35,
	fadeDuration:		0.10,
	overlayOpacity:		0.6,
	language:  	 		"nl",
	players:    		['img']
});