/**** Add application wide javascripts below this point  ******/
$(document).ready(function(){
	
	var animating = 0;
	var showing_move = 235;
	var showing_pods = 3;
	var showing_max_pos = 0 - (($('#showing ul li').size() * showing_move) - (showing_move * (showing_pods)));
	
	/* adjust widths betweent the range 150, 230 */
	jQuery.each($('#nav-primary li'), function(){
		$(this).animate({'width':Math.floor(((230 - 150) + 1) * Math.random()) + 150},1500);
	});
	
	$('.calendar-cell a').click(function() {
		var current = $(this);
		$("#showings-container").load("/showings/" + current.text());
		$(".pod h2 span#showing-date").load("/date_format/" + current.text(), status, function() {
			if (status !== "error") {
				$('.calendar-cell').each(function(i) {
					$(this).removeClass('selected');
				});
				
				current.parent().addClass('selected');
			}
			
			showing_max_pos = 0 - (($('#showing ul li').size() * showing_move) - (showing_move * (showing_pods)));
			animating = 0;
		});
		
		return false;
	});
	
	$('#showing .next').click(function(){
		
		if ($('#showing ul li').size() <= showing_pods)
			return false;
			
		if (Math.ceil($('#showing ul').position().left) <= showing_max_pos)
			return false;
			
		if (animating == 1)
			return false;
			
		animating = 1;
		
		$('#showing ul').animate({
			'left':$('#showing ul').position().left - showing_move
		}, 500, function() {
			animating = 0;
		});
	});
	
	$('#showing .prev').click(function(){
		
		if ($('#showing ul').position().left >= 0)
			return false;
			
		if (animating == 1)
			return false;
			
		animating = 1;
			
		$('#showing ul').animate({
			'left':$('#showing ul').position().left + showing_move
		}, 500, function() {
			animating = 0;
		});
	});
	
	$('#gallery-items a').click(function(){
		$('#gallery-hero').attr('src',$(this).attr('href'));
		return false;
	});
	
	$(".colorbox").colorbox();
	$(".iframe").colorbox({width:"875px", height:"485px", iframe:true});
	$(document).pngFix();
});
