$(document).ready(function() {
				
	
	/*---- The Grid ----*/

	if (($('.event').length || $('.story').length) && $('.view-content').length) {
		
		 $('.view-content').masonry({
		
			singleMode: false,
			columnWidth: 240,
			itemSelector: '.views-row',
			animate: true
		
		 });
	
	};
	
	
	/*---- Event Teasers ----*/
	
	if ( $('.event').length ) {
		
		// Set the height of each small teaser event
		$('.event').each(function() {
			
			$(this).height($('.event-teaser-small', this).height() + 15);
		
		});
		$('.event.promo').each(function() {
			
			$(this).height($('.promo-link', this).height() + 40);
		
		});
		
		// Define variables
		var originalSize = 0;
		var clickNo = 0;
		
		// Expand function
		$('.event').click(function() {
						
			// Set the large size
			largeSize = $('.event-teaser-large', this).height();
			
			// Expand the event
			if ( !$(this).hasClass('expanded') ) {
				
				// Reduce existing expanded events
				$('.event.expanded .event-teaser-small').show();
				$('.event.expanded .event-teaser-large').hide();
				$('.event.expanded').height(originalSize).removeClass('expanded');
	
				// Set the original size of the enlarged event
				originalSize = $('.event-teaser-small .event-teaser-details', this).height() + 20;				

				// Reduce other events to titles
				$('.event').each(function() {
			
					$(this).height($('.event-teaser-small .event-teaser-details', this).height() + 20);
		
				});
				$('.event.promo').each(function() {
			
					$(this).height($('.promo-link', this).height() + 40);
		
				});
						
				// Enlarge clicked event
				$(this).addClass('expanded').height(largeSize);
				$('.event-teaser-small', this).hide();
				$('.event-teaser-large', this).show();
				
				// Hide	small teaser images and reshuffle
				$('.event-teaser-small .event-teaser-image').slideUp('fast', function () {
			
					if (clickNo == 0) {														   
			
						$('.view-content').masonry();
			
					}
					clickNo++;
			
				});
				if (clickNo != 0) {														   
			
					$('.view-content').masonry();
			
				}				
				return false;
			
			}
			$('.view-content').masonry();
		
		});
	
	}
	
			
	/*---- Event Filter ----*/
	
	if ( !($.browser.msie) ) {
		if ( $('.event').length ) {
			$("#header").append('<div id="filter"><div class="drop"><p>Event Filter</p><ul><li class="All" style="width: 197px;"><a href="javascript:void(0);" class="All">All</a></li><li class="Cabaret"><a href="javascript:void(0);" class="Cabaret">Cabaret</a></li><li class="Circus"><a href="javascript:void(0);" class="Circus">Circus</a></li><li class="Comedy"><a href="javascript:void(0);" class="Comedy">Comedy</a></li><li class="Dance"><a href="javascript:void(0);" class="Dance">Dance</a></li><li class="Educational"><a href="javascript:void(0);" class="Educational">Educational</a></li><li class="Family"><a href="javascript:void(0);" class="Family">Family</a></li><li class="Festival"><a href="javascript:void(0);" class="Festival">Festival</a></li><li class="Film"><a href="javascript:void(0);" class="Film">Film</a></li><li class="Ideas"><a href="javascript:void(0);" class="Ideas">Ideas</a></li><li class="Kids"><a href="javascript:void(0);" class="Kids">Kids</a></li><li class="Music"><a href="javascript:void(0);" class="Music">Music</a></li><li class="Theatre"><a href="javascript:void(0);" class="Theatre">Theatre</a></li><li class="Visual"><a href="javascript:void(0);" class="Visual">Visual</a></li><li class="Workshops"><a href="javascript:void(0);" class="Workshops">Workshops</a></li></ul></div></div>');
		}
	
		$("#filter li").click(function() {
			if ($(this).hasClass('All')) {
				$("#no-events").hide();
				if ( $(".event").length ) { $(".event").show(); } else { $("#no-events").show(); }
			} else if ($(this).hasClass('Cabaret')) {
				$("#no-events").hide();
				$(".event:not(.Cabaret):parent").hide();
				if ( $(".event.Cabaret").length ) { $(".event.Cabaret:parent").show(); } else { $("#no-events").show(); }
			} else if ($(this).hasClass('Circus')) {
				$("#no-events").hide();
				$(".event:not(.Circus):parent").hide();
				if ( $(".event.Circus").length ) { $(".event.Circus:parent").show(); } else { $("#no-events").show(); }
			} else if ($(this).hasClass('Comedy')) {
				$("#no-events").hide();
				$(".event:not(.Comedy):parent").hide();
				if ( $(".event.Comedy").length ) { $(".event.Comedy:parent").show(); } else { $("#no-events").show(); }
			} else if ($(this).hasClass('Dance')) {
				$("#no-events").hide();
				$(".event:not(.Dance):parent").hide();
				if ( $(".event.Dance").length ) { $(".event.Dance:parent").show(); } else { $("#no-events").show(); }
			} else if ($(this).hasClass('Educational')) {
				$("#no-events").hide();
				$(".event:not(.Educational):parent").hide();
				if ( $(".event.Educational").length ) { $(".event.Educational:parent").show(); } else { $("#no-events").show(); }
			} else if ($(this).hasClass('Family')) {
				$("#no-events").hide();
				$(".event:not(.Family):parent").hide();
				if ( $(".event.Family").length ) { $(".event.Family:parent").show(); } else { $("#no-events").show(); }
			} else if ($(this).hasClass('Festival')) {
				$("#no-events").hide();
				$(".event:not(.Festival):parent").hide();
				if ( $(".event.Festival").length ) { $(".event.Festival:parent").show(); } else { $("#no-events").show(); }
			} else if ($(this).hasClass('Film')) {
				$("#no-events").hide();
				$(".event:not(.Film):parent").hide();
				if ( $(".event.Film").length ) { $(".event.Film:parent").show(); } else { $("#no-events").show(); }
			} else if ($(this).hasClass('Ideas')) {
				$("#no-events").hide();
				$(".event:not(.Ideas):parent").hide();
				if ( $(".event.Ideas").length ) { $(".event.Ideas:parent").show(); } else { $("#no-events").show(); }
			} else if ($(this).hasClass('Kids')) {
				$("#no-events").hide();
				$(".event:not(.Kids):parent").hide();
				if ( $(".event.Kids").length ) { $(".event.Kids:parent").show(); } else { $("#no-events").show(); }
			} else if ($(this).hasClass('Music')) {
				$("#no-events").hide();
				$(".event:not(.Music):parent").hide();
				if ( $(".event.Music").length ) { $(".event.Music:parent").show(); } else { $("#no-events").show(); }
			} else if ($(this).hasClass('Theatre')) {
				$("#no-events").hide();
				$(".event:not(.Theatre):parent").hide();
				if ( $(".event.Theatre").length ) { $(".event.Theatre:parent").show(); } else { $("#no-events").show(); }
			} else if ($(this).hasClass('Visual')) {
				$("#no-events").hide();
				$(".event:not(.Visual):parent").hide();
				if ( $(".event.Visual").length ) { $(".event.Visual:parent").show(); } else { $("#no-events").show(); }
			} else if ($(this).hasClass('Workshops')) {
				$("#no-events").hide();
				$(".event:not(.Workshops):parent").hide();
				if ( $(".event.Workshops").length ) { $(".event.Workshops:parent").show(); } else { $("#no-events").show(); }
			}
			$('.view-content').masonry();
		});
	}
	
	/*---- Font Size ----*/
	
	// Reset
	var originalFontSize = $('#body').css('font-size');
		$(".resetFont").click(function(){
		$('#body').css('font-size', originalFontSize);
	});
		
	// Increase Font Size
	$(".increase").click(function(){
		var currentFontSize = $('#body').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		var newFontSize = currentFontSizeNum*1.2;
		$('#body').css('font-size', newFontSize);
		return false;
	});
	
	// Decrease Font Size
	$(".decrease").click(function(){
		var currentFontSize = $('#body').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		var newFontSize = currentFontSizeNum*0.8;
		$('#body').css('font-size', newFontSize);
		return false;
	});		
								
});
