var basehref = $('base').attr('href');

// init & start
$(function() {
	
	// mainvisual fader
	fadeRandomimagesAfter('#mainvisual img:last');
	
	// realnext formulier 
	$('.realnext_search_base');
	
	// fancybox
	$("a.fancybox").fancybox({
		//'transitionIn'	:	'elastic',
		//'transitionOut'	:	'elastic',
		'type'			: 	'image',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'hideOnContentClick':true,
		'overlayShow'	:	true,
		'overlayOpacity':	0.3,
		'overlayColor'	:	'#666'
	});
	
	// fancybox
	$("a.wordsearch.fancy").fancybox({
		'width'			:	800,
		'height'		:	620,
		'type'			: 	'iframe',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'hideOnContentClick'	:false,
		'titleShow'		: false,
		'overlayShow'	:	true,
		'overlayOpacity':	0.3,
		'overlayColor'	:	'#666'
	});
	
	/*
	if($('#holder.home').length)
	{
		var msg = language == 'eng' ? '<h2>Welcome to the website of Colliers International.</h2><p><img src="gui/logos/colliers.international.logo.gif" align="right" width="132" height="89" /> We would like to inform you that Colliers International has acquired a majority stake in Amsterdam\'s leading commercial real estate services firm, Boer Hartog Hooft. With this merger the international experience of Colliers International will be reinforced with the regional strength of Boer Hartog Hooft.</p>' : '<h2>Welkom op de website van Colliers International.</h2><p><img src="gui/logos/colliers.international.logo.gif" align="right" width="132" height="89" /> Graag willen wij u mededelen dat Colliers International vanaf 15 november 2010 is gefuseerd met Boer Hartog Hooft, &#xE9;&#xE9;n van de oudste en meest gerenommeerde commercieel vastgoedspecialisten in de regio Amsterdam. Door deze fusie wordt de internationale expertise van Colliers International versterkt met de regionale kracht van Boer Hartog Hooft.</p>';
		
		$.fancybox(msg, {
			autoDimensions: false,
			width: 520,
			height:	'auto',
			overlayOpacity: 0.6,
			overlayColor: '#000'
		});
	}
	*/
});


function fadeRandomimagesAfter(theimg){
	
	if( $(theimg).length ){
		
		var src = $(theimg).attr('src');
		
		//wc( src );
		
		// haal resterende random plaatjes op
		$.post(basehref+'gui/mainvisuals/random.php?d='+pagetype,{r:'list'},
		function(data){
		
			for (var i = 0; i < data.length; i++) {
				
				//wc(data[i]);
				
				// prak de random plaatjes in de holder
				$('<img/>')
				.attr('alt',data[i])
				.insertAfter($(theimg));
			}
			
			// start fader
			$(theimg)
			.parent()
			.cycle({
				timeout:       8000,  // milliseconds between slide transitions (0 to disable auto advance) 
				speed:         3000,  // speed of the transition (any valid fx speed value) 
				next:          null,  // id of element to use as click trigger for next slide 
				prev:          null,  // id of element to use as click trigger for previous slide 
				before:        function(current,next){
					if( $(next).attr('alt').length ){
						$(next).attr('src',$(next).attr('alt')).removeAttr('alt');
					}
				},  // transition callback (scope set to element to be shown) 
				after:         null,  // transition callback (scope set to element that was shown) 
				height:       'auto', // container height 
				sync:          1,     // true if in/out transitions should occur simultaneously 
				fit:           0,     // force slides to fit container 
				pause:         0,     // true to enable "pause on hover" 
				delay:         -4000,     // additional delay (in ms) for first transition (hint: can be negative) 
				slideExpr:     null   // expression for selecting slides (if something other than all children is required) 
			});
	
		},"json");
		
	}
}

function wc()
{
	if(window.console)
	{
		for(var i = 0; i < arguments.length; i++)
		{
			window.console.log(arguments[i]);
		}
	}
}
