var permalink = false;

function init() {

	list_photos('date','desc',0);

	populate_sidebar();

	topnav_init();

	if (requestedphoto != -1) {									// story permalink through URL found
		permalink = true;										// set flag so we can control load process
		show_full_photo_scroll(requestedphoto);
	}
}

window.onload = init;



function list_photos(sortby,sortdir,pagestart) {
	// request main story list
	new Ajax('/ajax/retrieve_photolist.php', {
		postBody: Object.toQueryString({sortby: sortby, sortdir: sortdir, pagestart: pagestart}),
		update: 'storymaincontent',
		evalScripts: false,
		onComplete: function(){ 
			if (permalink) {
				open_fullstory(requestedstory);
				requestedstory = -1;
				permalink = false;
			}
		}
	}).request();
}


function populate_sidebar() {
	// request content for sidebar modules
	new Ajax('/ajax/retrieve_sidebar.php', {
		postBody: Object.toQueryString({modules: 'story_rated,story_discussed,story_viewed,author_rated,place_popular'}),
		update: 'sidebar',
		evalScripts: false,
		onComplete: function(){ nothing='examplecode'; }	// todo: do we need a function call on AJAX success?
	}).request();
}



// we catch opening of the lighttable to scroll window to the top
function show_full_photo_scroll(pid) {
	new Fx.Scroll(window).toTop();
	show_full_photo(pid,'photopage');
}



