/**
 * Get the value of a cookie with the given key.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String key The key of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
jQuery.cookie = function (key, value, options) {
    
    // key and at least value given, set cookie...
    if (arguments.length > 1 && String(value) !== "[object Object]") {
        options = jQuery.extend({}, options);

        if (value === null || value === undefined) {
            options.expires = -1;
        }

        if (typeof options.expires === 'number') {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }
        
        value = String(value);
        
        return (document.cookie = [
            encodeURIComponent(key), '=',
            options.raw ? value : encodeURIComponent(value),
            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
            options.path ? '; path=' + options.path : '',
            options.domain ? '; domain=' + options.domain : '',
            options.secure ? '; secure' : ''
        ].join(''));
    }

    // key and possibly options given, get cookie...
    options = value || {};
    var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};

/*
 *
 * jqTransform
 * by mathieu vilaplana mvilaplana@dfc-e.com
 * Designer ghyslain armand garmand@dfc-e.com
 *
 *
 * Version 1.0 25.09.08
 * Version 1.1 06.08.09
 * Add event click on Checkbox and Radio
 * Auto calculate the size of a select element
 * Can now, disabled the elements
 * Correct bug in ff if click on select (overflow=hidden)
 * No need any more preloading !!
 * 
 ******************************************** */
 
(function($){
	var defaultOptions = {preloadImg:true};
	var jqTransformImgPreloaded = false;

	var jqTransformPreloadHoverFocusImg = function(strImgUrl) {
		//guillemets to remove for ie
		strImgUrl = strImgUrl.replace(/^url\((.*)\)/,'$1').replace(/^\"(.*)\"$/,'$1');
		var imgHover = new Image();
		imgHover.src = strImgUrl.replace(/\.([a-zA-Z]*)$/,'-hover.$1');
		var imgFocus = new Image();
		imgFocus.src = strImgUrl.replace(/\.([a-zA-Z]*)$/,'-focus.$1');				
	};

	
	/***************************
	  Labels
	***************************/
	var jqTransformGetLabel = function(objfield){
		var selfForm = $(objfield.get(0).form);
		var oLabel = objfield.next();
		if(!oLabel.is('label')) {
			oLabel = objfield.prev();
			if(oLabel.is('label')){
				var inputname = objfield.attr('id');
				if(inputname){
					oLabel = selfForm.find('label[for="'+inputname+'"]');
				} 
			}
		}
		if(oLabel.is('label')){return oLabel.css('cursor','pointer');}
		return false;
	};
	
	/* Hide all open selects */
	var jqTransformHideSelect = function(oTarget){
		var ulVisible = $('.jqTransformSelectWrapper ul:visible');
		ulVisible.each(function(){
			var oSelect = $(this).parents(".jqTransformSelectWrapper:first").find("select").get(0);
			//do not hide if click on the label object associated to the select
			if( !(oTarget && oSelect.oLabel && oSelect.oLabel.get(0) == oTarget.get(0)) ){$(this).hide();}
		});
	};
	/* Check for an external click */
	var jqTransformCheckExternalClick = function(event) {
		if ($(event.target).parents('.jqTransformSelectWrapper').length === 0) { jqTransformHideSelect($(event.target)); }
	};

	/* Apply document listener */
	var jqTransformAddDocumentListener = function (){
		$(document).mousedown(jqTransformCheckExternalClick);
	};	
			
	/* Add a new handler for the reset action */
	var jqTransformReset = function(f){
		var sel;
		$('.jqTransformSelectWrapper select', f).each(function(){sel = (this.selectedIndex<0) ? 0 : this.selectedIndex; $('ul', $(this).parent()).each(function(){$('a:eq('+ sel +')', this).click();});});
		$('a.jqTransformCheckbox, a.jqTransformRadio', f).removeClass('jqTransformChecked');
		$('input:checkbox, input:radio', f).each(function(){if(this.checked){$('a', $(this).parent()).addClass('jqTransformChecked');}});
	};

	/***************************
	  Select 
	 ***************************/	
	$.fn.jqTransSelect = function(){
		return this.each(function(index){
			var $select = $(this);

			if($select.hasClass('jqTransformHidden')) {return;}
			if($select.attr('multiple')) {return;}

			var oLabel  =  jqTransformGetLabel($select);
			/* First thing we do is Wrap it */
			var $wrapper = $select
				.addClass('jqTransformHidden')
				.wrap('<div class="jqTransformSelectWrapper"></div>')
				.parent()
				.css({zIndex: 10-index})
			;
			
			/* Now add the html for the select */
			$wrapper.prepend('<div><span></span><a href="#" class="jqTransformSelectOpen"></a></div><ul></ul>');
			var $ul = $('ul', $wrapper).hide();
			/* Now we add the options */
			$('option', this).each(function(i){
				var oLi = $('<li><a href="#" index="'+ i +'">'+ $(this).html() +'</a></li>');
				$ul.append(oLi);
			});
			
			/* Add click handler to the a */
			$ul.find('a').click(function(){
										
					$('a.selected', $wrapper).removeClass('selected');
					$(this).addClass('selected');	
					/* Fire the onchange event */
					if ($select[0].selectedIndex != $(this).attr('index') && $select[0].onchange) { $select[0].selectedIndex = $(this).attr('index'); $select[0].onchange(); }
					$select[0].selectedIndex = $(this).attr('index');
					$('span:eq(0)', $wrapper).html($(this).html());
					$ul.hide();
					//alert('hidden!');
					return false;
			});
			/* Set the default */
			
			//alert(this.selectedIndex);
			
			//$('a:eq('+ this.selectedIndex +')', $ul).click();
			$('span:first', $wrapper).click(function(){$("a.jqTransformSelectOpen",$wrapper).trigger('click');});
			oLabel && oLabel.click(function(){$("a.jqTransformSelectOpen",$wrapper).trigger('click');});
			this.oLabel = oLabel;
			
			/* Apply the click handler to the Open */
			var oLinkOpen = $('a.jqTransformSelectOpen', $wrapper)
				.click(function(){
								
					//Check if box is already open to still allow toggle, but close all other selects
					if( $ul.css('display') == 'none' ) {jqTransformHideSelect();} 
					if($select.attr('disabled')){return false;}
					//alert('go for toggle');
					$ul.slideToggle('fast', function(){					
						var offSet = ($('a.selected', $ul).offset().top - $ul.offset().top);
						$ul.animate({scrollTop: offSet});
					});
					return false;
				})
			;
			$('a:eq('+ this.selectedIndex +')', $ul).click();
			
		});
	};
	$.fn.jqTransform = function(options){
		var opt = $.extend({},defaultOptions,options);
		
		/* each form */
		 return this.each(function(){
			var selfForm = $(this);
			if(selfForm.hasClass('jqtransformdone')) {return;}
			selfForm.addClass('jqtransformdone');
			if( $('select', this).jqTransSelect().length > 0 ){jqTransformAddDocumentListener();}
		}); /* End Form each */
				
	};/* End the Plugin */

})(jQuery);
				   
				   
// JavaScript Document
(function($) {
    var uid = 0;
    $.getUID = function() {
        uid++;
        return 'jQ-uid-'+uid;
    };
    $.fn.getUID = function() {
        if(!this.length) {
            return 0;
        }
        var fst = this.first(), id = fst.attr('id');
        if(!id) {
            id = $.getUID();
            fst.attr('id', id);
        }
        return id;
    }
})(jQuery);


function implode (glue, pieces) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Waldo Malqui Silva
    // +   improved by: Itsacon (http://www.itsacon.net/)
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: implode(' ', ['Kevin', 'van', 'Zonneveld']);
    // *     returns 1: 'Kevin van Zonneveld'
    // *     example 2: implode(' ', {first:'Kevin', last: 'van Zonneveld'});
    // *     returns 2: 'Kevin van Zonneveld'
    var i = '',
        retVal = '',
        tGlue = '';
    if (arguments.length === 1) {
        pieces = glue;
        glue = '';
    }
    if (typeof(pieces) === 'object') {
        if (Object.prototype.toString.call(pieces) === '[object Array]') {
            return pieces.join(glue);
        } else {
            for (i in pieces) {
                retVal += tGlue + pieces[i];
                tGlue = glue;
            }
            return retVal;
        }
    } else {
        return pieces;
    }
}

