$(function(){
	$("#container").paginering();
	
	$(".fancybox_gall").fancybox({
								 	cyclic		: true,
								 	onComplete : function()
									{
										if($(".playPause").length == 0)
										{
											$playPause = $("<div />")
																.addClass("playPause")
																.addClass("play")
																.click(playPauseFancybox);
											$("#fancybox-outer").append($playPause);	
											
											$("#fancybox-left, #fancybox-right").click(clearPlay);
										}
									},
									onClosed : function()
									{
										clearPlay();
										$(".playPause").remove();	
									}
								 });
	
	playPauseFancybox = function()
	{
		if($(".play").length > 0)
		{
			var $el = $(".play");
			$el.removeClass("play").addClass("pause");	
			$el.data('interval', setInterval(function(){
													  $.fancybox.next();
													  }, 5000)); // The interval
		}
		else
		{
			clearPlay();
		}
	}
	
	clearPlay = function()
	{
		var $el = $(".pause");
		$el.addClass("play").removeClass("pause");
		clearInterval($el.data('interval'));		
	}
});

