	// Document ready
$(document).ready(function() {
		// Replace the link to youtube, to a direct youtube video
	$(".video-item-piclink a[href*=youtube]").each(function() {
		var link = parseUri($(this).attr("href")) ;
		$(this).attr("href", 'http://www.youtube.com/v/' + link.queryKey.v + '?autoplay=1') ;
	}) ;
	$(".video-item-piclink a[href*=youtube], a.video-item-link[href*=youtube]").colorbox({
		html: '<div id="ytplayer"><p>You need Flash player 8+ and JavaScript enabled to view this video. <a href="http://get.adobe.com/flashplayer/">Click here to be taken to the flash player website</a></p></div>',
		innerWidth: 645,
		innerHeight: 390,
		onOpen: function() {
			pageTracker._trackPageview($(this).attr("loghref"));
		}
	}, function() {
		var params = { allowScriptAccess: "always" };
		var atts = { id: "myytplayer" };
		swfobject.embedSWF($(this).attr("href"), 
			"ytplayer", "640", "385", "8", null, null, params, atts);
	}) ;

	$(".video-item-piclink a[href*=/ajax/get_video_embed_code]").each(function() {
		var $self = $(this);
		$.ajax({
			url: $self.attr("href"),
			type: 'get',
			success: function(data, textStatus, XMLHttpRequest) {
				$self.data('video_embed_code', data);
			}
		});
	}) ;
	$(".video-item-piclink a[href*=/ajax/get_video_embed_code], a.video-item-link[href*=/ajax/get_video_embed_code]").colorbox({
		html: function() {
			return $(this).data('video_embed_code');
		},
		onOpen: function() {
			pageTracker._trackPageview($(this).attr("loghref"));
		}
	});
		//
	$(".thickbox").colorbox();
	
		// Apply masonry where necessary
	$(".content-columns-two").masonry({
		singleMode: true,
		itemSelector: ".content-panel"
	}) ;
	
		// Protected downloads
	if (!$.browser.msie) {
		$(".protected-download").colorbox();
		$("#colorbox").delegate('#frm-download_catcher', 'submit', function() {
			$.ajax({
				url: $("#frm-download_catcher").attr('action'),
				type: 'post',
				data: $("#frm-download_catcher").serialize() + '&doStoreAndDownload=1',
				success: function(data, textStatus, XMLHttpRequest) {
					window.location.href = data;
					$.colorbox.close();
				},
				error: function(XMLHttpRequest, textStatus, errorThrown) {
					$("#cboxLoadedContent div:first").html(XMLHttpRequest.responseText);
					$.colorbox.resize();
				}
			});
			return false;
		});
	}
}) ;