jQuery.fn.equalColumnHeights=function( columns )
{
	var total=$(this).length;
	var maxRowHeight=0;
	var allElements=$(this);
	$(this).each(function(index)
	{
		var hindex=index+1;
		var theight=$(this).height();
		if(theight>maxRowHeight)
		{
			maxRowHeight=theight;
		}
		if(parseInt(hindex/columns)==parseFloat(hindex/columns))
		{
			for(i=0;i<columns;i++)
			{
				$(allElements[index-i]).css('min-height', maxRowHeight+'px').addClass('adjusted');
			}
			maxRowHeight=0;
		}
		if(total==hindex)
		{
			$(allElements).not('.adjusted').each(function()
			{
				$(this).css('min-height', maxRowHeight+'px').addClass('adjusted');
			});
	}});
}

function nowPlaying(clipid)
{
	//alert(clipid);
	if( $('#cardata span#car_clip_'+clipid).length > 0 )
	{
		var titellink = $('#cardata span#car_clip_'+clipid+' .clip_link').html();
		$('#hpclipcontainer .clip-details h2').html(titellink);
		var authorlink = $('#cardata span#car_clip_'+clipid+' .author_link').html();
		$('#hpclipcontainer .clip-details span.author').html(authorlink);
	}
}

function moveBalkRight( pixels )
{
		if( ! pixels )
		{
			pixels = 2
		}

		$('#clip-balk li.clip a').css({'margin-top' : '0'});


		var currentmargin = $('.clips-index').css('margin-left');
		//alert( currentmargin );
		newmargin = parseInt(currentmargin.replace('px',''), 0) + pixels;
		if(newmargin > 0)
		{
			// clone one
			$('.clips-index li:last').insertBefore('.clips-index li:first');
			newmargin = -96;
		}
		$('.clips-index').css('margin-left', newmargin + 'px');
		if( $('#clip-right').hasClass('active') )
		{
			window.setTimeout( 'moveBalkRight('+pixels+')', 1 );
		}
}

