var basehref; // set with jQuery $('base').attr('href');

// init & start
$(function() {

	// set base url var
	basehref = $('base').attr('href');
	
	// media
	//initmedia();
		
	// fade
	$('div.folder div.thumbnail')
	.each(function(){
		
		var the = $(this);
		
		// eerst plaatjes preppen
		$(the)
		.nextAll('img')
		.each(function(){
			$(this)
			.appendTo($(this).prev());
		});
		
		// dan cyclen
		$(the)
		.cycle({
			fx: 'fade',
			delay:-4500, // additional delay (in ms) for first transition
			timeout:5500,
			speed: 3500,
			sync:1,
			pause:0,     // true to enable "pause on hover" 
			//random:random,	// niet in cycle.lite
			before:alt2src
		});
	});
	// transfer alt of elem to src of elem
	function alt2src(){
		$(this)
		.filter("[alt^='http']")
		.attr('src',$(this).attr('alt'))
		.removeAttr('alt');
	}
	
	// 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');
	
	// cycleoverride
	function cycleoverride(area){
		
		var imgid = $(area).attr('href');
		
		if( $('img#'+imgid).length ){
						
			$('img#topimage').remove();
			
			$('img#'+imgid)
			.clone()
			.addClass(imgid)
			.attr('id','topimage')
			.css({
				opacity:'1',
				display:'inline',
				'zIndex':400
			})
			.prependTo(
				$('img#'+imgid).parent()
			)
			.filter("[alt^='http']")
			.attr('src',$('img#'+imgid).attr('alt'))
			.removeAttr('alt');
			
			//$('img#topimage').not("."+imgid).remove();
		}
		
		return false;
	};
		
	// imagemap
	if( $('map').length ){
		
		$('area',$('map'))
		.mousedown(function(){
			cycleoverride(this);
			return false;

		})
		.click(function(){
			cycleoverride(this);
			return false;
		});
	}
	
});


/* 
	Functions
*/

// 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');
}
