$(document).ready(function () {
		
	/*
	var index = 0, hash = window.location.hash;
	if (hash) {
		index = /\d+/.exec(hash)[0];
		index = (parseInt(index) || 1) - 1; // slides are zero-based
	}
	*/
	
	$('ul#work.prevnext').cycle({ 
		//startingSlide: index,
		nowrap: 0,
		fx: 'fade',
		speed: 400,
		sync:0,
		height: 'auto',
		timeout: 0,
		cleartypeNoBg: true,
		prev: 	'a.prev',
		next: 	'a.next, a.imgnext',
		after:	onAfter,
		pagerAnchorBuilder: function(idx, slide) { 
			return '#index ul li:eq(' + idx + ') a'; 
		}
	 });
	     
	// Keyboard control for Cycle (left and right keys)

	$(window).keydown(function(e){
		if(e.which == 37){ 
			$('.prev').click();
		} else if(e.which == 39){
			$('.next').click();
		}
	});

	/* Index show hide stuff */

	$(".tab_content").hide();
	$("ul#filter li.image:first").addClass("active").show();
	$(".tab_content:first").show();

	$("ul#filter li.image").click(function() {
		$("ul#filter li.image").removeClass("active");
		$(this).addClass("active");
		$(".tab_content").hide();
		var activeTab = $(this).find("a").attr("href");
		$(activeTab).fadeIn(1);
		return false;
	});

	$('#index li a').click(function() {
		$('#index').hide();
		$('ul#filter li.image').removeClass("active");
		$("ul#filter li.image:first").addClass("active").show();
		$('#workarea').show(200);
		return false;

	});

/*
	$('a.indexbutton').click(function(){

		$(this).toggleClass('active');
		$('.introduction').hide();
		$('.index').slideToggle(200);
		
		if ($('ul#work').is(':visible')){
			$('ul#work').hide();
		} else {
			$('ul#work').show();
		}
	
		return false;
	});
	
  	
   	$('a.infobutton').click(function(){

		$(this).toggleClass('active');
		$('.index').hide();
		$('.introduction').slideToggle(200);



		return false;
	});
*/
	
	$('span a.close').click(function() {
		$(this).parent().parent().hide();
		$('ul#work').show(200);		
	
	});
	
	$('.interesting').hide();
	
	/* Show related projects of sort, thanks to the NYTimes */
	
	function centerBottom(selector) {
	    var newTop =   $(window).height() - $(selector).height();
	    $(selector).css({
	        'position': 'absolute',
	        'right': 0,
	        'top': newTop
	    });
	}

    // call it onload
    centerBottom(".interesting");

    // assure that it gets called when the page resizes
	/*
	    $(window).resize(function(){
	        centerBottom('.interesting');
	    });
	*/

	$('.interesting .close').bind('click',function(){
		$(this).parent().parent().remove();
	}); 
	
	// Display the box after 1 minute
	
	window.setTimeout(function() {
		 $('.interesting').fadeIn(400);
	}, 60000);   


	$(function(){
		positionFooter(); 
		function positionFooter(){
			$(".interesting").css({position: "absolute",top:($(window).scrollTop()+$(window).height()-$(".interesting").height())+"px"})	
		}
 
	$(window).scroll(positionFooter).resize(positionFooter)});

	$('.interesting li > a').visited(function() {
			// hides the li element
		$(this).parent().remove();
	});

	// List blog posts/projects on individual blog posts	

	$(".tab_content").hide();
	$("ul#tabs li:first").addClass("active").show();
	$(".tab_content:first").show();

	$("ul#tabs li").click(function() {
		$("ul#tabs li").removeClass("active");
		$(this).addClass("active");
		$(".tab_content").hide();
		var activeTab = $(this).find("a").attr("href");
		$(activeTab).fadeIn(1);
		return false;
	});
	
	
});

// Counters

function onAfter(curr,next,opts) {
	var caption = (opts.currSlide + 1) + ' of ' + opts.slideCount;
	$('#caption').html(caption);
	window.location.hash = opts.currSlide + 1;
}
