$(document).ready(function()
{
	$('.4seasons_video').each(function()
	{
		var video_id = this.id.replace("video_", "");
		
		embed_4seasons_player(video_id, 830, 466);
	});
	
	if($('.video_container').length)
	{
		new VideoPlayer(
			$('.video_container').attr('id'), 
			'start', 
			{
				basePath: base_path,
				debug: false,
				googleAnalytics: true
			}
		);
	}
	
	var banffFacebook = new cuisineFacebook({
		basePath: base_path,
		debug: false,
		siteName: "Banff Mountain Film Festival",
		locale: language
	});
	
	if($('.facebook_news').length)
	{
		banffFacebook.getNewsTeaser($('.facebook_news'), 3);
	}
});


$(window).load(function()
{
	slideshow.init();
});


function embed_4seasons_player(video_id, width, height)
{
	var swfVersionStr = "10.0.0";
	var xiSwfUrlStr = "playerProductInstall.swf";
	var flashvars = {};

	var pathTo = "http://4-seasons.tv/sites/all/themes/fourseasons/player/"; 
	var pathServer = "http://4-seasons.tv";

	// URL AUF VIDEO-XML
	flashvars["playlistfile"] = pathServer + "/video/"+video_id+"/xml";

	flashvars["logo.file"]   	= pathTo+"cornerbug.png"; 
	flashvars["logo.margin"]   	= 0;
	flashvars["logo.out"] 	   	= 0.5; 
	flashvars["logo.over"]     	= 1; 
	flashvars["logo.hide"]     	= false; 
	flashvars["logo.timeout"]  	= 3 
	flashvars["logo.position"] 	= 'top-right'; 

	flashvars["autostart"] = "true";
	flashvars["playerready"] = "onPlayerStart";
	flashvars["repeat"] = "list";
	flashvars["icons"] = "false";

	var plugins = new Array();
	plugins.push(pathTo+"FsTv.swf");
	plugins.push(pathTo+"FsProducts.swf");
	plugins.push(pathTo+"rtmpt.swf");

	flashvars["plugins"] = plugins.join(",");

	flashvars["FsTv.path"] = pathServer; 
	flashvars["FsTv.streamer"] = "rtmp://fms.0F99.edgecastcdn.net/000F99/_definst_"; 

	flashvars["FsTv.afterplaylist"] = "true";
	flashvars["FsTv.taf"] = "false"; 

	flashvars["FsProducts.path"] = pathServer; 
	flashvars["FsProducts.tracking"] = "true"; 

	flashvars["rtmpt.module"] = pathTo+"RTMPTMediaProvider.swf";
	flashvars["rtmpt.debug"] = "false";

	flashvars["skin"] = pathTo+"modieus.swf"; 

	var params = {};
	params.quality = "high";
	params.bgcolor = "#ffffff";
	params.allowscriptaccess = "always";
	params.allowfullscreen = "true";

	var attributes = {};
	attributes.id = "player";
	attributes.name = "player";
	attributes.align = "left";

	swfobject.embedSWF(
	    pathTo+"player.swf", 'video_'+video_id, 
	    width,height+32, 
	    swfVersionStr, xiSwfUrlStr, 
	    flashvars, params, attributes);
}


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);
	}
}
