/*
  UI handling class
*/
var ui_handler = {
  'handle' : function(type) {
	switch (type) {
	  case 'worktitle':
		this.worktitle();
		break;
	  
	  case 'taxonomy':
		this.taxonomy();
		break;
	  
	  case 'homepage':
		this.homepage();
		break;
	  
	  case 'default_handler':
		this.default_handler();
		break;
	}
  },
  
  /*
    Handler for worktitle page
  */
  'worktitle' : function() {
	if ($("#video-container-credits").is(':visible') && ($("#panel-themes").is(':visible') || $("#panel-collections").is(':visible'))) {
	  // If credits and one panel are both visible then use bg3
	  $("body").css("background-image", "url(" + theme_path + "/img/bg_black_menu_credits.jpg)");
	} else if ($("#panel-themes").is(':visible') || $("#panel-collections").is(':visible')) {
	  // If either panel is visible then use bg4
	  $("body").css("background-image", "url(" + theme_path + "/img/bg_black_menu.jpg)");
	} else if ($("#video-container-credits").is(':visible')) {
	  // Else if credits are open then use bg_black_credits.jpg
	  $("body").css("background-image", "url(" + theme_path + "/img/bg_black_credits.jpg)");
	} else {
	  $("body").css("background-image", "url(" + theme_path + "/img/bg_black.jpg)");
	}
  },
  
  'taxonomy' : function() {
	if (($("#panel-themes").is(':visible') || $("#panel-collections").is(':visible'))) {
	  $("body").css("background-image", "url(" + theme_path + "/img/bg_taxonomy_menu.jpg)");
	} else {
	  $("body").css("background-image", "url(" + theme_path + "/img/bg_taxonomy.jpg)");
	}
  },
  
  'homepage' : function() {
	if (($("#panel-themes").is(':visible') || $("#panel-collections").is(':visible'))) {
	  $("body").css("background-image", "url(" + theme_path + "/img/bg_home_menu_closed.jpg)");
	} else {
	  $("body").css("background-image", "url(" + theme_path + "/img/bg_home_menu_opened.jpg)");
	}
  },
  
  /*
    Default handler
  */
  'default_handler' : function() {
	if (($("#panel-themes").is(':visible') || $("#panel-collections").is(':visible'))) {
	  $("body").css("background-image", "url(" + theme_path + "/img/bg_menu.jpg)");
	} else {
	  $("body").css("background-image", "url(" + theme_path + "/img/bg.jpg)");
	}
  }
};

$(document).ready(function(){
/***** menu buttons ********/
	$("#btn-slide-themes").click(function(){
	  // Close collections panel
	  $("#panel-collections").hide();
	  $("#btn-slide-collections a").removeClass("active");
	  // Slides themes panel
    $("#panel-themes").toggle();
    $("#btn-slide-themes a").toggleClass("active");

    ui_handler.handle(page_type);
      
    return false;		
	});
	
	$("#btn-slide-collections").click(function() {
	  // Close themes panel
	  $("#panel-themes").hide();
    $("#btn-slide-themes a").removeClass("active");
    // Slides collections panel
		$("#panel-collections").toggle();
		$("#btn-slide-collections a").toggleClass("active");
		
		ui_handler.handle(page_type);
		
		return false;
	});

	/***** close buttons ********/
	$(".btn-close-themes").click(function () {
		$("#panel-themes").hide();
		$("#btn-slide-themes a").removeClass("active");
		ui_handler.handle(page_type);
		return false;
	});
	
	$(".btn-close-collections").click(function () {
	  $("#panel-collections").hide();
	  $("#btn-slide-collections a").removeClass("active");
	  ui_handler.handle(page_type);
	  return false;
	});
	
	
	$("#btn-slide-credits").click(function () {
	  if ($("#video-container-credits").is(':hidden')) {
		$("#video-container-credits").show();
	  } else {
		$("#video-container-credits").hide();   
	  }
	  ui_handler.handle(page_type);
	  return false;
	});

	$("#link-toggle-synopsis").click(function(){
	  if ($('#synopsis-full').is(':hidden')) {
		$('#synopsis-full').show();
		this.innerHTML = 'Collapse';
	  } else {
		$('#synopsis-full').hide();
		this.innerHTML = 'Show full synopsis';
	  }
	  
	  return false;
	});
	
	$("#link-show-term-description").click(function(){
	  $('.term-description-full').show();
	  $("#link-hide-term-description").show();
	  $(this).hide();
	  return false;
	});
	
	$("#link-hide-term-description").click(function(){
	  $('.term-description-full').hide();
	  $("#link-show-term-description").show();
	  $(this).hide();
	  return false;
	});
});
