$(function(){
	if(jQuery().cycle) {
		$('#features').cycle({
			fx: 'fade',
			timeout: 8000,
			random: 1,
			delay:  -2000,
			cleartype: 1, 
			next:   '#next', 
			prev:   '#previous',
			cleartypeNoBg: true
		});
		
		$('#features').hoverIntent({    
			sensitivity: 50,      
			over: function(){
					$("div#controls").fadeIn("fast");
				},    
			timeout: 500,     
			out: function(){
					$("div#controls").fadeOut("fast");
				}    
		});
	};
	
	$("#programs").jCarouselLite({
		btnNext: "#programs-next",
		btnPrev: "#programs-previous",
		scroll: 4,
		speed: 800,
		visible: 4
	});

	$("#issues").jCarouselLite({
		btnNext: "#issues-next",
		btnPrev: "#issues-previous",
		scroll: 4,
		speed: 800,
		visible: 5
	});
	
	$("#projects-submit").hide();
	
	$("#projects-view").change(function(){
		window.location.href = $("#projects-view").val()
	});

	//Site navigation
	$("ul#sitenav li a.sub").click(function(){ 
		var $nextDiv = $(this).next("ul");
		var $visibleSiblings = $("ul#sitenav li ul:visible");
		
		if ($visibleSiblings.length ) {
			$visibleSiblings.slideUp("fast", function() {
				$nextDiv.not(this).slideToggle("fast");
			});
		} else {
			$nextDiv.slideToggle("fast");
		}
		
		return false;
	});
	
	$("*").not("ul#sitenav li a.sub").click(function(){ 
		$("ul#sitenav li ul:visible").slideUp("fast");
	});
	
	$("ul#sitenav li ul").hoverIntent({    
		sensitivity: 50,      
		over: function(){},    
		timeout: 500,     
		out: function(){
				$(this).slideUp("fast");
			}    
	});

	//Expanding side bar navigation
	$("div.navexpand ul li.accordion ul").not("div.navexpand ul li.accordion ul.open").hide();
	$("div.navexpand ul li a.expand").click(function(){
		$(this).next("ul").slideToggle("slow").parent("li").siblings("li").children("ul:visible").slideUp("slow");
		return false;
	});
	
	//Expanding List
	$("dl.expand dd").not("dd.start").not("dl dl dd").hide();
	$("dl.expand dt").not("dl dl dt").click(function(){
		$(this).next("dd").slideToggle("slow")
		.siblings("dd:visible").slideUp("slow");
		$(this).toggleClass("active");
		$(this).siblings("dt").removeClass("active");
	});

	//External links to open in new window
	$("a.external, a[href $='.pdf']").attr({target: "_blank"});

	//Colorbox
	$("a[rel='gallery']").colorbox({ maxHeight: "90%", opacity: 0.80 });
	$("a[rel='gallery-w']").colorbox({ maxHeight: "90%", maxWidth: "80%", opacity: 0.80 });
	$(".colorbox").colorbox({ maxHeight: "80%", maxWidth: "90%", opacity: 0.80 });
	$(".colorboxframe").colorbox({ iframe: true, width: "750px", height: "80%", opacity: 0.80 });
	$(".colorboxframeshort").colorbox({ iframe: true, width: "750px", height: "60%", opacity: 0.80 });
	$(".issuu").colorbox({ iframe: true, width: "950px", height: "650px", opacity: 0.80 });
	$(".specialist").colorbox({ iframe: true, width: "800px", height: "60%", opacity: 0.80 });
	$(".coordinator").colorbox({ iframe: true, width: "500px", height: "50%", opacity: 0.80 });
	$(".aside-box").colorbox({ inline:true, href:"#aside-box", width: "650px", height: "60%", opacity: 0.80 });
	$(".aside-box-2").colorbox({ inline:true, href:"#aside-box-2", width: "650px", height: "60%", opacity: 0.80 });
	$("a[rel='flickr']").colorbox({ 
		title: function() {
			var url = $(this).attr('href');
			var photoID = url.split("/")[4].split("_")[0];
			
			return '<a href="http://flickr.com/photo.gne?id='+ photoID +'" target="_blank" class="flickr">View this photo on Flickr</a>';
		},
		maxHeight: "90%", 
		maxWidth: "90%", 
		opacity: 0.80 });
	
	//Arroyo Colorado
	$("#site13072").hide();
	$("a.show13072").click(function(){
		$("#site13072").show();
	});

	//News Articles Categories
	$("div.showall").show();
	$("li.older").hide();
	
	$("div.showall").click(function(){
		$("li.older").slideToggle();
	});

});