$(document).ready(function()
{
	if($('.video_container').length)
	{
		new VideoPlayer(
			$('.video_container').attr('id'), 
			'start', 
			{
				basePath: base_path,
				debug: false,
				googleAnalytics: true
			}
		);
	}
	
	var eoftFacebook = new cuisineFacebook({
		basePath: base_path,
		debug: false,
		siteName: "European Outdoor Film Tour",
		locale: language
	});
	
	if($('.facebook_news').length)
	{
		eoftFacebook.getNewsTeaser($('.facebook_news'), 2);
	}

});


$(window).load(function()
{
	if($("#container").pngFix)
		$("#container").pngFix();
	
	slideshow.init();
	move_footer_down();
});


function move_footer_down()
{
	$('#footer_container').css("margin-top", 0);
	var footer_offset = $(window).height() - $('#footer_container').offset().top - $('#footer_container').height();
	
	if(footer_offset > 0)
	{
		$('#footer_container').css("margin-top", footer_offset+"px");
		
		$(window).resize(function()
		{
			move_footer_down();
		});
	}
}


var slideshow = {
	
	'imageCount': 0,
	'currentImage': 0,
	'speed': 3000,
	'transition': 1000,
	'showNextTimeout': false,
	
	'init': function()
	{
		// check if we have a slideshow on the page
		if($('ul.slideshow').length)
		{
			// get image count
			this.imageCount = $('ul.slideshow li').length;
			
			// only start if we have more than one image
			if(this.imageCount > 1)
			{
				$('ul.slideshow li').css('overflow', 'hidden');
				$('ul.slideshow li').css('width', $('ul.slideshow').width());
				$('ul.slideshow li').css('position', 'absolute');

				// get slideshow height from first image
				var height = $('ul.slideshow li:first img').height();
				$('ul.slideshow').height(height);
				$('ul.slideshow li').height(height);

				// show next image on click
				$('ul.slideshow li').click(function()
				{
					slideshow.showNextImage();
				})

				// start slideshow
				this.showNextTimeout = setTimeout(slideshow.showNextImage, slideshow.speed);
			}
		}
	},
	
	'showNextImage': function()
	{
		// clear timeout to prevent overlapping of click event and timeer
		clearTimeout(this.showNextTimeout);
		
		// calculate next image
		var next = (slideshow.currentImage + 1 < slideshow.imageCount) ? slideshow.currentImage + 1 : 0;
		
		// fade in/out images
		$('ul.slideshow li').eq(next).fadeIn(slideshow.transition);
		$('ul.slideshow li').eq(slideshow.currentImage).fadeOut(slideshow.transition);
		
		// set current image and fire next timeout
		slideshow.currentImage = next;
		this.showNextTimeout = setTimeout(slideshow.showNextImage, slideshow.speed+slideshow.transition);
	}
}
