$(document).ready(function(){
	
	$('.photo-area').each(function() {
																 
		var group = $(this);
		var groupPager = $(this).parent().parent().find('.nav-photos-num');
		
		$(this).cycle({ 
				fx:     'fade', 
				speed:  'fast', 
				timeout: 0, 
				next:   $(this).parent().find('.album-header .btn-photo-next'), 
				prev:   $(this).parent().find('.album-header .btn-photo-prev'),
				pager:  $(this).parent().find('.nav-photos-num'),
				pagerAnchorBuilder: function(idx, slide) {
					return groupPager.find('li a').eq(idx);
				}
		});
	
	});
	
	/* navigate previous album */

	$('#btn-prev-album').click(function(){
																			
		$('html, body').stop();
																			
		var scrollPos = $(window).scrollTop() + 130;
		
		$('.album').each(function(){
			
			var elementTop = Math.round($(this).offset().top);
			var elementBottom = Math.round($(this).offset().top + $(this).height() + 50);
			
			if( elementTop <= scrollPos && scrollPos < elementBottom){
					
					if($(this).prev().length != 0){
						
						var destination = $(this).prev().offset().top - 130;
						$('html, body').stop().animate({scrollTop:destination}, 480, 'easeInOutQuint');
						window.location.hash = $(this).prev().find('.anchor').attr('id');
						
					}
					
			}
		
		});

		return false;
		
	});
	
	/* navigate next album */
	
	$('#btn-next-album').click(function(){
																			
		$('html, body').stop();
																			
		var scrollPos = $(window).scrollTop() + 130;	
		
		$('.album').each(function(){
			
			var elementTop = Math.round($(this).offset().top);
			var elementBottom = Math.round($(this).offset().top + $(this).height() + 50);
			
			if( elementTop <= scrollPos && scrollPos < elementBottom){
					
					if($(this).next().length != 0){
						
						var destination = $(this).next().offset().top - 130;
						$('html, body').stop().animate({scrollTop:destination}, 480, 'easeInOutQuint');
						window.location.hash = $(this).next().find('.anchor').attr('id');
						
					}
					
			}
		
		});

		return false;
		
	});
	
	/* hide/show album exceprt */
	
	$('.album-closing').each(function(){
		if($.trim($(this).find(".album-description").text()) != "") { 
			$(this).find('.album-description').slideDown('slow');
			$(this).prev('.album-options').find('.btn-info-hidden').toggleClass('btn-info-shown').toggleClass('btn-info-hidden');
		}else{
			$(this).prev('.album-options').find('.btn-info-hidden').hide();
		}
	});
	
	$('.btn-info-shown, .btn-info-hidden').click(function(){
		
		if($(this).hasClass('btn-info-shown')){
			$(this).parent().next().find('.album-description').slideUp('fast');
		}else{
			$(this).parent().next().find('.album-description').slideDown('slow');	
		}
		
		$(this).toggleClass('btn-info-shown').toggleClass('btn-info-hidden');
		
		return false;
	
	});



});
