﻿Publicis.namespace('Publicis.ContentOverlay', function ()
{
	return {
		loaded: function ($placeholder)
		{
			if ($placeholder.has('.video_container').length > 0)
			{
				Publicis.ContentOverlay.VideoPlayer.loaded($placeholder);
			}
			else if ($placeholder.has('.pictures_container').length > 0)
			{
				Publicis.ContentOverlay.PictureGallery.loaded($placeholder);
			}
		}
	};
});

Publicis.namespace('Publicis.ContentOverlay.VideoPlayer', function ()
{
	var ready = function (player_id)
	{
		var froogaloop = $f(player_id);

		froogaloop.addEvent('play', function (data)
		{
			$('.video_overlay').hide();
		});

		froogaloop.addEvent('finish', function (data)
		{
			$('.video_overlay').show();
		});
	};

	return {
		loaded: function ($placeholder)
		{
			var $iframe = $('div.video_container iframe', $placeholder);
			if ($iframe.length > 0)
			{
				$iframe.attr('id', 'vid_player');

				$f($iframe.get(0)).addEvent('ready', ready);
				$('.video_overlay_table').css({ height: $iframe.height() });
			}
		}
	};
});

Publicis.namespace('Publicis.ContentOverlay.PictureGallery', function ()
{
	return {
		loaded: function ($placeholder)
		{
			var $table = $('.pictures_table');
			var $images = $('.pictures_table a', $placeholder);

			var first = $images.eq(0).children('img');
			$table.css({ left: 420 - (first.width() / 2) - 50 });

			$images.click(function ()
			{
				var $this = $(this);
				$table.animate({ left: 420 - $this.position().left - ($this.width() / 2) }, 800, 'easeInOutCubic');

				return false;
			});
		}
	};
});

