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

var fancySettings = {
	'hideOnContentClick': true,
	'cyclic'		:	true,
	'margin'		:	80,
	'centerOnScroll':	true,
	'overlayOpacity':	0.8,
	'overlayColor'	:	'#b4b0af',
	'speedIn'		:	600, 
	'speedOut'		:	200, 
	'overlayShow'	:	true
}
	
// init & start
$(function() {
	
	$('.width95').wrapAll( $('<div/>').addClass('holder95') );
	
	// PNG fix 
	$(document).pngFix(); 
	
	$('a.thickbox',$('#pagecontent')).fancybox(fancySettings);
	
	// fade + /* Fancybox Using custom settings */
	fancyfade('#pagecontent div.folder div.thumbnail');
	
	$('a.enlarge').fancybox(fancySettings);
	
	/* table styling in js */
	$('td:first',$('table tr',$('#pagecontent'))).addClass('left');


});

/* 
	Functions
*/

function fancyfade(elem){

	$(elem)
	.each(function(){
		
		var the = $(this);
		
		var firstimg = $('a:first',the);
		
		// eerst plaatjes preppen
		$(the)
		.nextAll('a')
		.each(function(){
			$(this)
			.appendTo($(this).prev());
		});
		
		// dan cyclen
		$(the)
		.cycle({
			fx: 'fade',
			delay:-4500, // additional delay (in ms) for first transition
			timeout:7500,
			speed: 3500,
			sync:1,
			pause:0//,     // true to enable "pause on hover" 
			//random:random,	// niet in cycle.lite
			//before:alt2src
		});
	});
	
}
		  
function prevnextSubMenus(){

	// prev/next  submenu-items....  ff snel...
	
	//trug
	$('ul.sectionsmenu li ul li.selected')
	.prev('li')
	.children('a:first')
	.clone()
	.appendTo('#subnavigation')
	.wrap(
		$('<div/>')
		.addClass('menuitemnav')
		.addClass('prev')
	);
	//vedder
	$('ul.sectionsmenu li ul li.selected')
	.next('li')
	.children('a:first')
	.clone()
	.appendTo('#subnavigation')
	.wrap(
		$('<div/>')
		.addClass('menuitemnav')
		.addClass('next')
	);
	//is ie der? laten zien?
	$('#subnavigation:has("a")')
	.css('display','inline-block');
	
}

function openFancyMap(geocoder,address,title){
	
	var options = {
				zoom: 13,
				//disableDefaultUI: true,
				//center: myLatlng,
				mapTypeId: google.maps.MapTypeId.HYBRID
			}
	
	var addressHTML = address.replace(/,/g,'<br/>');
	
	$.fancybox(
		'<div></div>',
		{
        	'autoDimensions'	: false,
			'width'         	: 550,
			'height'        	: 450,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'onComplete'		:	function() {
				
				
			}
		}
	);
	
	// hier dan voor k•t IE
	addressMap(geocoder,$('#fancybox-inner'),address,title,options,addressHTML);
	
	
}

function addressMap(geocoder,mapNode,address,title,options,info){
	
	geocoder
	.geocode({
		'address':address
	},function(results, status) {
		
		if (status == google.maps.GeocoderStatus.OK) {
			
			mapNode.addClass('googlemap');
			
			var map = new google.maps.Map(mapNode[0],options);
	
			var marker = new google.maps.Marker({
				map: map, 
				title:title,
				position: results[0].geometry.location
			});
			
			if(info){
				var infowindow = new google.maps.InfoWindow({
					content: '<b>'+title+'</b><br/>'+info
				});
				infowindow.open(map,marker);
			}
			
			map.setCenter(results[0].geometry.location);
			
			google.maps.event.addListener(marker, 'click', function() {
				openFancyMap(geocoder,address,title);
			});
			
			$(mapNode)
			.parent()
			.mousemove(function () {
				$(mapNode).css({'z-index':'2'});
			});
			
		} else {
			
			$(mapNode)
			.html("Geocode was not successful for the following reason: " + address + ': ' + status);
		}
	});
			
}

// media
function initmedia(){

	$.fn.media.defaults.flvPlayer = basehref+'gui/media/flvplayer.swf';
	$('p a',$('div.video'))
	.media({ 
		width:  	540,//430, //4
		height: 	230,//343, //3 + 21 controlbar
		autoplay:	false, 
		src:		$(this).attr('href'),
		bgColor:	false, // background color
		caption:	false, // supress caption text
		attrs:		{ 
						autoplay:  false,  
						autostart:  false//, 
						//controlbar: 'none' 
					},  // object/embed attrs 
		params: 	{ 
						autoplay: false, 
						autostart: false//, 
						//controlbar: 'none' 
					}//, // object params/embed attrs 
	}); 
	
	//$('div.media p div embed')
	//.css('backgroundColor','#ff9600')
	//.attr('bgcolor','#ff9600');
}

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