var speed2 = 500;
/* Loading */
$(document).ready(function(){
	$("body").fadeIn(speed2);
});
/* Transitions */
$("#menu a, a.beauty").click(function(event){
	event.preventDefault();
	var url = $(this).attr('href');
	
	$("body").fadeOut(speed2, function(){
		var date = new Date();
		date.setTime(date.getTime() + (3 * 24 * 60 * 60 * 1000));
		$.cookie('scrollTo', window.pageYOffset, { path: '/' });
		window.location = url;
	});
});
/* Reference */
var change = true;
var click;
var move = 0;
var speed = 400;
$('#next, #prev').click(function(event){
	event.preventDefault();
	if(change){
		change = false;
		click = $(this);
		if(click.attr('id') == 'next'){
			move = count;
		}else{
			move = parseInt(count)-2;
		}
		$('#work').fadeOut(speed, function(){
			$('#work').html(ref[click.attr('rel')]['work']);
			$('#work').fadeIn(speed);
		});
		$('#screen img').fadeOut(speed, function(){
			$('#screen img').attr('src', '/r/'+ref[click.attr('rel')]['img']);
			$('#screen img').attr('alt', ref[click.attr('rel')]['name']);
			$('#screen img').fadeIn(speed);
		});
		$('#url').fadeOut(speed, function(){
			if(ref[click.attr('rel')]['url'] != ''){
				$('#url').html('<a href="'+ref[click.attr('rel')]['url']+'" title="'+ref[click.attr('rel')]['name']+'">'+ref[click.attr('rel')]['urlName']+'</a>');
			}else{
				$('#url').html(ref[click.attr('rel')]['urlName']);
			}
			$('#url').fadeIn(speed);
		});
		$('#info').fadeOut(speed, function(){
			$('#info').html(ref[click.attr('rel')]['info']);
			$('#counter span').html(click.attr('rel'));
			$('#info').fadeIn(speed, function(){
				$('#next').attr('rel', (parseInt(parseInt($('#next').attr('rel'))+move) % count)+1);
				$('#prev').attr('rel', (parseInt(parseInt($('#prev').attr('rel'))+move) % count)+1);
				jQuery.preLoadImages("/r/"+ref[$('#next').attr('rel')]['img'], "/r/"+ref[$('#prev').attr('rel')]['img']);
				change = true;
			});
		});
	}
});			
