	
	/*
		
		jYouTube		: Koppel automatisch de YouTube links in een popup gehost door YouTube zelf
		Created by		: Marc Hensen (Nettt Interactieve Media)
		Date			: 6-10-2009
		Url				: www.nettt.nl/youtube/
				
	*/
			
	(function($){ 
	
		$.fn.extend({ 

			jYouTube: function(settings) { 
				
				if(!settings){
					var settings = {};
				}
				
				settings.thumb = (settings.thumb == undefined) ? true : settings.thumb;
				settings.popupWidth = (settings.popupWidth == undefined) ? 320 : settings.popupWidth;
				settings.popupHeight = (settings.popupHeight == undefined) ? 240 : settings.popupHeight;

				this.each(function(){
					
					var url = this.href;
					var results = url.match("[\\?&]v=([^&#]*)");
					var vid = ( results === null ) ? url : results[1];
					
					if(settings.thumb == true){
					
						$(this).html("<img src=\"http://img.youtube.com/vi/"+vid+"/3.jpg\" title=\""+ $(this).html() +"\" border=\"0\" /><img border=\"0\" onmouseover=\"this.src ='/images/layout/play_button_hover.png'\" onmouseout=\"this.src ='/images/layout/play_button.png'\" src=\"/images/layout/play_button.png\" title=\"Watch via YouTube\" class=\"play\" />");
					
					}
					
					$(this).click(function(){
						
						var yUrl = "http://www.youtube.com/watch_popup?v=" +vid;
												
						var p = window.open(yUrl,"youtubePopup","location=1,status=1,scrollbars=1,width="+ settings.popupWidth +",height="+ settings.popupHeight);
						p.opener = null;
						p.focus();
						
						return false;
						
					});
					
				});
				
				return false;
			
			}
			
		}); 
		
	})(jQuery);

