$('document').ready(function () {
	var videoLinks = $('.video-modal');
	if (videoLinks.length > 0) {
		videoLinks.each(function () {
			var videoId = $(this).attr('name').split(':')[0].split('.')[0];
			var videoFilename = $(this).attr('name').split(':')[0];
			var videoWidth = $(this).attr('name').split(':')[1];
			var videoHeight = $(this).attr('name').split(':')[2];
			$('body').append('<div id=videoModal-' + videoId + ' ><div id=videoPlayer-' + videoId + '></div></div>');

			$(this).click(function () {
				var createPlayer = function () {
					jwplayer('videoPlayer-' + videoId).setup({
						file: videoFilename,
						modes: [
							{ type: 'flash', src: '/Content/Assets/player.swf' },
							{
								type: 'html5',
								config: {
									file: 'http://d1c15iwb1hhton.cloudfront.net/' + videoFilename,
									provider: "video"
								}
							},

						],
						controlbar: 'over',
						provider: 'rtmp',
						streamer: 'rtmp://sxtez8pl7xaan.cloudfront.net/cfx/st/',
						width: videoWidth,
						height: videoHeight,
						autostart: 'true'
					});
				}
				$('#videoModal-' + videoId).modal({
					minWidth: parseInt(videoWidth),
					minHeight: parseInt(videoHeight),
					opacity: 80,
					overlayCss: { backgroundColor: "#000" }
				});
			
				createPlayer();
				return false;
			});
		});
	}


});
