$(document).ready(function(){

	// home page slideshow
	$("#slideshow").cycle();
	
	// nav hover
	$("#nav a").removeClass("nojs").fadeTo("300",".7");
	$("#nav a").hover(
	function () {
		$(this).stop().fadeTo("300","1").animate( { backgroundColor:"#f9f0e1", color: "#c00"}, 300 );
	},
	function () {
		$(this).stop().fadeTo("300",".7");
		$(this).animate( { backgroundColor:"#fdfded", color: "#800"}, 300 );
	});
	
	// footer links hover
	$("#footer-links a").removeClass("nojs");	
	$("#footer-links a").hover(
	function () {
		$(this).stop().animate( { backgroundColor:"#333", color: "#fff"}, 300 );
	},
	function () {
		$(this).stop().animate( { backgroundColor:"#222", color: "#bbb"}, 300 );
	});
	
	// current menu
	var href = (window.location.pathname).split("/");
	$("#nav a").each(function(){
		var thisHref = $(this).attr("href").split("/");
		if (href[1]==thisHref[1]) { 
			$(this).parent().attr('class','current');
		} else if (href[1]=="") {
			$("#nav li:first").attr('class','current');
		}
	});
	$("#home #nav .current a").click(function(){
		$("#top").click(function() {
			$("html:not(:animated),body:not(:animated)").animate({ scrollTop: 500}, 1100 );
			return false;
		});
	});
	
	// fade / load
	$(".the-content li:first").show();
	$(".page-nav li:first").addClass('current');
	$(".page-nav a").click(function(){
		var toLoad = $(this).attr("href");
		$(".page-nav li").attr('class','');
		$(this).parent().attr('class','current');
		$(".the-content").fadeOut(300, function(){
			$(".the-content li").hide();
			$(toLoad).show();
		}).fadeIn(300);
		return false;
	});
	
	// next / previous links
	jQuery.easing.def = "easeInOutQuint";
//	$(".next").click(function(){
//			$("#slider").animate({"marginTop": "-=296px"}, "slow");
//			return false;
//	});
//	$(".previous").click(function(){
//			$("#slider").animate({"marginTop": "+=296px"}, "slow");
//			return false;
//	});
	
	// display embed video correctly
	$('.embed-me').each(function() {
		var link = $(this).attr('href').split('/');
		var playerWidth = '542';
		var color = "ffff33";
		var playerHeight = '390';	
		// youtube
		if ( (link[2]=='www.youtube.com')||(link[2]=='youtube.com') ) {
			var video = link[3].split('=')[1].split('&')[0];
			$(this).replaceWith("<object width='"+playerWidth+"' height='"+playerHeight+"'><param name='movie' value='http://www.youtube.com/v/"+video+"&hl=en&fs=1'></param><param name='allowFullScreen' value='true'></param><param name='allowscriptaccess' value='always'></param><embed src='http://www.youtube.com/v/"+video+"&hl=en&fs=1' type='application/x-shockwave-flash' allowscriptaccess='always' allowfullscreen='true' width='"+playerWidth+"' height='"+playerHeight+"'></embed></object>");
		}
	});
	
	// photo gallery
	$.getJSON("http://api.flickr.com/services/feeds/groups_pool.gne?id=1142222@N22&lang=en-us&per_page=100&api_key=484b06f2930e319c955d09ec346adc30&format=json&jsoncallback=?",function(data){
	    $.each(data.items, function(i,item){
		var parsed_title = item.title.split(' ').join('_');
		$("<div id='"+parsed_title+"' />")
		    .append("<img src='"+item.media.m.replace('_m.jpg','.jpg')+"'/>")
		    .append("<div class='title'>"+item.title+"</div>")
		    .append("<div class='description'>"+item.description+"</div>")
		    .append("<div class='author'>uploaded by <strong>"+item.author.split('(')[1].split(')')[0]+"</strong></div>")
		    .append("<div class='link'>"+item.link+"</div>")
		    .appendTo("#flickrload");
		var img = new Image();
		$(img)
		    .load(function(){
			var inlineHeight = $(this).height();
			var inlineWidth = $(this).width();
			$(this).attr('height',inlineHeight).attr('width',inlineWidth);
		    }).appendTo("#slider ul")
		    .wrap("<li><a href='#"+parsed_title+"'></a></li>")
		    .attr("src", item.media.m);
	    });
	    $(".jcarousel").jCarouselLite({
		btnNext: "#the-photos a.next",
		btnPrev: "#the-photos a.previous",
		vertical: true
	    });
	    $("#photos-nav a").click(function(){
		var toLoad = $(this).attr('href').split('#')[1];
		var thePic = $("#"+toLoad+" img:first").clone();
		$("#the-pic").html(thePic);
		$("#title").html($("#"+toLoad+" .description p:last").html());
		$("#uploaded").html($("#"+toLoad+" .author").html());
		$("#comment-link").attr('href',($("#"+toLoad+" .link").html()));
		return false;
	    });
	    $("#photos-nav a:first").each(function(){
		var toLoad = $(this).attr('href').split('#')[1];
		var thePic = $("#"+toLoad+" img:first").clone();
		$("#the-pic").html(thePic);
		$("#title").html($("#"+toLoad+" .description p:last").html());
		$("#uploaded").html($("#"+toLoad+" .author").html());
		$("#comment-link").attr('href',($("#"+toLoad+" .link").html()));
		return false;
	    });
	});


    
});

