	
	function OpenPopup(imgSource, imgWidth, imgHeight) 
	{
		var winl = (screen.width - imgWidth) / 2;
		var wint = (screen.height - imgHeight) / 2;
		if (winl < 0) winl = 0;
		if (wint < 0) wint = 0;

		windowprops = "height="+(imgHeight+18)+",width="+(imgWidth+18)+",top="+ wint +",left="+ winl +",location=no,"
		+ "scrollbars=no,menubars=no,toolbars=no,resizable=no,status=no";

		window.open(imgSource, "Popup", windowprops);
	}

	function ShowHide(elmId)
	{
		var element = document.getElementById(elmId);
		element.style.display = (element.style.display == 'none') ? 'block' : 'none';
	}

	function HideAll()
	{
		var element = '';
		for(var i = 0; i < arguments.length; i++)
		{
			element = document.getElementById(arguments[i]);
			element.style.display = 'none';
		}
	}

	function ShowAll()
	{
		var element;
		for(var i = 0; i < arguments.length; i++)
		{
			element = document.getElementById(arguments[i]);
			element.style.display = 'block';
		}
	}
  
var albumlastindex = 0;
var album = { 

  _lastimage: null,
  _lastindex: 0,
  _lastslide: -1,
  
  initialize: function() { 
    //$('frontslideshow').insert("a");
    album.startup();
  }, 
  startup: function() { 
    // 
    var delay = 5;
  
    // get timer
    new Ajax.Request('/files/templates/piaa/config.xml', {
        method: 'get',
        onSuccess: function(transport) {
          
          var xmlDocument;
          if(document.all)
          {
              xmlDocument = new ActiveXObject("Microsoft.XMLDOM");
              xmlDocument.loadXML(transport.responseText);
          }
          else // not IE
          {
              xmlDocument = transport.responseXML;
          }
          
          var childnodelength=xmlDocument.childNodes[0].childNodes.length;
          for(var i = 0; i < childnodelength; i++) {
            if(xmlDocument.childNodes[0].childNodes[i].nodeName == "slide") {
              //alert(xmlDocument.childNodes[0].childNodes[i].attributes["url"].value);
              /*var node = $(xmlDocument.childNodes[0].childNodes[i]);*/
              var url = xmlDocument.childNodes[0].childNodes[i].attributes[0].value;
              //alert(url);
              $('frontslideshow').insert('<img src=\"' + url + '\" style=\"display: none;\" id="albumimage' + i + '" />');          
            }
          }
          
          album.cycle();
        }
    });
    //
  }, 
  cycle: function() { 
    
    var images = null;
    if(album._lastimage == null) {
      var images = $('frontslideshow').getElementsBySelector('img');
      //alert(images);
      if(images.length > 0) {
        album._lastimage = images[0];
      }
      
      if(album._lastimage != null) {
        new Effect.Appear(album._lastimage.id, {
          duration: 1,
          fps: 50,
          queue:'end'
        }) 
      }
    }
    else
    {
      var nextsibling = null;
      var nextsiblings = album._lastimage.nextSiblings();
      if(nextsiblings.length > 0) {
        nextsibling = nextsiblings[0];
      }
      
      if(nextsibling == null) {
        var images = $('frontslideshow').getElementsBySelector('img');
        if(images.length > 0) {
          nextsibling = images[0];
        }
      }
      
      if(nextsibling != null) {
        new Effect.Fade(album._lastimage.id, { // the id of the <DIV> containing the photos 
          duration: 1, 
          fps: 50, 
          afterFinish: function() { 
            new Effect.Appear(nextsibling.id, {
              duration: 1,
              fps: 50,
              queue:'end'
            }) 
          } 
        })
        
        album._lastimage = nextsibling
      }
    }
    
    new PeriodicalExecuter(function(pe) {
      album.cycle();
      pe.stop();
    }, 4)
  }
} 

//window.onload = album.initialize
document.observe('dom:loaded', function() {
  album.initialize();
});