function moveBalkLeft( pixels )
{
		if( ! pixels )
		{
			pixels = 2
		}
		
		$('#clip-balk li.clip a').css({'margin-top' : '0'});
	
		var currentmargin = $('.clips-index').css('margin-left');
		//alert( currentmargin );
		newmargin = parseInt(currentmargin.replace('px',''), 0) - pixels;
		
		var offset = $('.clips-index li:last').offset();
		var right = offset.left + 96;
		
		if(right < document.width )
		{
			//alert(right);
			$('.clips-index li:first').insertAfter('.clips-index li:last');	
			newmargin = newmargin + 96;
		}
		
		$('.clips-index').css('margin-left', newmargin + 'px');
		if( $('#clip-left').hasClass('active') )
		{
			window.setTimeout( 'moveBalkLeft('+pixels+')', 1 );
		}
}

	function toggleworkingspace()
	{
		// originaal was de animator 990 x 600 
		// nu 575 x 950
		
		
		if( $('a#toggleworkingspace').hasClass('extended')  )	
		{
			$('#navigate').show();
			$('#site-footer').show();
			$('#menus').show();
			$('#user-functions').show();
			$('#site-menu').show();
			$('#identity').show();
			$('a#toggleworkingspace').removeClass('extended');
			$('a#toggleworkingspace span').html('vergroot werkruimte');
			$('object#animator').width('950').height('575');
			$('object#animator embed').width('950').height('575');
			$('object#animator embed').css({width: 950, height:575});
			// $('#content').css({padding:0});
			$('#main').css({width:'auto'});
			
		}
		else
		{
			$('#navigate').hide();
			$('#site-footer').hide();
			$('#identity').hide();
			$('#user-functions').hide();
			$('#menus').hide();
			$('#site-menu').hide();
			$('a#toggleworkingspace span').html('verklein werkruimte');
			$('a#toggleworkingspace').addClass('extended');
			
			// determine possibel width, max = 1240 for historical reasons
			
			var animwidth = $(window).width() - 40;
			if(animwidth > 1240)
			animwidth = 1240;
			
			var animheight = animwidth * 600/990;
			var available_height =  $(window).height() -50;
			if(animheight > available_height)
			{
			 // resize the other way
			 	animheight = available_height;
				animwidth = animheight * 900/600;			
			}
			
			
			//alert('new width '+animwidth);
			//alert('new height '+animheight);
			//alert()
			var pagewidth = animwidth+20;
			//alert('page = '+pagewidth);
			$('#main').css({width: pagewidth });
			
			$('object#animator').width(animwidth).height(animheight);
			$('object#animator').css({width: animwidth, height :animheight});
			
			$('object#animator embed').width(animwidth).height(animheight);
			$('object#animator embed').css({width: animwidth, height :animheight});
			
			//$('#content').css({padding:0});
		}		
	}

$(window).load(function()
{
	//$('body').show(500);
});

function skipintro()
{
	//alert('skip');
	//$('#skip-link').click();
	document.location.replace( $('#skip-link').attr('href') );
}

