Prolific.app('YouTube', function (app) {

	app.feature('thumbs', function (thumbs) {
	
		//Bind live events
		$('.youtube .thumbs a')
			.live('mouseenter', {}, function (e) {
				var $this = $(this),
					$thumb = $this.find('img.thumb'),
					$thumbData = $this.find('input.thumbsrc'),
					curThumb = 1;
					
				$this.data('thumbInterval', window.setInterval(function () {
						$thumb.attr('src', $thumbData.eq(curThumb).val());
						curThumb += 1;
						if (curThumb >= $thumbData.length - 1) {
							curThumb = 0;
						}
					}, 500)
				);				
				
			})
			.live('mouseleave', {}, function (e) {
				var $this = $(this);
				window.clearInterval($this.data('thumbInterval'));
			})
			.live('click', {}, function () {
				var $former = $(this).parent().parent().find('a.selected').removeClass('selected'),
					$this = $(this).addClass('selected'),
					$container = $('.youtube .video'),
					$movie = $('object', $container),
					$param = $('param[name=movie]', $movie),
					$embed = $('embed', $movie),
					$hiddens = $container.find('input[type="hidden"]'),
					$title = $hiddens.filter('.title'),
					$desc = $hiddens.filter('.desc'),
					$url = $hiddens.filter('.url');
				$param.attr('value', 'http://www.youtube.com/v/' + $this.attr('id').replace('vid_', '') + '&hl=en_US&fs=1&ccolor1=0x#ffffff&color2=0x000000');
				$embed.attr('src', 'http://www.youtube.com/v/' + $this.attr('id').replace('vid_', '') + '&hl=en_US&fs=1&ccolor1=0x#ffffff&color2=0x000000');
				$title.val($this.find('input.title').val());
				$desc.val($this.find('input.desc').val());
				$url.val($this.find('input.url').val());
				$movie.replaceWith($movie.clone(true));
			});
		
		thumbs.method('select', function (which) {
			$('.youtube .thumbs a').eq(which).click();
			return this;
		});
		
	});
	
	//Connect to Facebook
	app.module('sharing', function () {
		$(function () {
			Prolific.Facebook.sharing.connect({
				selector: '.youtube .video',
				getInfo: function () {
					var $this = $(this);
					return {
						message: '',
						attachment: {
							name: $this.find('.title').val(),
							description: $this.find('.desc').val(),
							href: $this.find('.url').val()
						},
						action_links: [{
							text: 'Berlin Lacrosse Camp',
							href: 'http://www.berlin-lacrosse-camp.de'
						}],
  						user_message_prompt: 'Comments:'

					};
				}
			});
		});
	});
	
});
