$(function() {

	$('.no-js').removeClass('no-js');
	
	jQuery.easing.def = "easeOutCubic";
	
	$('.tweets ul').after('<ul class="pager">').cycle({
		activePagerClass: 'active',
		fx: 'fade',
		speed: 1000,
		timeout: 10000,
		sync: 0,
		pager: '.pager',
		pagerAnchorBuilder: function(i, slide) { 
	        return '<li><a>' + (i+1) + '</a></li>'; 
	    },
	    pause: 1
	});
	$('.artist').setAllToMaxHeight();
	$('.track').setAllToMaxHeight();
	
	$('.navigation a').click(function(e){
		e.preventDefault();
		$('.navigation .current').removeClass('current');
		$(this).parent().addClass('current');
	})
	
	/*
	$('html').keydown(function(e) {
		if(e.keyCode == '40'){
			e.preventDefault();
			if($('.navigation .current').next().length){
				$('.navigation .current').next().find('a').trigger('click');
			}
		} else if(e.keyCode == '38'){
			e.preventDefault();
			$('.navigation .current').prev().find('a').trigger('click');
		}
	});
	*/
	
	$.localScroll({
		duration: 500,
		hash:false,
		queue:true
	});


	$('.work').each(function(i){
		
		$(this).find('ul').after('<a class="prev">Previous</a><a class="next show">Next</a>');
		$(this).find('ul').after('<div class="crop" />');
		var crop = $(this).find('.crop');
		var images = new Array();
		var n = 0;
		var next = $(this).find('.next');
		var prev = $(this).find('.prev');
		$(this).find('ul li').each(function(i){
			images.push($(this).find('img').attr('src'));
		});
		
		crop.css('background-image', 'url(' + images[n] + ')');
				
		prev.click(function(e){
			n--;
			crop.css('background-image', 'url(' + images[n] + ')');
			next.addClass('show');
			if(!images[n-1]){
				$(this).removeClass('show');
			}
		})
		
		next.click(function(e){
			n++;
			crop.css('background-image', 'url(' + images[n] + ')');
			prev.addClass('show');
			if(!images[n+1]){
				$(this).removeClass('show');
			}
			
		})
		
		$(this).find('.container').removeClass('loading');
		
	})

});

$.fn.setAllToMaxHeight = function(){
	return this.height( Math.max.apply(this, $.map( this , function(e){ return $(e).height() }) ) );
}
