$(document).ready(function(){

	// Navigation 
	
	$('#nav ul li').hover(
		function () {
			$(this).children('ul').show();
		}, 
		function () {
			$(this).children('ul').hide();
		}
	);
	
	$('#nav ul li ul li').hover(
		function () {
			$(this).children('ul').show();
		},
		function () {
			$(this).children('ul').hide();
		}
	);
	
	// Show Tabs
	
	$("li#overview").click(function() {
      	$("#show-summary").show();
      	$("#show-summary").siblings().hide();
      	$("li#overview").addClass('show-tab-active');
      	$("li#overview").siblings().removeClass('show-tab-active');
      	$(this).children('img').show();
      	$(this).siblings().children('img.arrow').hide();
     });
	
	$("li#date-time").click(function() {
      	$("#show-dates").show();
      	$("#show-dates").siblings().hide();
      	$("li#date-time").addClass('show-tab-active');
      	$("li#date-time").siblings().removeClass('show-tab-active');
      	$(this).children('img').show();
      	$(this).siblings().children('img.arrow').hide();
     });
	
	$("li#gallery").click(function() {
      	$("#show-gallery").show();
      	$("#show-gallery").siblings().hide();
      	$("li#gallery").addClass('show-tab-active');
      	$("li#gallery").siblings().removeClass('show-tab-active');
      	$(this).children('img').show();
      	$(this).siblings().children('img.arrow').hide();
     });
	
	$("li#video").click(function() {
      	$("#show-videos").show();
      	$("#show-videos").siblings().hide();
      	$("li#video").addClass('show-tab-active');
      	$("li#video").siblings().removeClass('show-tab-active');
      	$(this).children('img').show();
      	$(this).siblings().children('img.arrow').hide();
     });
	
	$("li#cast").click(function() {
      	$("#show-cast").show();
      	$("#show-cast").siblings().hide();
      	$("li#cast").addClass('show-tab-active');
      	$("li#cast").siblings().removeClass('show-tab-active');
      	$(this).children('img').show();
      	$(this).siblings().children('img.arrow').hide();
     });
     
     // Cast Squares
     
     $("#show-cast span.actor-name").click(function() {
     	$(this).siblings('span.actor-overview').fadeIn();
     	$(this).parent().siblings().children('span.actor-overview').fadeOut();
     });     
     
     $('#show-cast span.actor-name-overview a img').click(function(){
     	$('#show-cast span.actor-overview').fadeOut();
     });
     
     // Class Descriptions
     
     $('.summary-container img.i').click(function() {
     	$(this).next().fadeIn();
     	$(this).parent().parent().siblings().children().children('.class-description').fadeOut();
     	$(this).parent().parent().parent().siblings().children().children().children('.class-description').fadeOut();
     });
     
     $('.class-description img').click(function() {
     	$('.class-description').fadeOut();
     });
     
     // Share Your Experience
     
     $('#content-bottom .bravo a#share').click(function() {
     	$('#share-form').fadeIn();
     });
     
      $('#content-bottom .bravo #share-form a#close').click(function() {
     	$('#share-form').fadeOut();
     });
     
     //Tweets
     
     $(function(){
      $("#tweet").tweet({
        avatar_size: 32,
        count: 1,
        username: "nctheatre",
        template: "{text}"
      });
    });

	
	
});

/**
 * Set all passed elements to the same height as the highest element.
 * 
 * Copyright (c) 2010 Ewen Elder
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 * @author: Ewen Elder <glomainn at yahoo dot co dot uk> <ewen at jainaewen dot com>
 * @version: 1.0
 * 
 * @todo: Recaluclate height if extra content is loaded into one of the elements after it has been resized
 *        possibly detect if the highest column has a fixed CSS height to being with or is set to 'auto'; if set to auto
 *        then leave as auto so that it well expend or contract naturally as it would normally.
**/ 

(function ($)
{
	$.fn.equalHeightColumns = function (options)
	{
		var height, elements;
		
		options = $.extend({}, $.equalHeightColumns.defaults, options);
		height = options.height;
		elements = $(this);
		
		$(this).each
		(
			function ()
			{
				// Apply equal height to the children of this element??
				if (options.children)
				{
					elements = $(this).children(options.children);
				}
				
				// If options.height is 0, then find which element is the highest.
				if (!options.height)
				{
					// If applying to this elements children, then loop each child element and find which is the highest.
					if (options.children)
					{
						elements.each
						(
							function ()
							{
								// If this element's height is more than is store in 'height' then update 'height'.
								if ($(this).height() > height)
								{
									height = $(this).height();
								}
							}
						);
					}
					
					else
					{
						// If this element's height is more than is store in 'height' then update 'height'.
						if ($(this).height() > height)
						{
							height = $(this).height();
						}
					}
				}
			}
		);
		
		
		// Enforce min height.
		if (options.minHeight && height < options.minHeight)
		{
			height = options.minHeight;
		}
		
		
		// Enforce max height.
		if (options.maxHeight && height > options.maxHeight)
		{
			height = options.maxHeight;
		}
		
		
		// Animate the column's height change.
		elements.animate
		(
			{
				height : height
			},
			options.speed
		);
		
		return $(this);
	};
	
	
	$.equalHeightColumns = {
		version : 1.0,
		defaults : {
			children : false,
			height : 0,
			minHeight : 0,
			maxHeight : 0,
			speed : 0
		}
	};
})(jQuery);

