var projectPaneOptions = null;
var redirecting = false;

if(window.location.hash.length){
	window.location = '/projects/index/' + window.location.hash.substring(2);
	redirecting = true;
} 

$(function(){
	if(!redirecting){
		
		$('#filter-container').projectsSubnav({
			orientation:'horizontal',
			onSubmit:function(filters){
				var url = '/projects/index';
				
				if(filters.length){
					url += '/filters:' + filters.join(',') + '/layout:ajax';
					window.location.hash = '/filters:' + filters.join(',') + '/';
				}else{
					url += '/layout:ajax';
					window.location.hash = '';
				}
				
				$('.jq-projectsProjectPane').projectsProjectPane('destroy').remove();
				$('#projects-container').unbind().empty();
				$('#projects-container').addClass('loading');
				
				$('#projects-container').load(url, function(){
					$('#projects-container').removeClass('loading');
					$(this).hide().fadeIn();
					$('.project-pane').projectsProjectPane(projectPaneOptions);
				});
			}
		});
		
		projectPaneOptions = {
			onOver:function(el){
				$('.project-pane.expanded').hide();
				el.next('.expanded').fadeIn(300);
				el.projectsProjectPane('resumeSlideshow');			
			},
			onOut:function(el){
				$('.project-pane.expanded').hide();
				$('.jq-projectsProjectPane').projectsProjectPane('pauseSlideshow');	
			}
		}
		
		$('.project-pane').projectsProjectPane(projectPaneOptions);
	}
});

function resetFilters(){
	$('#filter-container').projectsSubnav('reset');
}

