/* = BEHAVIOR.JS
---------------------------------------------------

CONTENTS

	* Color animation jQuery-plugin
	* Cookies
	* Array.prototype
	* Core Variables
	* Masonry
	* Drawer Toggles
	* Load collection from flickr
	* Load photo set from flickr
	* Load photo from flickr
	* Resize single photo container
	* Load pagination
	* Load slideshow from flickr
	* Adjust display size
	* Purchase form
	* jQuery Address
	
	* Document Ready
	* Document Loaded
	* Window Resize

*/

/*
 Color animation jQuery-plugin
 http://www.bitstorm.org/jquery/color-animation/
 Copyright 2011 Edwin Martin <edwin@bitstorm.org>
 Released under the MIT and GPL licenses.
*/
(function(d){function i(){var b=d("script:first"),a=b.css("color"),c=false;if(/^rgba/.test(a))c=true;else try{c=a!=b.css("color","rgba(0, 0, 0, 0.5)").css("color");b.css("color",a)}catch(e){}return c}function g(b,a,c){var e="rgb"+(d.support.rgba?"a":"")+"("+parseInt(b[0]+c*(a[0]-b[0]),10)+","+parseInt(b[1]+c*(a[1]-b[1]),10)+","+parseInt(b[2]+c*(a[2]-b[2]),10);if(d.support.rgba)e+=","+(b&&a?parseFloat(b[3]+c*(a[3]-b[3])):1);e+=")";return e}function f(b){var a,c;if(a=/#([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})/.exec(b))c=
[parseInt(a[1],16),parseInt(a[2],16),parseInt(a[3],16),1];else if(a=/#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])/.exec(b))c=[parseInt(a[1],16)*17,parseInt(a[2],16)*17,parseInt(a[3],16)*17,1];else if(a=/rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(b))c=[parseInt(a[1]),parseInt(a[2]),parseInt(a[3]),1];else if(a=/rgba\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9\.]*)\s*\)/.exec(b))c=[parseInt(a[1],10),parseInt(a[2],10),parseInt(a[3],10),parseFloat(a[4])];return c}
d.extend(true,d,{support:{rgba:i()}});var h=["color","backgroundColor","borderBottomColor","borderLeftColor","borderRightColor","borderTopColor","outlineColor"];d.each(h,function(b,a){d.fx.step[a]=function(c){if(!c.init){c.a=f(d(c.elem).css(a));c.end=f(c.end);c.init=true}c.elem.style[a]=g(c.a,c.end,c.pos)}});d.fx.step.borderColor=function(b){if(!b.init)b.end=f(b.end);var a=h.slice(2,6);d.each(a,function(c,e){b.init||(b[e]={a:f(d(b.elem).css(e))});b.elem.style[e]=g(b[e].a,b.end,b.pos)});b.init=true}})(jQuery);

/* cookies */
function createCookie(name,value,days) {
if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}

function eraseCookie(name) {
createCookie(name,"",-1);
}

/**
 * Array.prototype.[method name] allows you to define/overwrite an object's method
 * needle is the item you are searching for
 * this is a special variable that refers to "this" instance of an Array.
 * returns true if needle is in the array, and false otherwise
 
 	var x = Array();
	if (x.contains('foo')) {
	   // do something special
	}
 
 */
Array.prototype.contains = function ( needle ) {
   for (i in this) {
       if (this[i] == needle) return true;
   }
   return false;
}

// core variables
var bbFlickrAPIkey = "5dc061011d2b0996d0f92728a96e5b4a";
var bbFlickrUserID = "66560174@N08"; // get this from a user name to build cleaner urls

var homeSlideShowID = "72157627513922129";

var pagination = $('#header .pagination');
var container = $('#photoset, #collection');

var collection;

var timthumbpath = 'http://www.russfega.com/assets/flickrimages/timthumb.php?src=';


// masonry
function masonPhotoset(container) {

	if(!container) {
		container = $('#photoset, #collection');
	}

	container.masonry({
	       itemSelector: '.photograph',
	       isResizable: false,  
	       gutterWidth: container.width() / 20 // 5% width gutters 
	 });   
	 
}

// drawer toggles
$('#about').hide();

var purchaseFormDrawer;

$('#buy a').live('click', function(){
    purchaseFormDrawer.slideToggle('fast', function() {
    	// Animation complete.
		$('#purchase form').show();
		$('#purchase #message').remove();
	});
    $('#buy').toggleClass("active");
    return false;
});

$('#actrigger').click(function(){
 	$('#about').slideToggle();
    $('#actrigger').toggleClass("active");
    return false;
});
	
	
// load collection from flickr
var collectionObject = [];
			
function loadCollection(){
	
	pagination.remove();
	var error;
	
	if (collectionObject.stat == "ok"){
	
		// use the local object
		showCollection();
	
	} else {
	

		// grab data from flickr
		$.getJSON("http://www.flickr.com/services/rest/?method=flickr.photosets.getList&api_key="+bbFlickrAPIkey+"&user_id="+bbFlickrUserID+"&format=json&nojsoncallback=1&jsoncallback=?",
		function(data){
			
			if(data.stat == "fail"){
			
				// let the user know what went wrong
				error = 'Whoops. '+data.message;
			
			} else if (data.stat == "ok"){
				
				// create the local object
				collectionObject = data;
				showCollection();
				
			} else {
			
				// let the user know something went wrong
				error = 'Whoops. Something went wrong.';
				
			}
		
		});
		
	}
	
	// show the content
	function showCollection(){
	
		$('#content').removeClass("loading");
	
		if (error) {
		
			$('#content').append('<span class="error">'+error+'<\/span>');
	
		} else {
			
			// insert the set nav
			$('<div id="collection"><\/div>').appendTo("#content");
			
			var collectioncontainer = $("#collection");
			
		    // masonry
		  	masonPhotoset(collectioncontainer);
				
			// create a link for each set
	    	$.each(collectionObject.photosets.photoset, function(i,photoset){   
	    	
	    		if (photoset.id != homeSlideShowID) {
					
					collectioncontainer.append('<div id="id' + photoset.id + '" class="photograph"><a href="/#/portfolio/'+photoset.id+'" rel="address:/deep-link' + photoset.id + '" title="' + photoset.title._content + '"><img src="http:\/\/farm' + photoset.farm + '.static.flickr.com\/' + photoset.server + '\/' + photoset.primary + '_' + photoset.secret + '_m.jpg" alt="' + photoset.title._content + '" title="' + photoset.title._content + '" \/><h3>' + photoset.title._content + '<\/h3><\/a><\/div>').masonry( 'reload' );
					
				} else {
					// don't include the slideshow
				}
				
			});  
			
			// masonry
		    collectioncontainer.imagesLoaded( function(){
		    	masonPhotoset(collectioncontainer);
		   	});
		   	
		}
		   	
	}
	
	return false;
}


// load a photo set from flickr
var photoSetObject = [];
var selectedPhotoSet = [];

function loadPhotoSet(photoSetID){
	
	pagination.remove();
	
	var photoSetID = photoSetID;	
	var error;
						
	if (photoSetObject != "") {
		
		var match;
		
		$(photoSetObject).each(function(i){
			
			if (photoSetObject[i].photoset.id == photoSetID) {
				
				// the requested photo set exists in the local object
				
				selectedPhotoSet = photoSetObject[i];
				
				match = true;
				
			} else {
			
				// no match
			
			}

		});
		
		if (match == true) {
		
			showPhotoSet();
			
		} else {
			
			// the requested photo set must be grabbed from flickr
			
			getPhotoSet();
			
		}
	
	} else {
			
		// the requested photo set must be grabbed from flickr
		
		getPhotoSet();
	
	}
	
	// get content from flickr
	function getPhotoSet() {
	
		// get the requested photo set from flickr and add it to the local object
		$.getJSON("http://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&api_key="+bbFlickrAPIkey+"&photoset_id="+photoSetID+"&format=json&nojsoncallback=1&jsoncallback=?",
			function(data){
				
				if(data.stat == "fail"){
				
					// let the user know what went wrong
					error = 'Whoops '+data.message;
				
				} else if (data.stat == "ok"){
				
					// add the requested photo set to the local object
					
					if (photoSetObject.contains(photoSetID)) {
						// already in the array
					} else {
						photoSetObject.push(data);
					}
					
					selectedPhotoSet = data;
		
					showPhotoSet();
					
				} else {
				
					// let the user know something went wrong
					error = 'Whoops. Something went wrong.';
					
				}
	
		});
		
	}
	
	// display the content
	function showPhotoSet() {
					
		$('#content').removeClass("loading");
	
		if (error) {
		
			$('#content').append('<span class="error">'+error+'<\/span>');
	
		} else {
	
			// insert the photo container
			$('<div id="photoset"><\/div>').appendTo("#content");
			
			var photosetcontainer = $("#photoset");
			
		    // masonry
		    masonPhotoset(photosetcontainer);
			
			// create a link for each photo
	    	$.each(selectedPhotoSet.photoset.photo, function(i,photo){  
				
				photosetcontainer.append('<div id="id' + photo.id + '" class="photograph"><a href="/#/portfolio/'+photoSetID+'/' + photo.id + '"><img src="http:\/\/farm' + photo.farm + '.static.flickr.com\/' + photo.server + '\/' + photo.id + "_" + photo.secret + '.jpg" alt="' + photo.title + '" title="' + photo.title + '" \/><h3>' + photo.title + '<\/h3><\/a><\/div>').masonry( 'reload' );
					
			});  
			
			// masonry
		    photosetcontainer.imagesLoaded( function(){
		    	masonPhotoset(photosetcontainer);
		   	});
		   	
		}
		
	}
	
	return false;
}

				
// load a photo from flickr
var photoObject = [];
var selectedPhoto = [];

function loadPhoto(photoID, photoSetID) {
	
	var error;
						
	if (photoObject != "") {
		
		var match;
		
		$(photoObject).each(function(i){
			
			if (photoObject[i].photo.id == photoID) {
				
				// the requested photo set exists in the local object
				
				selectedPhoto = photoObject[i];
				
				match = true;
				
			} else {
			
				// no match
			
			}

		});
		
		if (match == true) {
			
			showPhoto();
			
		} else {
			
			// the requested photo must be grabbed from flickr
			
			getPhoto();
			
		}
	
	} else {
			
		// the requested photo must be grabbed from flickr
		
		getPhoto();
	
	}
	
	// get photo from flickr
	function getPhoto() {

		$.getJSON("http://api.flickr.com/services/rest/?method=flickr.photos.getInfo&api_key="+bbFlickrAPIkey+"&photo_id="+photoID+"&format=json&nojsoncallback=1&jsoncallback=?",
			function(data){
				
				if(data.stat == "fail"){
				
					// let the user know what went wrong
					error = 'Whoops '+data.message;
				
				} else if (data.stat == "ok"){
				
					// add the requested photo set to the local object
					
					if (photoObject.contains(photoID)) {
						// already in the array
					} else {
						photoObject.push(data);
					}
					
					selectedPhoto = data;
				
					showPhoto();
					
				} else {
				
					// let the user know something went wrong
					error = 'Whoops. Something went wrong.';
					
				}
		
		});
	
	}
	
	// display the content
	function showPhoto() {
		
		loadPagination(photoID, photoSetID);
	
		if (error) {
		
			$('#content').append('<span class="error">'+error+'<\/span>');
	
		} else {

			// insert the photo container
			var viewer = $("#viewer");
			
			if(viewer.length === 0){
			
				$('<div id="viewer" class="active"><\/div>').appendTo("#content");
				viewer = $("#viewer");
				
				purchaseForm = '<div id="purchase" class="clearfix"><div class="copy"><h3>Request a Quote for Prints of <span class="title"></span><\/h3><form id="purchaseform" action=""><input id="requestthis" type="readonly" class="accessibility" value="" /><input type="text" id="email" value="you@yours.com" /><button type="submit" value="">send</button></form><p class="confirmation">Thanks for your interest in prints of <span class="title"></span>. You\'ll receive more information soon.</p></div></div><!-- /#purchase -->';
				
				$(purchaseForm).insertBefore("#content");
				
				purchaseFormDrawer = $('#purchase');
				
				resizeViewer();
				
			} else {
			
				viewer = $("#viewer");
				
			}
				
			purchaseRequest(photoID, photoSetID);
							
			// show the photo   
    	
    		var imagesource = timthumbpath + 'http:\/\/farm' + selectedPhoto.photo.farm + '.static.flickr.com\/' + selectedPhoto.photo.server + '\/' + selectedPhoto.photo.id + "_" + selectedPhoto.photo.secret + '_b.jpg&w=800';
			
			viewer.append('<div id="id' + selectedPhoto.photo.id + '" class="photograph"><img src="'+ imagesource +'" alt="' + selectedPhoto.photo.title._content + '" title="' + selectedPhoto.photo.title._content + '" \/><h3>' + selectedPhoto.photo.title._content + '<\/h3><\/div>');
			
			$("div", viewer).hide();
				
			$("div", viewer).imagesLoaded( function(images){
				$('#content').removeClass("loading");
				$("div", viewer).fadeIn();
	   		}); 
	   		
	   		$('#purchase .title').text(selectedPhoto.photo.title._content);
	   		$('#purchase #requestthis').attr("value", selectedPhoto.photo.title._content);
		   	
		}
		
	}
	
	return false;
}

// single photo viewer resize
function resizeViewer() {

	if ($("body").hasClass("singlephoto") && $(window).height() > 600) {
	
		// resize the single photo viewer 
		if ($('.singlephoto #viewer').height() < $(window).height()){
			
			var containerHeight = $(window).height() - 300;
			
			$('.singlephoto #viewer').height(containerHeight);
	
		} else {
			// do nothing
		}
		
	} else if ($("body").hasClass("home")) {
	
		// resize slideshow viewer

		if ($('.home #photoset').height() < $(window).height()){
	
			$('.home #photoset').height($(window).height() - $('#header').outerHeight(true));
			
		} else {
			// do nothing
		}
	
	} else {
	
		// nothing to resize
	
	}
}



// single photo pagination
function loadPagination(photoID, photoSetID){
	
	var nextPhoto;
	var prevPhoto;
	var openSet;
	var buyPrint;
					
	var openSet = '<li id="set"><a href="/#/portfolio/'+photoSetID+'/"><span class="accessibility">Set<\/span></a><\/li>';
	var buyPrint = '<li id="buy"><a href="/#/portfolio/'+photoSetID+'/'+photoID+'"><span class="accessibility">Buy<\/span></a><\/li>';
	
	var error;
		
	if (photoSetObject != "") {
		
		var match;
		
		$(photoSetObject).each(function(i){
			
			if (photoSetObject[i].photoset.id == photoSetID) {
				
				// the requested photo set exists in the local object				
				selectedPhotoSet = photoSetObject[i];
				
				match = true;
				
			} else {
			
				// no match
			
			}

		});
		
		if (match == true) {
			
			// use the local object	
			showPagination();
			
		} else {
			
			// the requested photo info must be grabbed from flickr			
			getPagination();
			
		}
	
	} else {
			
		// the requested photo info must be grabbed from flickr		
		getPagination();
	
	}
	
	// get pagination info
	function getPagination() {
	
		$.getJSON("http://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&api_key="+bbFlickrAPIkey+"&photoset_id="+photoSetID+"&format=json&nojsoncallback=1&jsoncallback=?",
			function(data){
		
				if(data.stat == "fail"){
				
					// let the user know what went wrong
					error = 'Whoops '+data.message;
				
				} else if (data.stat == "ok"){
				
					// add the requested photo set to the local object
					
					if (photoSetObject.contains(photoSetID)) {
						// already in the array
					} else {
						photoSetObject.push(data);
					}
					
					selectedPhotoSet = data;
					
					showPagination();
					
				} else {
				
					// let the user know something went wrong
					error = 'Whoops. Something went wrong.';
				
				}
		
		});
		
	}
	
	// display the pagination
	function showPagination() {
					
		pagination = $('#header .pagination ul');
			
		if(pagination.length) {
			pagination.empty();
		} else {
			$('#header').append('<div id="id' + photoID + '" class="pagination"><ul><\/ul><\/div>');
			pagination = $('#header .pagination ul');
		}
		
		var i=0;
		var currentIndex;
		
		for (i=0;i<=selectedPhotoSet.photoset.photo.length;i++)
		{
			if(selectedPhotoSet.photoset.photo[i].id == photoID) {
				currentIndex = i;
				break;
			}
		}
				
		if (currentIndex === (selectedPhotoSet.photoset.photo.length-1)){
			// we're on the last photo
			nextPhoto = '<li id="next" class="inactive"><\/li>';
		} else {
			nextPhoto = '<li id="next"><a href="/#/portfolio/'+photoSetID+'/' + selectedPhotoSet.photoset.photo[currentIndex+1].id + '"><span class="accessibility">Next<\/span></a><\/li>';
		}
		
		if (currentIndex === 0){
			// we're on the first photo
			prevPhoto = '<li id="prev" class="inactive"><\/li>';
		} else {
			prevPhoto = '<li id="prev"><a href="/#/portfolio/'+photoSetID+'/' + selectedPhotoSet.photoset.photo[currentIndex-1].id + '"><span class="accessibility">Prev<\/span></a><\/li>';
		}
				
	    pagination.append(prevPhoto, openSet, buyPrint, nextPhoto);
	    	
	}		
	
	return false;
			
}

// loadSlideShow
var photoSetSlideshowObject = [];

function loadSlideShow(photoSetID) {

	pagination.remove();
	
	var error;
	var photoSetID = photoSetID;
	
	if (photoSetSlideshowObject.stat == "ok"){
	
		// use the local object
		showSlideshow();
	
	} else {
	
		// grab data from flickr		
		$.getJSON("http://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&api_key="+bbFlickrAPIkey+"&photoset_id="+photoSetID+"&format=json&nojsoncallback=1&jsoncallback=?",
		function(data){
		
			if(data.stat == "fail"){
			
				// let the user know what went wrong
				error = 'Whoops. '+data.message;
			
			} else if (data.stat == "ok"){
			
				// create the local object
				photoSetSlideshowObject = data;
			
				// use the remote object
				showSlideshow();
			
			} else {
			
				// let the user know something went wrong
				error = 'Whoops. Something went wrong.';
			
			}
				
		});
	}
	
	// display the content
	function showSlideshow() {
		$('#content').removeClass("loading");
	
		if (error) {
		
			$('#content').append('<span class="error">'+error+'<\/span>');
	
		} else {
	
			// insert the photo container
			
			$('<div id="photoset"></div>').appendTo("#content").hide();
		
			var photoSetContainer = $("#photoset");
			
		
			// resize the content container
			resizeViewer(); 
	
			// create a slide for each photo
	    	$.each(photoSetSlideshowObject.photoset.photo, function(i, photo){  
				
				photoSetContainer.append('<div id="id' + photo.id + '" class="photograph"><a href="/#/portfolio"><img src="'+ timthumbpath +'http:\/\/farm' + photo.farm + '.static.flickr.com\/' + photo.server + '\/' + photo.id + "_" + photo.secret + '_b.jpg&w=800" alt="' + photo.title + '" title="' + photo.title + '" \/><h3>' + photo.title + '<\/h3></a><\/div>');
					
			});  
		
			// initialize the slideshow
			$('#photoset').cycle({
				fx: 'fade'
			});
			
			$('#photoset,#header,#footer').fadeIn(1500, function(){
				$('body').removeClass('splash').removeAttr('style');
			});
			
		}
	}
	
	return false;
}

function adjustDisplaySize() {
	
	// make the adjustment which corresponds to the display format
	if ($("body").hasClass("home") || $("body").hasClass("singlephoto")) {
	
		// single photo size
		resizeViewer();
	
	} else {
	
		// masonry
		masonPhotoset(); 
	
	}
}

// purchase form
function purchaseRequest(photoID, photoSetID) {

	function validateEmail(txtEmail){
	   var filter = /^[a-zA-Z0-9]+[a-zA-Z0-9_.-]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$/;
	    if(filter.test(txtEmail)){
	        return true;
	    }
	    else{
	        return false;
	    }
	}
	
	var sending = false;
	
	$("#purchase #email").focus(function () {
         $(this).attr('value', '');
    });
	
	$("#purchase #email").blur(function () {
	
		if (sending == true){
        } else {
        	//$(this).attr('value', 'you@yours.com');
        }
        
    });
	
	$("#purchase button").live('click', function() {
		
		// validate and process form
		
		sending = true;
		
		$("#purchase #message").remove();
			
		var requestedPrintPhoto = $("input#requestthis").val();
			
		var email = $("input#email").val();
		
		if (validateEmail(email) && email != "" && email != "you@yours.com") {
			// valid email address
	    } else {
			// invalid email address
			$("input#email").focus().addClass("error").attr('value', 'you@yours.com');
			return false;
      	}
		
		var requestPrintInfo = '/assets/process.php?email=' + email + '&photo=' + requestedPrintPhoto + '&refURL=' + document.location.href.replace(/#/i, "hash");
		
			
		$.ajax({
	      type: "POST",
	      url: requestPrintInfo,
	      data: requestPrintInfo,
	      success: function(data) {
	      	
	      	if (data == "success") {
	      
		        $('#purchase form').hide();
		        $('#purchase').append("<div id='message'></div>");
		        $('#message').html("<h2>Thanks for your interest. You'll receive a response soon.</h2>").hide()
		        .fadeIn(1500, function() {
		        });
		        
		    } else {
		    
		        $('#purchase').append("<div id='message'></div>");
		        $('#message').html("<h2>Whoops, something went wrong. Try again.</h2>").hide()
		        .fadeIn(1500, function() {
		        });

		    }
		    
		    sending = false;
		    
	      }
	     });
	     
    return false;
    
	});

}


// -----------------------------------------------------------
// START DOING THINGS!
// -----------------------------------------------------------


// jQuery Address Handles Clean URLs
$.address.change(function(event) {  

	$('#content').addClass("loading");
    
    // split the event value into parts to get the hierarchical values
    // www.baseurl.com/collection/photoset/photo
	var eventValueArray = event.value.split("/");
	var activeCollection = eventValueArray[1];
	var activePhotoset = eventValueArray[2];
	var activePhoto = eventValueArray[3];
	
	var activeSection;
	
	// utility page urls
	if(activeCollection === "about"){
		activeCollection = null;
		activeSection = eventValueArray[1];
	}
				
	// set the container height
	var containerHeight = $('#content div.active').height();
	
	if($(window).height() > 600) {
		$('#content div.active').height(containerHeight);
	}
	
	// empty the container
	$('#content div:not(#viewer)').removeAttr('style').removeClass('masonry');
	
	$('#content div div').fadeOut('fast', function() {
    	$(this).remove();
  	});
	
	$('body').removeClass('singlephoto photoset collection home');
	
	$('#purchase').hide();
		
    // do something depending on the event.value property  
	if (event.value === "/") {
	
		// we're on the home page
		
		$('body').addClass('home');
		$('#content div:not(#photoset)').remove();
		
		if (!readCookie("animated")) {
	
			$('body').addClass('splash');
	
			$('#content').append('<div id="splash"><\/div>').hide().fadeIn(1500, function() {
				// Animation complete.
				
				$('#splash').fadeOut(1500, function() {
				// Animation complete.
					$('body').animate({
					    backgroundColor: '#333'
					}, 1500, function() {
					    // Animation complete.
						loadSlideShow(homeSlideShowID);
						//firstload = true;
						createCookie("animated", "true", 7);
					});
		    	});
		    	
	    	});
    	
		} else {
		
			loadSlideShow("72157627395473659");
		
		}
	
	} else if (activePhoto) {
		
		$('body').addClass('singlephoto').removeClass('firstload');
		$('#content div:not(#viewer)').remove();
		
		// load photo
		loadPhoto(activePhoto, activePhotoset);
		
	} else if (activePhotoset) {
		
		$('body').addClass('photoset').removeClass('firstload');
		$('#content div:not(#photoset)').remove();
	
		// load photoset
		loadPhotoSet(activePhotoset);
		
	} else if (activeCollection) { 
	
		$('body').addClass('collection').removeClass('firstload');
		$('#content div:not(#collection)').remove();
		
		// load collection
		loadCollection();
		
	} else if (activeSection) {
	
		// load a different page
		
	}
    
}); 

// document ready
$(document).ready(function() {
    
    
});

// document loaded
$(window).load(function() {
	
	adjustDisplaySize();
				
});

// document resized    
$(window).resize(function(){  
	
	adjustDisplaySize();
	 
}).resize();
