$(function() {

		// On the home page, make the rocket collapsible
	if (!($.browser.msie && $.browser.version <= 6)) {
		if ($("body#home").length) {
			$("#footer").prepend('<div id="rocket-opener">Open!</div>');
			$("#content").data("start-height", $("#content").height());
			$("#content").css({
				height: 0,
				visibility: "hidden"
			});
			$("#open-zag-bottom").css("margin-top", "-110px");
			$("#rocket-opener")
				.one("click", function(e) {
					$("#content")
						.stop(true, true)
						.css("visibility", "visible")
						.animate({
							height: $("#content").data("start-height")
						}, 1500);
					$("#open-zag-bottom")
						.animate({
							marginTop: "-50px"
						}, 500);
					$(this).remove();
				});
			
				// Once everything has loaded, after 10 seconds then open the rocket.
			$(window).bind("load", function(e) {
				setTimeout(function() {
					if ($("#rocket-opener").length) {
						$("#rocket-opener").trigger("click");
					}
				}, 10000);
			});
		}
	}

		// Picture gallery
	$("#content-main .pictures a, #content-main #gallery-list a").attr("rel", "gallery").fancybox({
		titlePosition: 'inside',
		transitionIn: 'elastic',
		transitionOut: 'elastic'
	});
	
		// Video gallery
	$("#content-main #video-list a").each(function() {
		$(this).fancybox({
			titlePosition: 'inside',
			transitionIn: 'elastic',
			transitionOut: 'elastic',
			content: $("#video-holdingarea .video[vid=" + $(this).attr("vid") + "]").html()
		});
	});
	
		// Twitter feed on news
	$("#tweet-list").twitterbox('cs_visyon');
	
		// Masonry the events up
	$(window).bind("load", function(e) {
		$('#event-list').masonry({ singleMode: true });
	});
	
/**
 * Audio elements
**/
	var as = audiojs.createAll({
		css: null
	});
	
/**
 * Video elements
**/
		
		// If H264 is not playable, write in a flash fallback
	if (Modernizr.video.h264) {
		$(".media .video")
			.bind("click", function(e) {
				var $self = $(this);
				$.fancybox({
					autoScale: false,
					scrolling: 'no',
					centerOnScroll: true,
					content: $self.find('.the-video').clone()
				});
				e.preventDefault();
			});
	}
	else {
		$(".media .video")
			.bind("click", function(e) {
				var $self = $(this),
					$srcVideoElement = $self.find('video');
				$.fancybox({
					autoScale: false,
					scrolling: 'no',
					centerOnScroll: true,
					content: function() {
						var $video = $('<div id="flow-player-container"></div>');
						$video
							.width($srcVideoElement.attr("width"))
							.height($srcVideoElement.attr("height"))
							.flowplayer(window.location.protocol + "//" + window.location.host + '/assets/flowplayer/flowplayer-3.2.5.swf', {
								clip: {
									url: $srcVideoElement.attr('src'),
									autoPlay: false
								}
							});
						return $video;
					}
				});
				e.preventDefault();
			});
	}
	
/**
 * Media sidebar
**/

	$(".media .picture a").attr("rel", "gallery").fancybox({
		titlePosition: 'inside'
	});
	
});
