$(function(){
	/* 
	 * jquery 1.2.2
	 * @author: arjen
	 * 
	 */
	
	//titel en artiest ophalen voor gebruik bij video player
	var title = $('#voorstellingKopAfbeeldingContainer .title').text();
	var artist = $('#voorstellingKopAfbeeldingContainer .artist').text();
	
	// voorstelling img slider	
	if (typeof $('body.voorstellingDetail #voorstellingKopAfbeeldingContainer img').get(0) != 'undefined') {
		sBodyId = $('body').attr('id');
		aBodyId = sBodyId.split('-');		
		if (typeof aBodyId[1] != 'undefined' && !isNaN(aBodyId[1])) {
			iVoorstId = aBodyId[1];			
			var so = new SWFObject("/flash/slideInfoTitle.swf", "soSlideInfoTitle", "400", "375", "8", "#FFFFFF");
			so.addVariable("xmlPos", "/flash/voorstelling.xml.php?id="+iVoorstId);
			so.addVariable("slideTime", 5); // s
			so.addVariable("fadeTime", 0.5); // s
			so.addParam("wmode", "opaque");
			//$('#binnenkort div.contentItem').attr('id', 'binnenkortInner')
			so.write("voorstellingKopAfbeeldingContainer");
			$('#voorstellingKopAfbeeldingContainer').addClass('swf');
		}
	}
	
	// voorstellingsoverzicht (prijzen)
	if (typeof $('body.voorstellingDetail #subVoorstellingPrijzen dl').get(0) != 'undefined') {
		
		//$('#prijsgroep-3eRang-term, #prijsgroep-3eRang-desc, #prijsgroep-ongeplaceerd-term, #prijsgroep-ongeplaceerd-desc').hide();
		
		//console.log($('#subVoorstellingPrijzen dt.level0').length);
		 
		 if ($('#subVoorstellingPrijzen dt.level0').length > 2) {
		
		 	$('#subVoorstellingPrijzen .contentBox').append('<p><a href="#" id="togglePrijzenAnchor">toon alle prijzen&nbsp;&#62;</a></p>');
		 	$('#togglePrijzenAnchor').click(function(){
		 		if ($('#prijsgroep-3eRang-term').css('display') == 'none') {
		 			$('#prijsgroep-3eRang-term, #prijsgroep-3eRang-desc, #prijsgroep-ongeplaceerd-term, #prijsgroep-ongeplaceerd-desc').slideDown();
		 			$('#togglePrijzenAnchor').text('< verberg');
		 		}
		 		else {
		 			$('#prijsgroep-3eRang-term, #prijsgroep-3eRang-desc, #prijsgroep-ongeplaceerd-term, #prijsgroep-ongeplaceerd-desc').slideUp();
		 			$('#togglePrijzenAnchor').text('toon alle prijzen >');
		 		}
		 		return false;
		 	});
		
		 }
	}

	// voorstelling media
	$('#voorstellingDetail .mediaContainer').not('#voorstellingDetail-ecard').hide();
	
	// audio
	$('#voorstellingMediaOpties-recensies').add('#mediaContainer-recensies a.backlink').click(function(){
		//hide the active
		var clicked = $('#voorstellingMediaOpties-recensies');
		var container = $('#mediaContainer-recensies');
		toggleMedia(clicked, container);
		
		return false;
	});
	
	
	// audio
	$('#voorstellingMediaOpties-audio').add('#mediaContainer-audio a.backlink').click(function(){
		//hide the active
		var clicked = $('#voorstellingMediaOpties-audio');
		var container = $('#mediaContainer-audio');
		toggleMedia(clicked, container);
		
		return false;
	});
	
	$('#mediaContainer-audio a').not('.backlink').click(function(){
		//hide all flash players
		$('#voorstellingDetail-flashVideo, #voorstellingDetail-flashAudio').remove();
		
		var f = $(this).attr('href');

				
		$('#voorstellingKopAfbeeldingContainer').after('<div id="voorstellingDetail-flashAudio">www</div>');
		//always show it again
		$('#voorstellingKopAfbeeldingContainer').show();
		
		//return false;
		var so = new SWFObject("/flash/audioplayerDetail.swf", "flashAudio", "400", "30", "8", "#f3f3f3");
		so.addParam("wmode", "opaque");
		so.addVariable("playMe", true);
		so.addVariable("myFile", f);
		so.useExpressInstall('/flash/expressinstall.swf');
		so.write("voorstellingDetail-flashAudio");
		return false;
	});
	
	
	// video
	$('#voorstellingMediaOpties-video').add('#mediaContainer-video a.backlink').click(function(){
		//hide the active
		var clicked = $('#voorstellingMediaOpties-video');
		var container = $('#mediaContainer-video');
		toggleMedia(clicked, container);
		
		return false;
	});
	
	$('#mediaContainer-video a').not('.backlink').click(function(){
		//hide the image and the audio player
		$('#voorstellingDetail-flashVideo, #voorstellingDetail-flashAudio').remove();
		
		
		var f = $(this).attr('href');
		
		$('#voorstellingKopAfbeeldingContainer').after('<div id="voorstellingDetail-flashVideo"></div>');
		$('#voorstellingKopAfbeeldingContainer').hide();
		
		var so = new SWFObject("/flash/videoplayerDetail.swf", "flashVideo", "398", "375", "8", "#ffffff");
		so.addParam("wmode", "opaque");
		so.addVariable("playMe", true);
		so.addVariable("myFile", f);
		
		so.addVariable("title", title);
		so.addVariable("artist", artist);
		so.useExpressInstall('/flash/expressinstall.swf');
		so.write("voorstellingDetail-flashVideo");
		return false;
	});	

});


function toggleMedia(clicked, container)
{
	//if what we clicked is visible
	if(container.is(':visible'))
	{
		//remove the flash players
		$('#voorstellingDetail-flashVideo, #voorstellingDetail-flashAudio').remove();
			
		//hide it
		container.slideToggle('normal', function(){
			//show the omschrijving
			$('#voorstellingDetail-omschrijving').slideToggle();
			clicked.removeClass('active');
		});
	} else {
		//hide that which is showing
		showing = $('#voorstellingDetail-omschrijving').add('#mediaContainer-audio').add('#mediaContainer-video').add('#mediaContainer-recensies').filter(':visible');
		showing.slideToggle('normal', function(){
			//and show the clicked
			container.slideToggle();
			//deactivate the 
			$('#voorstellingMediaOpties-video').add('#voorstellingMediaOpties-audio').add('#voorstellingMediaOpties-recensies').removeClass('active');
			clicked.addClass('active');
		});
	}
	
}
