// controls for ProjectPager
function pageTo(id, title, doScroll){
	jQuery("#icon_cell_"+id+" a").blur();
	if(id == currentProjectId) return false;
	jQuery("#title_cell").html(title);
	jQuery("#pager_content").fadeTo("medium", 0.1); // avoid scroll jumps by almost fading to 0
	jQuery.get(PROJECT_URL+"content.php",
			   {contentId:id},
			   function(data){
				   jQuery("#pager_content").html(data);
				   jQuery("#pager_content").fadeTo("medium", 100, function(){
						if (jQuery.browser.msie) this.style.removeAttribute('filter'); // IE ugliness with fades and anti-aliasing
					});
				   Lightbox.prototype.updateImageList(); // re-init image list in case content has lightbox
			   });
	// visuals
	var rollSrc = jQuery("#icon_cell_"+currentProjectId+" img").attr("src");
	jQuery("#icon_cell_"+currentProjectId+" img").attr("src", jQuery("#icon_cell_"+id+" img").attr("src"));
	jQuery("#icon_cell_"+id+" img").attr("src", rollSrc);
	currentProjectId = id;
	
	// scroll to pager
	if(doScroll) jQuery.scrollTo(jQuery("#title_cell"));
	
	return false;
}

function nextPage(doScroll){
	var index = getCurrentIndex();
	if(index == -1) return;
	index++;
	if(index >= projectIds.length) return;
	pageTo(projectIds[index], projectTitles[index], doScroll);
}

function prevPage(doScroll){
	var index = getCurrentIndex();
	if(index == -1) return;
	index--;
	if(index < 0) return;
	pageTo(projectIds[index], projectTitles[index], doScroll);
}

function getCurrentIndex(){
	for(var i=0; i<projectIds.length; i++){
		if(projectIds[i] == currentProjectId) return i;
	}
	return -1;
}

jQuery(document).ready(function(){
	jQuery("#pager a").tooltip({track: true, 
							   showURL: false,
							   delay:0
							   });
});
