function initExt() {
	//there are 34 thumbnails
	var thumbLoading = false;
	$('#thumbnail-container div.single-asset img.thumbnail').bind("click", function() {
		if (thumbLoading) return;
		
		if (visibleFlyoutId != null) {
			$(visibleFlyoutId).fadeOut('fast');
			visibleFlyoutId = null;
		}
		
		thumbLoading = true;
		
		//pausing the previous video player, if the case
		if ($("video").get(0) != undefined) {
			$("video").get(0).pause();	
		}
		
		var thumbnail = $(this);
		$(thumbnail).parent().siblings("div.thumb-loading").css("display", "block");
		
		$.ajax({
			url:  '/mixer/show_media/' + $(this).attr("id"),
			success: function(data) {
				$("div#media-container").html(data);
			},
			error: function(jqXHR, textStatus, errorThrown) { 
				alert("ajax call error [" + errorThrown + "]");
			},
			complete: function() {
				$("div#media-container div#see-more span").bind("click", function() {
					if ($("div#description").css("display") == "none") {
						$("div#description").fadeIn("fast");
						$(this).text("Hide description");
					} else {
						$("div#description").fadeOut("fast");
						$(this).text("Show description");
					}
				});	
				
				$(thumbnail).parent().siblings("div.thumb-loading").css("display", "none");
				thumbLoading = false;
			}
		});
	});
	
	//this is for the case when assets are grouped
	$('#thumbnail-container ul.asset-group-container li').not('li.owner-name').bind("click", function() {
		if (thumbLoading) return;
		
		$(this).parent().fadeOut("fast");
		thumbLoading = true;
		
		//pausing the previous video player, if the case
		if ($("video").get(0) != undefined) {
			$("video").get(0).pause();	
		}
		
		var thumbnail = $(this).parent().siblings("div.group-asset").first().children("img.thumbnail").first();
		$(thumbnail).parent().siblings("div.thumb-loading").css("display", "block");
		
		$.ajax({
			url:  '/mixer/show_media/' + $(this).attr("id"),
			success: function(data) {
				$("div#media-container").html(data);
			},
			error: function(jqXHR, textStatus, errorThrown) { 
				alert("ajax call error [" + errorThrown + "]");
			},
			complete: function() {
				$("div#media-container div#see-more span").bind("click", function() {
					if ($("div#description").css("display") == "none") {
						$("div#description").fadeIn("fast");
						$(this).text("Hide description");
						if (visiblePaneName != null) {
							$("div#" + visiblePaneName).fadeOut("fast");	
						}
					} else {
						$("div#description").fadeOut("fast");
						$(this).text("Show description");
					}
				});	
				
				$(thumbnail).parent().siblings("div.thumb-loading").css("display", "none");
				thumbLoading = false;
			}
		});
	});

	var visibleFlyoutId = null;
	$('#thumbnail-container div.group-asset img.thumbnail').bind("click", function() {
		var flyoutId = "#asset-list-"+$(this).attr("id");
		if ($(flyoutId).css("display") == "none") {
			if (visibleFlyoutId != null) {
				$(visibleFlyoutId).fadeOut('fast');
			}
			
			$(flyoutId).fadeIn('fast');			
			visibleFlyoutId = flyoutId;
		} else {
			$(flyoutId).fadeOut('fast');
		}
	});
	
	$('#thumbnail-container ul.asset-group-container').mouseout(function() {
		setTimeout(function(){hideGroupContainer(this);}, 3000);
	});
	
	//loading the first thumbnail (or the first thumbnail in the first group)
	if ($('#thumbnail-container table div').first().attr('class') == 'single-asset') {
		$('#thumbnail-container div.single-asset img.thumbnail').first().click();
	} else {
		$('#thumbnail-container ul.asset-group-container li').not('li.owner-name').eq(0).click();
	}
	
	$("a#menu-create-mix").bind("click", function() {
		$("div#mix-container").fadeIn("fast");
	});
}

function hideGroupContainer(hContainer) {
//	$(hContainer.parent).fadeIn(1000, function() {
		$(hContainer).fadeOut('fast');
//	});
}

var visibleContainer;
function displayContainer(name) {
	if (name == 'map' && visibleContainer != "map-container") {
		$("#" + visibleContainer).fadeOut("fast", function() {
			$("div#narrative-previews iframe").attr("src", ""); //a way, maybe not the best, to silence the player
			$("#map-container").fadeIn("fast");
			
			visibleContainer = "map-container";
		});
	} else if (name == 'mixer' && visibleContainer != "thumbnail-container") {
		$("#" + visibleContainer).fadeOut("fast", function() {
			$("#thumbnail-container").fadeIn("fast");
			
			visibleContainer = "thumbnail-container";
		});		
	}
}
