var actual = 0;

function center(){
	$('.box').css('padding-top',($('body').height() - $('.box').height())/2+'px');
}

$(window).ready(function() {
	center();
});

$(window).resize(function() {center();});

function binding(){
	$('.prev').click(function(){
		actual[1] = (actual[1] > 0) ? --actual[1] : page[actual[0]].length - 1;
		set_photo(actual[1]);
		$('#i'+$(this).attr('href')).html(page[actual[0]][actual[1]][1]);
		return false;
	});
	
	$('.next').click(function(){
		actual[1] = (actual[1] < page[actual[0]].length - 1) ? ++actual[1] : 0;
		set_photo(actual[1]);
		$('#i'+$(this).attr('href')).html(page[actual[0]][actual[1]][1]);
		return false;
	});
	
	$('.page').click(function(){
		var id = $(this).attr('href');
		if($('#p'+id).css('display')=='inline-block'){
			if($('#p'+actual[0]).css('display')=='none'){
				$('#h'+actual[0]).animate({width: 'toggle'},function() {
					$('#p'+actual[0]).css('display','inline-block');
					$('#p'+id).css('display','none');
					$('#h'+id).animate({width: 'toggle', opacity: 'toggle'},function() {$(this).css('display','inline-block');});
					actual[0] = id;
					actual[1] = 0;
					set_photo(0);
					$('#i'+id).html(page[actual[0]][actual[1]][1]);
				});
				return false;
			}
			$('#p'+id).css('display','none');
			$('#h'+id).animate({width: 'toggle', opacity: 'toggle'},function() {$(this).css('display','inline-block');});
			actual[0] = id;
			actual[1] = 0;
		} else {
			$('#h'+id).animate({width: 'toggle'},function() {$('#p'+id).css('display','inline-block');});
			start_photo();
			return false;
		}
		set_photo(0);
		$('#i'+id).html(page[actual[0]][actual[1]][1]);
		return false;
	});
	
	$('.contact a').click(function(){return false;});
	
	$('.contact a').mouseover(function(){
		$(this).html('Contact /');
		$('#contact').fadeIn(1000);
		$('#contact').css('display','inline-block');
		return false;
	});
	
	$('.contact a').mouseout(function(){
		$(this).html('/ Contact');
		$('#contact').fadeOut(1000);
		return false;
	});
	
	$('.info_link').click(function(){return false;});
	
	$('.info_link').mouseover(function(){
		var id = $(this).attr('href');
		$('#i'+id).fadeIn(1000);
		$('#i'+id).css('display','inline-block');
		return false;
	});
	
	$('.info_link').mouseout(function(){
		var id = $(this).attr('href');
		$('#i'+id).fadeOut(1000);
		return false;
	});
}

function set_photo(id){
	$('.background').attr('src','upload/'+page[actual[0]][id][0]);
	$('.background').lazyload({ 
		effect : "fadeIn"
	});
}

function start_photo(){
	$('.background').attr('src','upload/'+bg_photo);
	$('.background').lazyload({ 
		effect : "fadeIn"
	});
}