$(document).ready(function() {

	if( $('#intro').length > 0  )
	{
		$('#intro').css('height','100%');
		
		
		// pak een plaatje en animeer het van boven naar beneden
		var aantal_bumpers = $('#bumpers li').length;
		var index  = Math.ceil( Math.random() * aantal_bumpers ) - 1;
		var bumperlink = $('#bumpers li').eq(index).find('a');
		var src = bumperlink.attr('href');
		$('<img id="thebumperimage" src="'+src+'" alt="" />').hide().appendTo('body');
		//alert(src);
		$('body').css({'text-align' : 'center'} );
		$('#thebumperimage').css({position : 'relative', 'margin': '-500px auto 0 auto' }).show();
		$('#thebumperimage').animate({ 'margin-top': '40%' }, 4000 );
		
		window.setTimeout( 'skipintro()' , 4000 );
		
	}
	
	$('#group_role').each( function(){
		
		if( $(this).html() == 'docent')
		{
			$('<span class="sep">|</span><span class="content"><a href="'+$('#docentenlink-lesmateriaal').html()+'"><span><span>Lesmateriaal</span></span></a></span>').insertAfter('#navigate #content-menu span.content:last');
		}
	});
		


	//$('').appendTo('#balk .clips-index li a');
	
	$('#content-menu span.active').addClass('current');
	
	$('#content-menu span.content').hover( function(){
		$(this).addClass('active');
		}, function(){
			
			if( ! $(this).hasClass('current') )
			{
				$(this).removeClass('active');	
			}
	});
	
	//$('body').hide();
	$("form#ClipSearch21Form").jqTransform();
	
	$('#ClipSearch21Form').live('submit',function(){
		
		vurl = $(this).attr('action') +'?'+ $(this).serialize();
		//alert(vurl);
		$.ajax({ async : true, url: vurl, success: function(data){
				//alert(data);	
				$('#search-results-clips').replaceWith(data).show('fast');
			}
		});	
		return false;
										 
	});
	
	$("form#ClipSearch9Form").jqTransform();
	
	$('#ClipSearch9Form').live('submit',function(){
		
		vurl = $(this).attr('action') +'?'+ $(this).serialize();
		//alert(vurl);
		$.ajax({ async : true, url: vurl, success: function(data){
				//alert(data);	
				$('#search-results-clips').replaceWith(data).show('fast');
			}
		});	
		return false;
										 
	});
	
	$('#hp-intros .col').equalColumnHeights(4);
	$('#hp-intros .col .blog-main').equalColumnHeights(4);
	
	$('.blog-item a.meer').live('click',function(){
		$('.blog-item').removeClass('blog-item-active');
		var el = $(this).attr('href');
		$(el).addClass('blog-item-active');
	});
	
	
	if( document.location.hash != "")
	{
		var bloghref = document.location.hash.toString();
		$('a[href='+bloghref+']').click();
		//alert(document.location.hash);
	}
	
	
	
	$('.verdieping-item a.meer').live('click',function(){
		$('.verdieping-item').removeClass('verdieping-item-active');
		var el = $(this).attr('href');
		$(el).addClass('verdieping-item-active');
	});
	
	 $("a[href^=http]").attr('target','_blank').addClass('external');
	 
	 $('a[href$=".pdf"]').attr('target', '_blank');
	
	
	$('.verdieping-item a').live('click', function(event){
		
		// in en uitklap
		if( $(this).hasClass('meer') )
		{
			return;
		}
		
		// externe link
		if( $(this).hasClass('external') )
		{
			return;
		}
		
		event.preventDefault();
		
		var el = $(this).attr('href');
		$('#verdieping-view-extended-info .cnt').html( $(el).html() );
		
				
		var offset = $(this).offset();
		var top = offset.top -217; // viewer = 516, breedte = 82. 516 / 2 = 258. 258 - 41 =
		$('#verdieping-view-extended-info').css({top : top+'px' });
		$('#verdieping-view-extended-info').show('fast');
	});
	
	
	
	/*
	$('#clip-listing img').live('load', function(){
		 // 150 / 104
		 console.log( 'image ='+ $(this).height() );
		if(  $(this).height() < 104 && $(this).height() != 0 )
		{
			$(this).css('margin-top', parseInt( ( 104 - $(this).height() ) / 2 )  +'px');
		}
		
	});
	*/
	
	$("body").click(function(event) {
							 
		if( $(event.target).parents('#balk').length == 0 && $(event.target).parents('#view-clip').length == 0)
		{
			$('#view-clip').hide();
		}
		
		$('#clip-balk li.clip a').removeClass('current');
		$('#clip-balk li.clip a').removeClass('brother');
			
		//if( $(event.target).parents('#verdieping-view-extended-info').length == 0)
		//{
		$('#verdieping-view-extended-info').hide();
		//}
		
		
	}); 
	
	$('#clip-balk li.clip a').mouseenter(function(event){								  
			$('#holyPlayerContainer').html('');
			$('#view-clip').slideUp();

			$('#clip-balk li.clip a').removeClass('current');
			$('#clip-balk li.clip a').removeClass('brother');
//			css({'margin-top' : '0'});
			$(this).addClass('current');
			$(this).parent().prev('li').find('a').addClass('brother');
			$(this).parent().next('li').find('a').addClass('brother');
			
			$('#clip-balk li.clip a').not('.current').not('.brother').css({'margin-top' : '0'});
			$('#clip-balk li.clip a').stop( true, true);
			$('.current').animate({'margin-top' : '-20px'}, 150 );
			$('.brother').animate({'margin-top' : '-10px'}, 150);

	});
	
	$('#clip-right').mouseenter(function(){
		$(this).addClass('active');
		moveBalkRight(2);
	});

/* not smooth enough
	$('#clip-right').click(function(){
		$(this).removeClass('active');
		moveBalkRight( 96 );
	});
*/
	
	$('#clip-right').mouseleave(function(){
		$(this).removeClass('active');	
	});
	
	$('#clip-left').mouseenter(function(){
		$(this).addClass('active');
		moveBalkLeft(2);
	});
/* not smooth enough

	$('#clip-left').click(function(){
		$(this).removeClass('active');
		moveBalkLeft( 96 );
	});
*/
	$('#clip-left').mouseleave(function(){
		$(this).removeClass('active');	
	});

	$('#clip-balk li.clip a').click(function(event){
		event.preventDefault();
		$(this).showClipFromBalk();		
	});
	
	$('.act-home-display #search-results-clips li.clip a').live('click', function(event){
		event.preventDefault();
		$(this).showClipFromListing();		
	});
	
	$('.afd-animaties #search-results-clips li.clip a').live('click', function(event){
		event.preventDefault();
		$(this).showClipFromListing();		
	});
	
	$('.act-users-myprofile .search-results-clips li.clip a').live('click', function(event){
		event.preventDefault();
		$(this).showActiveClip();	
	});
	
	$('.act-users-profile .search-results-clips li.clip a').live('click', function(event){
		event.preventDefault();
		$(this).showActiveClip();	
	});
		
	$('.act-contents-ccontest #search-results-clips li.clip a').live('click', function(event){
		event.preventDefault();
		$(this).showNomineeClip();		
	});
	
	$('.act-contents-ccontest #search-results-clips li.clip a').eq(0).click();
	
	$('.act-clips-grouplist li.clip a').live('click', function(event){
		event.preventDefault();
		$(this).showActiveClip();		
	});
	
	$('#clip-single-viewer').each( function(){	
		$(this).showSingleClip();
	});
	
	$('#cclip-embedlinks input').live('click', function(){
		var domEl = $(this).get(0);
		domEl.focus();
		domEl.select();
	});
	
	$('#clip-balk').mouseleave(function(){
		$('#clip-balk li.clip a.current').stop( true, true );
		$('#clip-balk li.clip a.brother').stop( true, true );
		$('#clip-balk li.clip a').css({'margin-top' : 0 });
		$('#clip-balk li.clip a').css({'margin-top' : 0 });
	});
	
	
	$('#content_attachments .video a[href$=".flv"]').each(function(){
									  
		var href=$(this).attr('href');
		var image = "";
		width = 556;
		height = 313 ; //zonder balk
		balk = 23;
		theheight = parseInt(height+balk);
		
			// detect preview image
			if( $('img', this).length > 0 )
			{
				image = $('img', this).attr('src');
				var fmovie = '<object width="'+width+'" height="'+theheight+'" name="player" id="player" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param value="/flvplayer/jw51/player.swf" name="movie"/><param name="wmode" value="transparent" /><param value="true" name="allowfullscreen"><param value="always" name="allowscriptaccess"><param value="file=' + href + '&amp;autostart=0&amp;screencolor=white&amp;repeat=always&amp;volume=50&amp;image='+image+'" name="flashvars"><embed name="player1" id="player2" width="'+width+'" height="'+theheight+'"  wmode="transparent"  allowfullscreen="true" allowscriptaccess="always"  type="application/x-shockwave-flash" src="/flvplayer/jw51/player.swf" flashvars="file=' + href + '&amp;autostart=0&amp;screencolor=white&amp;repeat=no&amp;volume=50&amp;image='+image+'"/></object>';
			}
			else
			{
				var fmovie ='<object width="'+width+'" height="'+theheight+'" name="player" id="player" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param value="/flvplayer/jw51/player.swf" name="movie"/><param name="wmode" value="transparent" /><param value="true" name="allowfullscreen"><param value="always" name="allowscriptaccess"><param value="file=' + href + '&amp;autostart=0&amp;screencolor=white&amp;repeat=always&amp;volume=50" name="flashvars"><embed name="player1" id="player2" width="'+width+'" height="'+theheight+'"  wmode="transparent"  allowfullscreen="true" allowscriptaccess="always"  type="application/x-shockwave-flash" src="/flvplayer/jw51/player.swf" flashvars="file=' + href + '&amp;autostart=0&amp;screencolor=white&amp;repeat=no&amp;volume=50"/></object>';
			}
									  
			  
			$(fmovie).insertBefore(this);
			$(this).hide();
	});
	
	$('#hp-video a[href$=".flv"]').each(function(){
									  
		var href=$(this).attr('href');
		var image = "";
		
		width = 666;
		height = 375 ; //zonder balk
		balk = 23;
		theheight = parseInt(height+balk);
		
			// detect preview image
			if( $('img', this).length > 0 )
			{
				image = $('img', this).attr('src');
				var fmovie = '<object width="'+width+'" height="'+theheight+'" name="player" id="player" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param value="/flvplayer/jw51/player.swf" name="movie"/><param name="wmode" value="transparent" /><param value="true" name="allowfullscreen"><param value="always" name="allowscriptaccess"><param value="file=' + href + '&amp;autostart=0&amp;screencolor=white&amp;repeat=always&amp;volume=50&amp;image='+image+'" name="flashvars"><embed name="player1" id="player2" width="'+width+'" height="'+theheight+'"  wmode="transparent"  allowfullscreen="true" allowscriptaccess="always"  type="application/x-shockwave-flash" src="/flvplayer/jw51/player.swf" flashvars="file=' + href + '&amp;autostart=0&amp;screencolor=white&amp;repeat=no&amp;volume=50&amp;image='+image+'"/></object>';
			}
			else
			{
				var fmovie ='<object width="'+width+'" height="'+theheight+'" name="player" id="player" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param value="/flvplayer/jw51/player.swf" name="movie"/><param name="wmode" value="transparent" /><param value="true" name="allowfullscreen"><param value="always" name="allowscriptaccess"><param value="file=' + href + '&amp;autostart=0&amp;screencolor=white&amp;repeat=always&amp;volume=50" name="flashvars"><embed name="player1" id="player2" width="'+width+'" height="'+theheight+'" wmode="transparent" allowfullscreen="true" allowscriptaccess="always"  type="application/x-shockwave-flash" src="/flvplayer/jw51/player.swf" flashvars="file=' + href + '&amp;autostart=0&amp;screencolor=white&amp;repeat=no&amp;volume=50"/></object>';
			}
									  
			  
			$(fmovie).insertBefore(this);
			$(this).hide();
	});
	
	
	$('.instructievideo-listing a[href$=".flv"]').click(function(event){
		
		event.preventDefault();
		
		var href=$(this).attr('href');
		var image = "";
		width = 666;
		height = 375 ; //zonder balk
		balk = 23;
		theheight = parseInt(height+balk);

		var fmovie ='<object width="'+width+'" height="'+theheight+'" name="player" id="player" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param value="/flvplayer/jw51/player.swf" name="movie"/><param name="wmode" value="transparent" /><param value="true" name="allowfullscreen"><param value="always" name="allowscriptaccess"><param value="file=' + href + '&amp;autostart=1&amp;screencolor=white&amp;repeat=always&amp;volume=50" name="flashvars"><embed name="player1" id="player2" width="'+width+'" height="'+theheight+'"  wmode="transparent"  allowfullscreen="true" allowscriptaccess="always"  type="application/x-shockwave-flash" src="/flvplayer/jw51/player.swf" flashvars="file=' + href + '&amp;autostart=1&amp;screencolor=white&amp;repeat=no&amp;volume=50"/></object>';
			  
		$('#mplayer').html(fmovie);
	});
	
			
	$('a.openclose').live('click', function(event)
	{		
		event.preventDefault();
		var elm = $(this).attr('href');
		if( $(elm).hasClass('closed') )
		{
			$(this).html('-');
			$(elm).show('fast');
			$(elm).removeClass('closed').addClass('opened');
		}
		else
		{
			$(this).html('+');
			$(elm).hide('fast');
			$(elm).addClass('closed').removeClass('opened');
		}
		  
	});
	
	$('div.xhrget .xhrarea a').live('click', function(event){
		
		if( $(this).hasClass('openclose') )
		{
			return;
		}
		
		if( $(this).parent().hasClass('clip') )
		{
			return;
		}
													   
		var uid = '#'+ $(this).parents('.xhrget').eq(0).getUID();
		if( $(this).parents('.header').length > 0 )
		{
			$(this).parents('.header').eq(0).append('<span class="loading"></span>');
		}
		else
		{
			$(uid).append('<span class="loading"></span>');
		}
		var vurl = $(this).attr('href');
		event.preventDefault();

		$.ajax({ async : true, url: vurl, success: function(data){
				//alert(data);	
				$('.loading').remove();
				$(uid).css( { opacity : 0 } ).html(data).animate({ opacity : 1 }, 1000);
				if( $(uid).attr('rel') != '')
				{
					var colleague = '#'+$(uid).attr('rel');
					$(colleague).html(data).show('fast');
				}
				
			}
		});			  
	});
	
	$('#CommentComment').live('focusin', function(){
		if( $(this).val() == 'Schrijf je reactie') 
		{
			$(this).val('');
		}
	});
	
	$('#CommentAddForm').live('submit', function(){
		
		var vurl = $(this).attr('action');
		var data = $(this).serialize();
		$('#CommentComment').val('');
		//$(this).serialize()
		
		$.ajax({ type : 'POST', async : true, data : data, url: vurl, success: function(data){
			
			$('#cclip-comments').html(data);
			
			}
		});	
					
		return false;
	});
	
	$('span.xhrget .xhrarea a').live('click', function(event){
														
														
		$(this).html('<span class="loading"></span>');
		var vurl = $(this).attr('href');
		event.preventDefault();
		var uid = '#'+$(this).closest('.xhrget').insertBefore(tthis).getUID();
		$.ajax({ async : true, url: vurl, success: function(data){
				//alert(data);	
				$(uid).replaceWith(data).show('fast');
			}
		});
		
								  
	});


	$('div.xhrstart').each(function(){
			//						alert('start');
		$(this).hide();
		var uid = '#'+$(this).getUID();
		var vurl = $(this).find('a.xhrstart').attr('href');
		$.ajax({ async : true, url: vurl, success: function(data){
				//alert(data);	
				$(uid).html(data).css({opacity:0}).show().addClass('xhrstartloaded').animate({opacity:1}, 300);
				
				$('#clip-viewer-cnt').each( function()
				{
				
					if( $(this).find('object').length == 0)
					{
						// als er geen filmpje speelt, klik dan op de eerste
						$('ul.clip-listing a:first').click();
					}
				
				});
			}
		});
	});
/**/	

	$('.favorites #home #favorites-items a').click(function(){
		$('#stage-1').click(); 
	});
	
	$('#stage-1').live('click', function(){
	   	$('#home .item').hide(); // for next time
		$('#home').hide();
		$(this).removeStage1();
		$('.message').closeMessage();	
		$('body').removeClass('bw');		
		$('#favorite-show-feed a.close-viewer').click();
	});
	
	$('.message').each( function(){
	
		var fm = $(this);
		fm.createStage1();
		fm.append('<span class="close-message">x</span>');
	
		$('.close-message').click( function(){										
			//alert('click');
			fm.closeMessage();
			} 
		);
		
		var timer = window.setTimeout( function(){ 
			fm.closeMessage();
		}, 3000 );
	});
	
	
	
	$('object#animator').after('<p class="workspace-switcher"><a id="toggleworkingspace" class="nowarnings"><span>Vergroot werkruimte</span></a></p>');
		
	$('a#toggleworkingspace').click(function(){
			toggleworkingspace();		
	});
	
	
	$('#UserUsername').blur(function(){
									 
		$('#usernamehelp span.message').html('...');
			var username = $(this).val();
			 //alert(username);
			if(username != '')
			{
				var url = '/users/xhr_check_username/'+username;
				$.get( url , function(data)
				{
					if (data.indexOf('OK') > 1)
					{
					}
					else
					{
						$('#usernamehelp').show();
						$('#usernamehelp span.message').html(data);
						
						$('a.tip').click(function(event)
						{
							event.preventDefault();
							var tip = $(this).html();
							$('#UserUsername').val(tip);
							$('#usernamehelp').hide();
						});
					}
	
				});
			
			}
			 
	});

	
	/*
	$('#CommentComment').live('keydown', function(event){
		
		if( event.keyCode == 13 )
		{
			$('#CommentAddForm').submit();
		}
		
	});
	*/
	
	
	$('#cclip-holylike a').live('click', function(event){
		
		event.preventDefault();
		var favcount = parseInt($(this).find('.favcount').html()) + 1;
		$(this).find('.favcount').html(favcount).show();
		
		var vurl = $(this).attr('href');
				//alert(url);
				$.ajax({ 
					   async : true, 
					   type : 'get',
					   dataType : 'json',
					   url: vurl, 
					   success: function(returndata){
						   
						    //alert(returndata.clipname);
							$(this).html( returndata.html );
					}
				});
		return false;		
	} );
	
	
	$('#ccontest-main #search-results-clips .paging-next a').live('click', function(event){
	
		event.preventDefault();
		$('ul.clip-listing li:first').insertAfter('ul.clip-listing li:last');
		$('ul.clip-listing li').eq(1).find('a').click();
																	 
	});
	
	
	$('#ccontest-main  #search-results-clips .paging-previous a').live('click', function(event){
	
		event.preventDefault();
		$('ul.clip-listing li:last').insertBefore('ul.clip-listing li:first');
		$('ul.clip-listing li').eq(1).find('a').click();
																	 
	});
	
	
});
	
