/*!
 * AM Adriaan Mellegers JS
 */



$(document).ready( function() {

	//alert('AM');

    // Load the classic theme
	Galleria.loadTheme('/ndxz-studio/site/js/themes/am12/galleria.am12.js');

	// Initialize Galleria
	//$('.galleria').galleria({  transition: 'pulse', autoplay: 100  });
	// now done per gallery, so we can have different speeds / transitions
	
	$('.go_information').live('click', go_information);
	$('.go_top').live('click', go_top);
	
	
	
	/* Masonry */
	
	$('#main').masonry({
      itemSelector: '.item',
      columnWidth: 100
    });
    
    
	
	/* Infinite Scroll */
	
	$('#main').infinitescroll({
 
		navSelector  : "#main_navigation",            
		// selector for the paged navigation (it will be hidden)
		
		nextSelector : "#main_navigation a",    
		// selector for the NEXT link (to page 2)
		
		itemSelector : "#main div.item",         
		// selector for all items you'll retrieve
		
		donetext     : "<h4>END OF PAGE</h4>",
		loadingImg   : false,
		loadingText  : "Loading"
		
		},function(arrayOfNewElems){
 
		// optional callback when new content is successfully loaded in.
 
		// keyword `this` will refer to the new DOM content that was just added.
		// as of 1.5, `this` matches the element you called the plugin on (e.g. #content)
		//                   all the new elements that were found are passed in as an array
		
		//alert(arrayOfNewElems);
		
		for (i=0; i<arrayOfNewElems.length; i++) {
			//alert($(arrayOfNewElems[i]).attr('class'));
			transition = $(arrayOfNewElems[i]).attr('class').split('transition-')[1].split(' ')[0];
			autoplay = $(arrayOfNewElems[i]).attr('class').split('autoplay-')[1].split(' ')[0];
			//alert(transition + autoplay);
			
			galleria_options = new Array();
			
			if (transition) galleria_options['transition'] = transition;
			if (autoplay) galleria_options['autoplay'] = autoplay;
			
			$($(arrayOfNewElems[i]).children('.galleria')).galleria(galleria_options);
			//alert($(arrayOfNewElems[i]).attr('id'));
			
			$('#main').masonry( 'reload' );
			
			};
		
		//alert('Loaded.');
 
		});
	
	
});


function go_information(event) {

	if ($('#information').is(':visible')) {
		if (window.pageYOffset > $('#information').height()) {
			$('html, body').animate({scrollTop:0});
			} else {
			$('#information').slideUp();
			$('html, body').animate({scrollTop:0});
			}
		} else {
		$('#information').slideDown();
		$('html, body').animate({scrollTop:0});
		}
	return false;
}

function go_top(event) {
	$('html, body').animate({scrollTop:0});
	return false;
}
