$(function(){
	/*
	$("#wsVideo").fancybox({
		fitToView	: false,
		width		: 630,
		height		: 390,
		autoSize	: false,
		closeClick	: false,
		openEffect	: 'elastic',
		closeEffect	: 'none',
		type		: 'swf',
  		swf 		: {'allowfullscreen':'true'}
	});
	*/	
	
	$("#wsVideo").click(function(){
		
		var playerVersion = swfobject.getFlashPlayerVersion(); 
   	 	var majorVersion = playerVersion.major; 
		
		//YouTube support only HTML5 and either the h.264 video codec or the WebM format
		var v = document.createElement('video');
		var webmSupport = !!(v.canPlayType && v.canPlayType('video/webm; codecs="vp8, vorbis"').replace(/no/, ''));
		var h264Support = !!(v.canPlayType && v.canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"').replace(/no/, ''));
		
		if (majorVersion > 0 || webmSupport || h264Support) {
			
			$.fancybox({
				fitToView: false,
				width: 630,
				height: 390,
				autoSize: false,
				closeClick: false,
				openEffect: 'elastic',
				closeEffect: 'none',
				href: this.href.replace(new RegExp("\/v\/", "i"), '\/embed\/'),
				type: 'iframe',
				swf: {
					'allowfullscreen': 'true'
				},
				beforeLoad: function(){
					googleAnalyticsTrackEvent('video', 'play', 'Welcome to Website.com');
				},
				beforeClose: function(){
					googleAnalyticsTrackEvent('video', 'stop', 'Welcome to Website.com');
				}
			});
			
		} else {
			
			var css = 'font-size:16px; padding:20px 20px 5px; line-height:1.3em;';
			
			$.fancybox({
				fitToView: false,
				width: 630,
				height: 390,
				autoSize: false,
				closeClick: false,
				openEffect: 'elastic',
				closeEffect: 'none',
				content: '<div style="'+ css +'">The Adobe Flash Player or an HTML5 supported browser is required to view this video. '
					+ '<br/><br/>- <a href="http://get.adobe.com/flashplayer/" target="_new">Get the latest Flash Player</a>, or <br/>'
					+ '- <a href="http://www.youtube.com/html5" target="_new">Learn more about upgrading to an HTML5 browser</a></div>'
					+ '<br/><div style="'+ css +'">Once installed, visit <a href="/">Website.com</a> again to view the video, or '
					+ 'if you prefer, you can view the video directly at <a href="http://www.youtube.com/watch?v=TRPztXMknL0" target="_new">YouTube</a>.</div>',
				type: 'html'
			});
		}
		
		return false;

	});
		
});

