jQuery.noConflict();
jQuery(document).ready(function($){
	var playerOverlaySelectors = '#showreel-player #player-overlay';
	
	$('ul#background-image-fader').innerfade({ speed:'slow', timeout:5000, type:'sequence', containerheight:'230px' });
	
	function slideBackgroundIn() {
		$(this).stop();
		$(this).animate({backgroundPosition: '0px -22px'}, 200);
	}
	function slideBackgroundOut() {
		$(this).stop();
		$(this).animate({backgroundPosition: '0px 0px'}, 200);
	}
	$('div#navi ul li a').css({backgroundPosition: '0px 0px'});
	$('div#navi ul li a').hover(slideBackgroundIn,slideBackgroundOut);
	
	function slideIn(contentID) {
		var $contentContainer = $(contentID);
		$contentContainer.siblings().stop().css({marginLeft:800});
		$contentContainer.stop().css({marginLeft:800}).animate({
		  marginLeft: 0
		});
	}
	function slideOut(contentID) {
		var $contentContainer = $(contentID);
		$contentContainer.stop().css({marginLeft:0}).animate({
		  marginLeft: 800
		});
	}
	$('.home ul#box-navigation li a.internal').click(function() {
		slideIn('#content-'+$(this).parent().attr('id'));
		return false;
	}); 
	$('div.content-part a.close').click(function() {
		slideOut('#'+$(this).parent().parent().attr('id'));
		return false;
	});
	
	var player = undefined;
	$('#thumbs a.videothumb').click(function() {
		var id = $(this).attr('id').replace(/thumb-vid-/g, '');
		
		showOverlay(true);
		
		$('#thumbs a.videothumb').removeClass('active');
		$(this).addClass('active');
		
		$('.clipinfo').hide();
		$('.clipinfo.vid-'+id).show();
		
		if(player == undefined) {
			player = flowplayer('splayer', {
				allowfullscreen: false, 
				src: '/assets/templates/seven/flowplayer-3.2.7-0.swf'
			}, {
				clip: {
					url: $(this).attr('href'),
					autoPlay: true,
					onStart: function(clip){
						showOverlay(false);
					}
				},
				onLoad: function() {
					$(playerOverlaySelectors).addClass('loaded');
				}
			});
		}
		else {
			player.play($(this).attr('href'));
		}
		
		return false;
	}).eq(0).click();
	
	function showOverlay(show) {
		if(show) {
			$(playerOverlaySelectors).show();
		}
		else {
			$(playerOverlaySelectors).hide();
		}
	}
});
