// JavaScript Document
curPos = 0;
prevPos = 0;
nextPos = 1;

function menu() {
	for (var i = 1; i < images.length; i++) {
	images[i][2] = images[i][2].replace(/"/g,"&quot;");
	
	var output = '<a href="#' + i + '" id = "gallery_' + i +'" src="' + images[i][0] + '" description="' + images[i][2]  + '" title="' + images[i][1] + '" index="'+ i + '">' + i + '</a>'
	if (images[i][3] == 1) {
	var output = '<B>' + output + '</B>';
	}
	document.writeln(output);
	}
}

function updateimage(i) {
	curPos = parseInt(i);
	prevPos = curPos - 1;
	nextPos = curPos + 1;
	//alert(nextPos);
	if( (images.length -1) < nextPos ) nextPos = 1;
	if( prevPos == 0 ) prevPos = images.length-1;
	$("#wipe").fadeOut('700');
	$("#image").css({"background-image": 'url(' + images[curPos][0] + ')'});
	$("#image").attr("src", images[curPos][0]);
	$("#image").attr("title", images[curPos][1]);
	$("#rightbar h1").empty().append(images[curPos][1]);
	$("#rightbar #description h2").empty().append(images[curPos][1]);											
	$("#rightbar #description p").empty().append(images[curPos][2]);
	$("#navigation_gallery a").removeClass("selected");
	$("#gallery_" + curPos).addClass("selected");
}

	
$(document).ready(function(){
	updateimage(get_string());						   
	$("#rightbar h3").empty().append(images[0][0]);
	
	$("#navigation_gallery a").click(function() {
			 updateimage($(this).attr("index"));
	})
	
	$("#previous").click(function() {
			$("#previous").attr("href", "#" + prevPos);
			updateimage( prevPos );
	})

	$("#next").click(function() {
  			$("#next").attr("href", "#" + prevPos);
			updateimage( nextPos );
	})	
	
});