// JavaScript Document

$(document).ready(function(){
						   
	//borrowed from jQuery easing plugin
	//http://gsgd.co.uk/sandbox/jquery.easing.php
	$.easing.elasout = function(x, t, b, c, d) 
	{
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	}; 	
	
	//Handler for opening mid menu				   
  	$('.expand').click(function(e) {
		DisplaySubFloor();
	});
	
	//Handler for closing mid menu
	$('.photo-menu-close').click(function(e) {
		HideSubFloor();
	});
	
	//Photo Link Handlers
	$('#link-photos-travel').click(function(e) {
		GoToPhotoCollection(e);
	});
	$('#link-photos-picturePhone').click(function(e) {
		GoToPhotoCollection(e);
	});
	$('#link-photos-desktops').click(function(e) {
		GoToPhotoCollection(e);
	});
	$('#link-photos-anyGivenDay').click(function(e) {
		GoToPhotoCollection(e);
	});
	$('#link-photos-headers').click(function(e) {
		GoToPhotoCollection(e);
	});
});

/*** Expose photo menu  ***/
function DisplaySubFloor()
{
	$('#top-layer').animate({'top':'270px'},1500);
	$('#middle-layer').animate({'top':'220px'},2037);
}

/***  Hide Photo Menu  ***/
function HideSubFloor()
{
	$('#top-layer').animate({'top':'150px'},1500);
	$('#middle-layer').animate({'top':'150px'},2037);
	GoHome();
}

/*** Scroll to Photo Collection ***/
function GoToPhotoCollection(e)
{
	//trim the first three characters off the link to get to the element name
	var photoCollection = '#' + ((e.target.id).substring(5));
	//stop any current ani and go to div offset by 30
	$('#photo-window').stop().scrollTo(photoCollection, 2500,{offset:-30,easing:'elasout'});
	//console.log($(photoCollectionID).html());
}

function GoHome(e)
{
	$('#photo-window').stop().scrollTo({top:0, left:0},800);
}
