/*
---
Custom Portfolio Javascript. You can add custom javascript to your site's portfolio section here (Galleries and pages).
The allows you to make additions and tweaks without modifying the site's core files.

To Activate this file, change the filename from Portfolio-sample.js to Portfolio.js

copyrights:
  - [Kemso, Ember](http://kemso.com, http://emberpack.com)

licenses:
  - [MIT License](http://emberpack.com/license.txt)
...
*/

/*
*	You can override the default portfolio options here.
*	You can also create new fields in your Site Settings section for any of these options.
*/
window.portfolio_default_options = {
	
	/*
	*	Make the gallery resize to fit the current image
	*/
	auto_gallery_height: true,
	
	/*
	*	Enable mouse wheel scrolling. (Note this only works in browsers that support horizontal scrolling (mostly just on Macs).
	*/
	mouse_scroll: true,
	
	/*
	*	If mouse_scroll is on, snap to closet image when scroll is finished.
	*/
	mouse_scroll_snap: true,
	
	/*
	*	Make the gallery height pop to the height of the largest item while mouse scrolling
	*/
	gallery_height_on_mouse_scroll: false,
	
	/*
	*	Hide gallery navigation while scrolling
	*/
	mouse_scroll_hide_navigation: false,
	
	/*
	*	Use vertical arrow keys to change the current gallery
	*/
	change_page_with_arrows: true,
	
	/*
	*	Wait to load images until they enter the screen.
	*	If you have a "lazy_load" custom field in your galleries, it will override this setting
	*/
	lazy_load: true,
	
	/*
	*	Number of images to load ahead of the current image, (when lazy_load is turned on).
	*/
	lazy_load_count: 3,
	
	/*
	*	Preload any images before starting up the site?
	*/
	assets_to_preload: [
	],
	
	/*
	*	Fit gallery overview into a grid
	*/
	gridify_gallery_overview: true,
	
	/*
	*	Weather or not to scroll through the album thumbnails on mouseover.
	*/
	gallery_overview_mouseover_preview: true,
	
	/*
	*	Dont allow drag and drop to save images.
	*/
	protect_images: false,
	
	/*
	*	Auto open categores ( turn this off for drop downs)
	*/
	auto_open_categories: false
}

// Page events.
window.addEvent('domready', function(){

	window.controller.addEvents({
		
		/* When the site is loaded and set up, but before any animation */
		'siteReady': function(){
		
		},
		
		/* When animation is complete */
		'postAnimation': function(){
		
		},
		
		'pageReady': function(page){
			switch(page.type)
			{
				case 'Gallery':
					handle_gallery(page);
					break;
				case 'Page':
					handle_page(page);
					break;
				case 'Contact':
					handle_contact(page);
					break;
			}
		}
	});
	
	
	/* Move nav to bottom if it's overlapping */
	if(config.get('sidebar_on_top') == '1')
	{
		var check_nav = function(){
			var w = $('sidebar').getElement('.content-padding').getComputedSize().width;
			var l = $('logo').getComputedSize({styles: ['margin','padding','border']}).totalWidth;
			var n = $('navigation').getComputedSize({styles: ['margin','padding','border']}).totalWidth;
			if(l + n > w){
				$('sidebar').addClass('nav-overflow');
				window.removeEvent('resize', check_nav);
			}else{
				//$('sidebar').removeClass('nav-overflow');
			}
		};
		window.addEvent('resize', check_nav);
		check_nav();
	}
	
	
	/* close category drop downs when you click on a gallery */
	$('navigation').getElements('li.category li a').addEvent('click', function(){
		this.getParent('.category').retrieve('cat:reveal').dissolve();
	});

});


// --------------------------------------------------------------------
	
/**
 * Handle a gallery
 * 
 */
function handle_gallery(page)
{
	// Center images vertically
	/*
$('content').getElements('.gallery .item.photo').each(function(el){
		el.getElement('img').setStyle('margin-top', Math.floor(600 - el.getElement('img').getSize().y) / 2);
	});
*/
}


// --------------------------------------------------------------------
	
/**
 * Handle a page
 * 
 */
function handle_page(page)
{

}


// --------------------------------------------------------------------
	
/**
 * Handle the contact page
 * 
 */
function handle_contact(page)
{

}
