/***********************VIDEO EMBED FUNCTIONS******************************************/
//Start with onload add:

$(function(){ //Function to load video in a new overlay div and play it.
	$("a.FLVvideo").click(function(event){
		event.preventDefault();
		var regex = /[^/*][.aspx|.asp]/g; //Regex to find if the provided id is a Vimeo id, or a relative link
		var EmbedLink = this.id;
		if(!regex.test(EmbedLink))
	   		EmbedLink = "http://player.vimeo.com/video/" + this.id;
	   
		//Go and start video	
		try {
			var rel = $(this).attr("rel");
			var rel_array = rel.split(";");
			var container = null;
			
			for(x in rel_array){
				var value = rel_array[x].toLowerCase();
				if(value.substr(0,7) == "height:"){
					var Vheight = value.substr(7,value.length);
				}
				if(value.substr(0,6) == "width:"){
					var Vwidth = value.substr(6,value.length);
				}
				if(value.length > 9 && value.substr(0,10) == "container:"){
					container = value.substr(10, value.length);
				}
			}
			$(this).StartEmbed(Vheight, Vwidth, EmbedLink, container);
		}
		catch(e){
			alert("Unfortunately in your browser it is not possible to see this video. You can view this video at: " + EmbedLink);
		}
	});
});


jQuery.fn.extend({
	StartEmbed: function(Vheight, Vwidth, VideoLink, container) { // Embed the video
		$("#videoFrame").remove();
		$(".closebutton").remove();
		$("img:hidden").show();
		if(container == null)
			$(this).find("img").hide();
		
		var TheHtml = "<div class='closebutton' style='text-align:right'><a href='#' title='close'>Sluiten</a></div>" + 
						"<div id='videoFrame' class='hidden' style='width:" + Vwidth + ";height:" + Vheight + ";margin-bottom:15px;'>"
						+  "<iframe src='" + VideoLink + "?byline=0&amp;portrait=0&amp;color=ffffff&amp;loop=0&amp;autoplay=1' width='" + Vwidth + "' height='" + Vheight + "' frameborder='0'></iframe>"
						+ "</div>";

		if(container == null)
			$(this).after(TheHtml);
		else 
		{
			$("#" + container).empty();
			$("#" + container).append(TheHtml);
		}

		$("#videoFrame").fadeIn('slow');
		$(".closebutton").click(function(event) {
			 event.preventDefault();
			$(this).parents().find("img").show();
			$(".closebutton").remove();
			$("#videoFrame").remove();
			$("#NoYouTube").remove();
		});
		return true;
	}
});


/***********************END OF VIDEO EMBED FUNCTIONS************************************/
        
        
    


