
var xml_gallery = '/gallery/';
var records_per_page = 7;
var width = 70;
var	height = 48;
var xmlDoc, record, index, display, row, recNodes,nodeNames,elementNodes,column;
var nr,heading,caption,sortfield,selectfield,selectvalue,record,field,fields,fieldArray,sortFldAttr;



function loadGallery(serie)
{
	$("#thumbs").html('');
	var url = xml_gallery;
	if (serie) {
		url +="?dir="+serie;	
	}
	document.getElementById('selectGallery').value = serie;
	createXML(url);
}




function show(nr) 
{
		
	//var imgName=display[nr].field0;
	//var position = display[nr].field6;
	
	showimg = document.images.showImg;
	src = '/fotos/'+images[nr];
	fade(src,showimg);
	

}
/////////////////////////////////////
// Create HTML Overview Thumbnails

function getThumbs(galleryPage)
{
  
  var pages = Math.floor(index/records_per_page);
  var remainderRecords = index % records_per_page;
  
 
  // navigation section
  var list="<div id=\"thumbNav\">pages: ";
  if(index > 0)
  {
    for (i=0;i<=pages;i++)
    {
      pageno=i+1;
      if (i!=pages||remainderRecords!=0)
      {
		list+="<a href='javascript:getThumbs("+i+")'";
		if(i==galleryPage) list+="id='current' ";
		list+=">"+pageno+"</a>&nbsp;";
	
		if (pageno == 26) {
			list +="<br>";
		}
      }
    }
  }
  list+="</div>";

  start = (galleryPage*records_per_page);
  if(galleryPage==pages) stop=(galleryPage*records_per_page)+remainderRecords;
  else stop=(galleryPage+1)*records_per_page;


	var thumbs = '';
  	for (i=start;i<stop;i++)
  	{
    	thumbs += addThumb(i);
  	}
  document.getElementById("thumbs").innerHTML=thumbs+list;
}


//////////////////////////////////////
// Parse XML File /////////////////////
var images;
function parseXML()
{
	var pics;
	pics = xmlDoc.getElementsByTagName("record");
  	index = pics.length
	
	// number of nodes in record which in Mozilla browsers includes whitespace nodes
 	recNodes = pics[0].childNodes.length;
	images = new Array;
	for(i=0;i<index;i++)
  	{
    	images[i] = pics[i].firstChild.firstChild.nodeValue
  	}
	
	getThumbs(0);
	show(0);
}



//////////////////////////////////////
// Load XML File /////////////////////

function createXML(file)
{

    $.ajax({
                 type: "GET",
                 url: file,
                 dataType: "xml",
                 success: function(xml) {
                    
					$('#showImg').attr('src',$(xml).find('record:first picture').text());
					
					 $(xml).find('record').each(function(){
                         var pic = $(this).find('picture').text();
                         var thumb = $(this).find('picturethumb').text();
                         var  orientation = $(this).find('orientation').text();
                         
						$('<div></div>').attr('pic',pic).attr('orient',orientation).addClass('dia').html($('<img></img>').attr('src','/fotos/thumb/?f='+pic)).appendTo('#thumbs');
                     }); 
                 }});

}

$(document).ready(function() {

	$('.dia').live('click',function() {
		$('#showImg').attr('src',$(this).attr('pic'));
		if($(this).attr('orient') == 'h') {
			$('#showImg').attr('width',550);
			$('#showImg').attr('height',410);

		} else {
			$('#showImg').attr('width',410);
			$('#showImg').attr('height',550);

		}
	});

});

