var basehref;
var site_base_url;

$(function(){	// shorthand for $(document).ready() BTW	
	
	// set base url var
	basehref = $('base').attr('href');
	site_base_url = basehref;
	
	// mainvisual fader
	fadeRandomimagesAfter('div.clmn.middle #mainimage img:first');
	
	// PIR font replacement
	$.pir.options.php = basehref+"pir.php";
		// pirren maar
	$("span.pirimg").pir({font: "UniversLTStd-Cn.otf", wrap: true});
	$("div.clmn.middle p").pir({font: "UniversLTStd-LightCnObl.otf", wrap: true});
	
	// dinge
	$(".welcome p").not(".lead").hide();
		
	$(".welcome p").not(".lead").before("<a href='#' class='clickmore'>Read more &#62;</a>");

	$(".clickmore").click(function(){
		$(this).hide("fast",function(){
			$(this).next().slideDown("slow");
		});
		return false;
	});

});

function fadeRandomimagesAfter(theimg){
	
	if( $(theimg).length ){
		
		var src = $(theimg).hide().attr('src');
		
		//wc( src );
		
		// haal resterende random plaatjes op
		$.post(basehref+'imgs.php',{img:src,dir:'gui/home/random/'},
		function(data){
			
			for (var i = 0; i < data.length; i++) {
			
				// prak de random plaatjes in de holder
				$('<img/>')
				.attr('src',data[i])
				.insertAfter($(theimg));
			}
			
			//$('img',$(theimg).parent()).shuffleall();
			
			// start fader
			$(theimg)
			.parent()
			.cycle({
				timeout:       6000,  // milliseconds between slide transitions (0 to disable auto advance) 
				speed:         2000,  // 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:        null,  // 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]);
		}
	}
}