(function($) {
    $.fn.extend({
				
				
							 
		showClipFromBalk : function (){
	
				var href = $(this).attr('href').split('#');
				var clip_id = href[1].replace('clip-','');
				
				$('#holyPlayerContainer').html('');
				
				var offset = $(this).offset();
				var left = offset.left -217; // viewer = 516, breedte = 82. 516 / 2 = 258. 258 - 41 = 
				
				if( left + 550 > $(document).width() )
				{
					newleft = $(document).width() - 550;
					movedleft = left - newleft;
					var pointerbgpos = -284 + movedleft + 'px';
					//alert(pointerbgpos);
					//#view-clip .pointer{background:url(img/clipplayer-pointer.png) no-repeat -284px 0;
					$('#view-clip .pointer').css({'background-position' : pointerbgpos+' 0'});					
					left = newleft;
				}
				else
				{
					//alert(left);
					//#view-clip .pointer{background:url(img/clipplayer-pointer.png) no-repeat -284px 0;
					$('#view-clip .pointer').css({'background-position' : '-284px 0'});
				}
				
				var	next_clip_url = "";
				var respond_url = "";


				var clipdata = $(this).parent('li').find('.clip-data');
				var title = $('.clip-title', clipdata).html();
				var views = $('.clip-views', clipdata).html();

				$('#holyPlayer-clip-data h3').html(title);
				//$('#holyPlayer-clip-data p.views').html(views);
				
				
				$('#view-clip').css( 'left', left+'px' );
				$('#view-clip').slideDown();
				
				
				if( $('body').hasClass('afd-home') )
				{
					var playercolor = '69a4a0'; 
				}
				if( $('body').hasClass('afd-lesmethode') )
				{
					var playercolor = 'ff9a56'; 
				}
				if( $('body').hasClass('afd-voorscholen') )
				{
					var playercolor = 'a9ceea'; 
				}
				if( $('body').hasClass('afd-voororganisaties') )
				{
					var playercolor = '679bc0'; 
				}
				if( $('body').hasClass('afd-animaties') )
				{
					var playercolor = 'd43577'; 
				}
				if( $('body').hasClass('afd-blog') )
				{
					var playercolor = 'ff7be8'; 
				}
				if( $('body').hasClass('afd-over') )
				{
					var playercolor = 'f7bc43'; 
				}
				if( $('body').hasClass('afd-automaat') )
				{
					var playercolor = '7ecc16'; 
				}
				//alert(playercolor);
				var flashvars = "clip_id="+clip_id;
				flashvars += "&amp;autoplay=1";
				flashvars += "&amp;repeat=0";
				flashvars += "&amp;panelcolor=0x"+playercolor;
				flashvars += "&amp;pureplayer=1";
				flashvars += "&amp;mute=0";
				flashvars += "&amp;next_url="+next_clip_url;
				flashvars += "&amp;react_url="+respond_url;
				
				
				var fmovie ='<object width="502" height="377" name="player" id="player" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param value="/tests/holyPlayer.swf" name="movie"/><param value="' + flashvars + '" name="flashvars"><param name="wmode" value="transparent"><embed name="player1" id="player1" width="502" height="377" allowfullscreen="true" allowscriptaccess="always" wmode="transparent" type="application/x-shockwave-flash" src="/tests/holyPlayer.swf" flashvars="' + flashvars + '"/></object>';
			  
				$('#view-clip .cnt').css({height:'440px'});
				$('#holyPlayerContainer').append(fmovie);
		} ,


							 
		showClipFromListing : function (){
	
				//alert('clipfromlisting');
				var href = $(this).attr('href').split('#');
				var clip_id = href[1].replace('clip-','');
				var url = "";
				var	next_clip_url = "";
				var respond_url = "";
				
				
				if( $('body').hasClass('afd-home') )
				{
					var playercolor = '69a4a0'; 
				}
				if( $('body').hasClass('afd-animaties') )
				{
					var playercolor = 'd43577'; 
				}
				else
				{
					var playercolor = $('#domaincolor2').html();
				}
				var clipdata = $(this).parent('li').find('.clip-data');
				var title = $('.clip-title', clipdata).html();
				//var views = $('.clip-views', clipdata).html();


				$('#clip-viewer-clip-data h3').html(title);
				//$('#clip-viewer-clip-data p.views').html(views);
				
				var flashvars = "clip_id="+clip_id;
				flashvars += "&amp;autoplay=1";
				flashvars += "&amp;repeat=0";
				flashvars += "&amp;panelcolor=0x"+playercolor;
				flashvars += "&amp;pureplayer=1";
				flashvars += "&amp;mute=0";
				flashvars += "&amp;next_url="+next_clip_url;
				flashvars += "&amp;react_url="+respond_url;
				
				var fmovie ='<object width="543" height="407" name="player" id="player" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param value="/tests/holyPlayer.swf" name="movie"/><param value="' + flashvars + '" name="flashvars"><param name="wmode" value="transparent"><embed name="player1" id="player1" width="543" height="407" allowfullscreen="true" allowscriptaccess="always" wmode="transparent" type="application/x-shockwave-flash" src="/tests/holyPlayer.swf" flashvars="' + flashvars + '"/></object>';

				/*
				var fmovie ='<object width="502" height="377" name="player" id="player" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param value="/tests/holyPlayer.swf" name="movie"/><param value="' + flashvars + '" name="flashvars"><param name="wmode" value="transparent"><embed name="player1" id="player1" width="502" height="377" allowfullscreen="true" allowscriptaccess="always" wmode="transparent" type="application/x-shockwave-flash" src="/tests/holyPlayer.swf" flashvars="' + flashvars + '"/></object>';
				*/
				
				//alert(fmovie);
				
				$('#clip-viewer-cnt').html(fmovie);
				
		} ,
		
		showNomineeClip : function(){
			
				var href = $(this).attr('href').split('#');
				var clip_id = href[1].replace('clip-','');
				var playercolor = $('#domaincolor2').html();
				
				$('.clip-listing li.clip').removeClass('current');
				
				var listitem = $(this).parent('li');
				listitem.addClass('current');
				
				var clipdata = listitem.find('.clip-data');
				var title = $('.clip-title', clipdata).html();
				$('#clip-viewer-clip-data h3').html(title);
				
				var	next_clip_url = "";
				var respond_url = "";
				
				var flashvars = "clip_id="+clip_id;
				flashvars += "&amp;autoplay=1";
				flashvars += "&amp;repeat=0";
				flashvars += "&amp;panelcolor=0x"+playercolor;
				flashvars += "&amp;pureplayer=1";
				flashvars += "&amp;mute=0";
				flashvars += "&amp;next_url="+next_clip_url;
				flashvars += "&amp;react_url="+respond_url;
				
				var fmovie ='<object width="543" height="407" name="player" id="player" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param value="/tests/holyPlayer.swf" name="movie"/><param value="' + flashvars + '" name="flashvars"><param name="wmode" value="transparent"><embed name="player1" id="player1" width="543" height="407" allowfullscreen="true" allowscriptaccess="always" wmode="transparent" type="application/x-shockwave-flash" src="/tests/holyPlayer.swf" flashvars="' + flashvars + '"/></object>';
				
				$('#clip-viewer-cnt').html(fmovie);
				
				$('#nominee-story .cms-text').html(  $('#nominee-story-'+clip_id ).html()  );
				
		},
		
		showActiveClip : function (){
			
				var hash = $(this).attr('href').split('#');
				var clip_id = hash[1].replace('clip-','');
				actionhtml = "";
				if( $(this).parent('li').hasClass('myclip') )
				{
					var actionhtml = $(this).parent('li').find('div.actions').html(); 
				}
				
				// om the next urkl te berekenen, checken we de index van deze clip binnen 
				//var index = $(this).index('.clip-listing li a');
				//alert(index);
				
				//if( $('#group_role').html() == 'docent' )
				//{
				var vurl = '/'+$('#current_community_slug').html()+'/'+ $('#current_language_code').html() +'/clips/view/'+clip_id+'.xhr';
				//}
				//else
				//{
				//	var vurl = '/'+$('#current_community_slug').html()+'/'+ $('#current_language_code').html() +'/clips/view/'+clip_id;
				//}
				//alert(url);
				$.ajax({ 
					   async : true, 
					   type : 'get',
					   dataType : 'json',
					   url: vurl, 
					   success: function(returndata){
						   
						    //alert(returndata.clipname);
							$('#view-clip').html( returndata.html );
							
							var	next_clip_url = "";
							var reply_url = returndata.reply_url;							
							
							var flashvars = "clip_id="+clip_id;
							flashvars += "&amp;autoplay=1";
							flashvars += "&amp;repeat=0";
							flashvars += "&amp;lang=nl";
							flashvars += "&amp;panelcolor=0x"+$('#domaincolor2').html();
							flashvars += "&amp;activeplayer=1";
							flashvars += "&amp;mute=0";
							flashvars += "&amp;next_url="+next_clip_url;
							flashvars += "&amp;react_url="+reply_url;
							
							/*
							var fmovie ='<object width="502" height="377" name="player" id="player" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param value="/tests/holyPlayer.swf" name="movie"/><param name="wmode" value="transparent"><param value="' + flashvars + '" name="flashvars"><embed name="player1" id="player1" width="502" height="377" allowfullscreen="true" allowscriptaccess="always"  type="application/x-shockwave-flash" wmode="transparent" src="/tests/holyPlayer.swf" flashvars="' + flashvars + '"/></object>';
							*/
							var fmovie ='<object width="470" height="352" name="player" id="player" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param value="/tests/holyPlayer.swf" name="movie"/><param name="wmode" value="transparent"><param value="' + flashvars + '" name="flashvars"><embed name="player1" id="player1" width="470" height="352" allowfullscreen="true" allowscriptaccess="always"  type="application/x-shockwave-flash" wmode="transparent" src="/tests/holyPlayer.swf" flashvars="' + flashvars + '"/></object>';
			
							 
							$('#view-clip').show();
							/* 
							$('#view-clip .cnt').css({height:'440px'});
							*/
							$('#holyPlayerContainer').html(fmovie);
							
							
							/* als het om mijn clip gaat, heeft de listitem een actions div, die kan naar #clip-viewer-actions */
							$('#clip-viewer-actions').html(  actionhtml  );
							
					}
				});
	
		},
		
		
		showSingleClip : function (){
			
 				var clip_id = $('#clip_id').html();
				var	next_clip_url = $('#next_clip_url').attr('href');
				var reply_url = $('#replay_url').html();							
							
							var flashvars = "clip_id="+clip_id;
							flashvars += "&amp;autoplay=1";
							flashvars += "&amp;repeat=0";
							flashvars += "&amp;lang=nl";
							flashvars += "&amp;panelcolor=0x"+$('#domaincolor2').html();
							flashvars += "&amp;activeplayer=1";
							flashvars += "&amp;mute=0";
							flashvars += "&amp;next_url="+next_clip_url;
							flashvars += "&amp;react_url="+reply_url;
							
							var fmovie ='<object width="470" height="352" name="player" id="player" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param value="/tests/holyPlayer.swf" name="movie"/><param name="wmode" value="transparent"><param value="' + flashvars + '" name="flashvars"><embed name="player1" id="player1" width="470" height="352" allowfullscreen="true" allowscriptaccess="always"  type="application/x-shockwave-flash" wmode="transparent" src="/tests/holyPlayer.swf" flashvars="' + flashvars + '"/></object>';
			
							$('#holyPlayerContainer').html(fmovie);
		},
		
		removeStage1:function()
		{
			//alert('closing time');
			$('html').css({height : '100%', 'overflow-y' : 'auto'});
			$('#stage-1').hide();
			$('#stage-1-content').html('');
			$('#share-window').hide();		
			$('#mask .frame img').css({ 'margin-top' : '-2px' });

		},
		
		closeMessage : function()
		{
			//alert('close');
			$(this).hide('fast');
			//$(this).slideToggle('fast').removeStage1();
		},
		createContentStage : function(options) {

		},
		
		removeContentStage:function()
		{
			$('html').css({height : 'auto', 'overflow-y' : 'auto'});
			$('#content-stage-1').hide();
			$('#content-stage-1-content').html('');
		}
		
		
    });
})(jQuery);	


function shareClip(clip_id){
	
	document.location.hash = 'cclip-actions-elsewhere';
	
	}
function likeClip(clip_id){
	
	$('#cclip-holylike a').click();
	
	}
function commentOnClip(clip_id){
	
	document.location.hash = 'cclip-commentform';
	
	}
