;(function($){

	var siteHeight = 837;

	$(document).bind('newContent', function() {
		$('a.zoom').colorbox();
		$('#fotogallery').jScrollPane();
	});

	$(document).ready(function(){

		// Full height page
		$(window).resize(function(){
			$('#wrapper').css('top', Math.max(0, ($(window).height()/2) - (837/2)));
		}).trigger('resize');
	});


	// Toggle boxes
	$('.toggle-box-content, .sub-toggle-box-content').each(function(){
//		$(this).data('height', $(this).height()).css('overflow', 'hidden');
		$(this).hide();
	});

	$('a.toggle').click(function(){

		$(this).parent().find('a.sub-toggle:first').trigger('click');
		$('.toggle-box-content:visible').hide();
//		$('.toggle-box-content:visible').animate({height: 0}, 400, function(){
//			$(this).hide()
//		});

		var $toggleBox = $(this).parent().find('.toggle-box-content:first');

		$toggleBox
			.show();
//			.animate({height: '100%'}, 400);

		return false;

	});

	$('a.sub-toggle').click(function(){

		var gallery = $(this).attr('rel');

		$('div#fotogallery-wrapper').animate({width: 0}, 200, function(){
			$.get('/gallery.php', {
				gallery : gallery
			}, function(data){

				$('#fotogallery')
					.html(data);

				$('#fotogallery-wrapper')
					.animate({width: 210}, 200);

				$(document).trigger('newContent');

			}, 'html');
		});





//		$('.sub-toggle-box-content:visible').animate({height: 0}, 400, function(){
//			$(this).hide()
//		});

		$(this).parents('.toggle-box').find('.sub-toggle-box-content').hide();
		var $toggleBox = $(this).parent().find('.sub-toggle-box-content');
//		$(this).parents('.toggle-box-content').height($toggleBox.height);

		$toggleBox
			.show();
//			.animate({height: $toggleBox.data('height')}, 400);

		return false;

	});

	$('a.toggle:first').trigger('click');


})(jQuery);
