$(function() {
	
//	if(!$('#portfolio').hasClass('current')) {
//		$('#portfolio').mouseenter(function() {
//			$('#circle').addClass('portfolio');
//		}).mouseleave(function() {
//			$('#circle').removeClass('portfolio');
//		});
//	}
//	
//	if(!$('#downloads').hasClass('current')) {
//		$('#downloads').mouseenter(function() {
//			$('#circle').addClass('downloads');
//		}).mouseleave(function() {
//			$('#circle').removeClass('downloads');
//		});
//	}
//	
//	if(!$('#about').hasClass('current')) {
//		$('#about').mouseenter(function() {
//			$('#circle').addClass('about');
//		}).mouseleave(function() {
//			$('#circle').removeClass('about');
//		});
//	}
	
	// removed document.ready as we're already inside a jquery onload event'
	var NumberOfLogos = 4;
	$('#logo').css('background-image', 'url(\'css/images/logo'+((Math.floor(Math.random()*NumberOfLogos))+1)+'.png\')');
	
	$('#logo').mouseenter(function() {
		$(this).animate({'top':'3px'}, 150);
	}).mouseleave(function() {
		$(this).animate({'top':'0'}, 100);
	});
	
	$("#scrollWrapper").scrollable({ vertical: true, keyboard: true, speed: 250, clickable: false, api:true });
	
	// Enter the page with a hash
	if (window.location.hash.length > 0) {
		
		// Grab the thumb
		var thumb = $('#longScroller div div a[href="' + window.location.hash + '"]');
		var index = $(thumb).parent('div').index() + ($(thumb).parent('div').parent('div').index() * 4);
		
		$('#images div:eq(' + index + ')').animate({ 'opacity': 1, 'z-index': 1, }, 200);
		
		var instance = $("#scrollWrapper").data('scrollable');
		instance.seekTo($(thumb).parent('div').parent('div').index(), 1);
	}
	else {
		
		$('#images div:eq(0)').animate({ 'opacity': 1, 'z-index': 1, }, 200);
	}
		
	// Click on an image
	$('#longScroller div div').click(function(e) {
		
		e.stopPropagation();
		e.preventDefault();

		var _this = $(this).children('a');
		var index = $(this).index() + ($(this).parent('div').index() * 4);
		
		if ($('#images div:not(:animated)') && $('#images div.showed').index() != index) {
			
			window.location.hash = $(_this).attr('href');
			$('#images div').css({ 'z-index': 0 });
			$('#images div:eq(' + index + ')').css('display', 'block').animate({ 'opacity': 1, 'z-index': 1, }, 200, function() {
				$('#images div:not(:eq(' + index + '))').animate({ 'opacity': 0 }, 200, function() {
					$(this).css('display', 'none');
				});
				$('#images div, #scrollBackWrapper a').removeClass('showed');
			});
		}
	});
	
	// Hide the arrows
	if ($("#longScroller > div").length <= 1) {
		$(".prev, .next").removeClass('shown');
	}
	
});
