var youtube	= {

	$window		: null,
	$lightbox	: null,
	$embedArea	: null,

	$minHeight	: null,

	/**
	* CONTROL METHODS
	*/
	getEmbedCode: function(e)
	{
		var pageID		= $(e.currentTarget).siblings('.pageID').html();
		var youtubeID	= $(e.currentTarget).siblings('.youtubeID').html();

		$.post(baseURL + 'webservice/youtube',
		{
			pageID		: pageID,
			youtubeID	: youtubeID
		},
		function(data)
		{
			if(data.status == 'ok')
			{
				if(navigator.userAgent.toLowerCase().indexOf('msie 6') > -1 || navigator.userAgent.toLowerCase().indexOf('msie 7') > -1)
				{
					//Adform.Tracking.Track(32823,120545);
				}
				else
				{
					_gaq.push(['_trackEvent', '_root/youtube/', youtubeID]);
				}
				youtube.showLightbox(data.response);
			}
			else if(data.status == 'error')
			{
				alert(data.response);
			}
		},
		'json');
	},
	showLightbox: function(embedCode)
	{
		window.scrollTo(0,0);

		youtube.$lightbox.find('.content').addClass('youtube-lightbox');
		youtube.$embedArea.empty();
		youtube.$embedArea.html(embedCode);
		youtube.$lightbox.fadeIn(600);
		
		var _winHeight	= this.$window.height() + this.$window.scrollTop();
		youtube.$lightbox.find('.background').height(Math.max(youtube.$minHeight, _winHeight));
	},
	hideLightbox: function(embedCode)
	{
		youtube.$embedArea.empty();
		youtube.$lightbox.hide();
	},

	/**
	* INIT METHODS
	*/
	init: function()
	{
		youtube.$window		= $(window);
		youtube.$lightbox	= $('#lightbox');
		youtube.$embedArea	= $('#embedarea');

		youtube.$minHeight	= $('#wrapper').height() + $('#footer').height() + 190;

		youtube.initLightbox();

		$('.youtube-with-text .image').each(function()
		{
			var $this	= $(this);
			$this.bind('click', youtube.getEmbedCode);
		});
	},
	initLightbox: function()
	{
		this.$lightbox.find('.close').bind('click', youtube.hideLightbox);
		this.$lightbox.find('.background').bind('click', youtube.hideLightbox);
	}
};

$(document).ready(youtube.init);
