			
// declare 
var activeFunction = 'video';
var activeClass = ''; 

$(function() {
						 

initializeVideo();
initializePhoto();


// initialize
	
	// set the media box standard to zero
	var mediabox = 0;
	
	// attach media switching to buttons & activate video automatically
	$('#videoSwitch').addClass('active'); // activate video 
	
	
	
	// add switch to buttons
	$('#videoSwitch').click(function() {
		switchMedia('video')
	});
	
	$('#photoSwitch').click(function() {
		switchMedia('flickr')
	});
	
	// add close function to mediaHolder button
	$('#closeMedia').click(function(){
		openMediaHolder('close');															
	});


	$("#videoSlider").hide();
	$("#photoSlider").hide();
	switchMedia('video');

	// start the video slider
	$("#videoSlider").slider({ handle: '#youtubehandle', animate: true,   
		slide: function(event, ui) 
		{
			width = $('#videosSplash').css("width")
			width = width.substr(0,width.length-2)							
			steps = (width-940)/100;
			$('#videosSplash').css("left",-(steps*ui.value)+'px');								
		}

	});	

// start the video slider
	$("#photoSlider").slider({ handle: '#photohandle', animate: true,   
		slide: function(event, ui) 
		{
			width = $('#imagesSplash').css("width")
			width = width.substr(0,width.length-2)							
			steps = (width-940)/100;
			$('#imagesSplash').css("left",-(steps*ui.value)+'px');								
		}

	});	
});
// /initialize
				  
				  
				  // videos
				  		// link videos directly into the mediaBox
						function initializeVideo()
						{
							var regex = '/v=[^&]*/';
							var videoArray = $("#videosSplash").children('a');
							var youtube_id = '';
							for(var i=0; i < videoArray.length; i++ )
							{
								
								videoArray[i].href = 'javascript: void(0); playVideo(\''+ videoArray[i].href +'\', 1, \''+videoArray[i].id+'\');';								
							}
							
						}
						
						

						// link all photos directly to the mediaBox
						function initializePhoto()
						{
							var photoArray = $("#imagesSplash").children('a');
							
							for(var i=0; i < photoArray.length; i++ )
							{								
								photoArray[i].href = 'javascript: void(0); playAlbum(\''+ photoArray[i].href +'\',\''+photoArray[i].id+'\');';								
							}							
						}

				function openMediaHolder(action)
				{
					
					if(action=='open')
					{
						$('#mediaHolder').show()
						$('#portletPanel').hide();
						
					}
					
					if(action=='close')
					{
						// close the media holder
						$('#mediaHolder').hide();
						
						// open the portlet again
						$('#portletPanel').show();
						
						// deselect all video's and images
						var photoArray = $("#imagesSplash").children('a');
							for(var i=0; i < photoArray.length; i++ )
							{
								$(photoArray[i]).removeClass('active')
							}
						
						var videoArray = $("#videosSplash").children('a');
							for(var i=0; i < videoArray.length; i++ )
							{
								$(videoArray[i]).removeClass('active')
							}						
					}
					
						
				}
				 
				  
				function switchMedia(type)  
				{					
					$('#photoSwitch').removeClass('active');
					$('#videoSwitch').removeClass('active');
					if(type=='flickr')
					{
						
						activeFunction = 'flickr';
						$('#photoSwitch').addClass('active');
						$('#videosSplash').hide();
						$('#imagesSplash').fadeIn();
						
						$("#videoSlider").hide();
						$("#photoSlider").fadeIn();
						
						
					}
					
					if(type=='video')
					{
						activeFunction = 'video';
						$('#videoSwitch').addClass('active');
						
						$('#imagesSplash').hide();
						$('#videosSplash').fadeIn(500);
						
						$("#videoSlider").fadeIn(500);
						$("#photoSlider").hide();
						
						
					}
				}
				  

				function playAlbum(ALBUM_ID, objectID)
				{
					openMediaHolder('open');
					$('#mediaTitle').html('Foto\'s');
					
					var photoArray = $("#imagesSplash").children('a');
					for(var i=0; i < photoArray.length; i++ )
					{
						$(photoArray[i]).removeClass('active')
					}
					$('#'+objectID).addClass('active');
					/*
					ALBUM_ID = ALBUM_ID.substr(0, (ALBUM_ID.length)-5);
					ALBUM_ID = ALBUM_ID+'o.jpg'*/
					
					
					$('#mediaObject').html('<div class="flickrImageHolder"><img src="'+ ALBUM_ID +'" alt="Flick foto"/></div>');
				}
				  
				  
				function playVideo(VIDEO_ID, autoplayx, objectID)
				{
					
					openMediaHolder('open');
					$('#mediaTitle').html('Video\'s');
					
					var videoArray = $("#videosSplash").children('a');
					for(var i=0; i < videoArray.length; i++ )
					{
						$(videoArray[i]).removeClass('active')
					}
					
					$('#'+objectID).addClass('active');
					
					var autoPlay = '';
					if(autoplayx==1)
					{
						autoPlay = 'autoplay=1&';
					}
					else
					{
						autoPlay = '';
					}
					
					$('#mediaObject').html('<object width="332" height="274"><param name="movie" value='+ VIDEO_ID +'?fs=1&amp;'+ autoPlay +'hl=en_EN"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><param name="setPlaybackQuality" value="small"></param><embed src="'+ VIDEO_ID +'?fs=1&amp;'+ autoPlay +'hl=en_EN" type="application/x-shockwave-flash" allowscriptaccess="always" setPlaybackQuality="sall" allowfullscreen="true" width="332" height="274"></embed></object>');
			
				}
				  
