// JavaScript Document

var picture;
var nextPicture;

function previousPicture() {
	
	picture = parseFloat( document.location.hash.substring(1) );
	if( picture > 1 ) {
		
		nextPic = picture;
		nextPic--;
		document.location.hash = "#" + nextPic;
		
	}else{
		
		document.location.hash = "#" + galPictureCount;
		
	}
	
}

function nextPicture() {
	
	if( document.location.hash != "" ) {
	picture = parseFloat( document.location.hash.substring(1) );
	if( picture < parseFloat( galPictureCount ) ) {
		
		nextPic = picture;
		nextPic++;
		document.location.hash = "#" + nextPic;
		
	}else{
		
		document.location.hash = "#1";
		
	}
	}else{ document.location.hash = "#2"; }
	
}

$().ready(function() {
	
	var url = document.location.toString();
	var uRegExp = /\/f\//;
	
	if( url.search( uRegExp ) != -1 ) {
		setInterval("checkAnchor()", 300);
	}
	
});

var currentAnchor = null;
var picture;

function checkAnchor() {
	
	if(currentAnchor != document.location.hash) {
		currentAnchor = document.location.hash;
		
		if(!currentAnchor) {
			picture = "1";
		}else{
			picture = currentAnchor.substring(1);
			if( parseFloat( picture ) > parseFloat( galPictureCount ) ) { document.location.hash = "#1"; }
		}
		
		$("#imageNumber").html("Bilde " + picture + " av totalt " + galPictureCount);
		$("#image").html("<img src='" + baseUrl + "ajax/" + galYear + "/folder/" + galFolder + "/pic/" + picture + "' onclick='nextPicture()' style='cursor:pointer;border:1px solid #8e8e8e;padding:6px;' alt='Gallery Picture' />");
		
	}
	
}