jQuery(function( $ ){

	$('.link').click(function() {
		// pull the section out of the url and strip off the hash sign (href="#intro")
		var section = jQuery(this).attr("href").replace(/#/g,'');
		$("nav a").removeClass("n_active");
		$("nav a[href$=#" + section + "]").addClass("n_active")
	});


	$('#photos_slider').nivoSlider({
		animSpeed: 300, //Slide transition speed
		pauseTime: 3000,
		effect: "fade",
		directionNav:true
	});
	
	$.localScroll();
	
	$('body').scrollTo($('#s_updates'), 500);
	
	// Closes the footer
	
	$('.close_footer').click(
		function(){
			footerClose()
		}
	);
	
	// Catches all clicks to the "participate" class and opens the footer each time
	
	$('.open_footer, .participate').click(
		function(){
			
			if ($('#footer').hasClass('closed')) {
				footerOpen();
			}
			else {
				footerClose();
			}
		}
	);
	
	

	
	// Function to OPEN the footer
	function footerOpen() {
		$('.footer_container').css("top", "-590px");
		$('#footer').removeClass('closed')
		$('.footer_content').css("background", "#ffffff");
		$('.footer_top').css("background", "#eee");
		$('.footer_open').css("top", "-40px");
		$('.footer_close').css("top", "0");
		window.location.hash="#participate";
	};	
	
	// function to CLOSE the footer
	function footerClose() {
		$('#footer').addClass('closed')
		$('nav a.participate').removeClass("p_active");
		$('.footer_container').animate({
			"top": "-40px"
		}, 400, function(){	$('.footer_content').css("background", "#fff")});
		$('.footer_top').css("background", "fff");
		$('.footer_open').animate({
			"top": "0"
		}, 200)
		$('.footer_close').animate({
			"top": "-40px"
		}, 200)
	};
	
	
	$('.play_video').click(function(){
	});
	
	// select #slider_kit and make it scrollable. use circular and navigator plugins
		$("#slider_features").scrollable({ circular: true }).navigator({
			// select #flowtabs to be used as navigator
			navi: "#slider_features_tabs",
			// select A tags inside the navigator to work as items (not direct children)
			naviItem: 'a',
			// assign "current" class name for the active A tag inside navigator
			activeClass: 'active',
			// make browser's back button work
			history: false,
			items: '.slider'
		});
		
		
		$("#slider_video").scrollable({ circular: true }).navigator({
			// select #flowtabs to be used as navigator
			navi: "#slider_video_tabs",
			// select A tags inside the navigator to work as items (not direct children)
			naviItem: 'a',
			// assign "current" class name for the active A tag inside navigator
			activeClass: 'active',
			// make browser's back button work
			history: false,
			items: '.slider'
		});
		
		var slider_video = $("#slider_video").data("scrollable");
		$(".polaroids").click(function() {
			slider_video.seekTo($("#tab_photos"));
			$('#container').scrollTo($('#s_video'), 500, { offset: {left: -$offset_width, top:-$offset_height} });
			$('#s_video').addClass("s_active");
			$("nav a[href$=#video]").addClass("n_active");
		});
		
		$(".play_video").click(function() {
			slider_video.seekTo($("#tab_video"));
			$('#container').scrollTo($('#s_video'), 500, { offset: {left: -$offset_width, top:-$offset_height} });
			$('#s_video').addClass("s_active");
			$("nav a[href$=#video]").addClass("n_active");
		});
		
		
		$("#slider_rules").scrollable({ circular: true }).navigator({
			// select #flowtabs to be used as navigator
			navi: "#slider_rules_tabs",
			// select A tags inside the navigator to work as items (not direct children)
			naviItem: 'a',
			// assign "current" class name for the active A tag inside navigator
			activeClass: 'active',
			// make browser's back button work
			history: false,
			items: '.slider'
		});
			
	
		$('#twitter_feed').twitterSearch({ 
		    term:  'arthousecoop', 
		    title: '', 
		    titleLink: 'http://www.arthousecoop.com/projects/amlp', 
		    birdLink:  'http://twitter.com/jquery', 
		    css: {  
		      img: {  width: '30px', height: '30px' }  
		      
		    } 
		});
		
		jQuery('#participate_form').submit(function() {
			var tshirtbox = jQuery('#choose_shirt').val();
			if (jQuery('#tshirt').attr('checked') && tshirtbox == "") {
		  	alert('Please choose a t-shirt size.');
			  return false;
			}
		});
		
		if (jQuery('#tshirt').attr('checked')) {
			jQuery('#choose_shirt').attr('disabled', '');
		} else {
			jQuery('#choose_shirt').attr('disabled', 'disabled');
		}
		
		jQuery('#tshirt').bind('click', function () {
			if (jQuery(this).attr('checked')) {
		      jQuery('#choose_shirt').attr('disabled', '');
		    } else {
		      jQuery('#choose_shirt').attr('disabled', 'disabled');
		    }
		});
		
});



