var lastpage = 0;
var currentpage = 0;
var jsonFlickrApi = function(rsp){
	if (rsp.stat != "ok"){
		document.getElementById("flickr").style.display="none";
	}
	var vp = document.getElementById("flickrviewport");
	vp.innerHTML = "";
	if(rsp.photos.photo.length==0){
		vp.innerHTML="<strong>Sorry, we couldn't find any pictures of the festival on <a href=\"http://flickr.com\">Flickr</a>!</strong>";
		return null;
	}
	var cc = -1;
	for (var i=0; i<rsp.photos.photo.length; i++){
		var photo = rsp.photos.photo[i];
		var img = document.createElement('img');
		img.src= "http://farm"+photo.farm+".static.flickr.com/"+photo.server+"/"+photo.id+"_"+photo.secret+"_s.jpg";
		if(i%9==0){cc++;}
		var a = document.createElement("a");
		a.href="http://www.flickr.com/photos/"+photo.owner+"/"+photo.id;
		a.title=photo.title;
		a.appendChild(img);
		a.className="fimg";
		a.rel = cc;
		if(cc>0){a.style.display = "none";}
		vp.appendChild(a);
	}
	lastpage = cc;
	if(lastpage>0){
		document.getElementById("prev").style.display = "inline";
		document.getElementById("next").style.display = "inline";
	}
}
function f_hideall(except){
	var as = document.getElementsByTagName("a");
	for(i=0;i<as.length;i++){
		var a = as[i];
		if(a.className.substring(0,4)=="fimg"){
			a.style.display = "none";
		}
	}
	for(i=0;i<as.length;i++){
		var a = as[i];
		if(a.className.substring(0,4)=="fimg"&&a.rel==except){
			a.style.display = "inline";
		}
	}
}
function nf() {
	currentpage++;
	if(currentpage>lastpage){
		currentpage=0;
	}
	f_hideall(currentpage);
	return false;
}
function pf() {
	currentpage--;
	if(currentpage<0){
		currentpage=lastpage;
	}
	f_hideall(currentpage);
	return false;
}
