/*
 * Javascript for the handling of the gallery
 *
 */

var hm;            /* History manager */

var qsParm = new Array();

/* Parsing the variable from the current URL */

function qs()
{
   var query = window.location.search.substring(1);
   var parms = query.split('&');
   for (var i=0; i<parms.length; i++)
   {
      var pos = parms[i].indexOf('=');
      if (pos > 0)
      {
      var key = parms[i].substring(0,pos);
      var val = parms[i].substring(pos+1);
      qsParm[key] = val;
      }
   }
};

/* We shouldn't need to do this, getStyle should suffice.  However the inclusion of ShadowBox breaks this feature under IE
   for some strange reason. */
   
function getOpacity(el)
{
   if (Window.ie)
      return el.filters.alpha.opacity / 100;
   else
      return el.getStyle("opacity").toFloat();
}

/* Initialise the gallery selector */

function initGallerySelectors() 
{
	var szNormal = 30, szSmall  = 30, szFull = 150;

   var links = $$("#findme .gal a");
//   links.each(function(link, i) {
//      link.addEvent("click", function(e) {
//        var target = e.target;
//         e.preventDefault();
//         $("fadeoutoverlay").effect('opacity', {duration:250}).start(0, 1).chain(function(){Window.location = target});
//   	});
//   });
   
	gals = $$("#findme .gal");
	var galDescriptions = $$("#findme .albumDescriptionContainer");
	//var fx = new Fx.Elements(gals, {wait: false, duration: 500, transition: Fx.Transitions.Cubic.easeOut});
	
	var fxD = new Fx.Elements(galDescriptions, {wait: false, duration: 250, transition: Fx.Transitions.Cubic.easeOut});
   galDescriptions.each(function(gd, i) {
        gd.setStyle('opacity', 0);
   });
      
   /* Set up a mouse enter event to expand the current gallery and contract the others */
	gals.each(function(gal, i) {
		gal.addEvent("mouseenter", function(event) {
			var oD = {};

		   var op = getOpacity(galDescriptions[i]);   			
	      oD[i] = { opacity: [op, 0.9]
			        };
			       
			gals.each(function(other, j) {
				if(i != j) {
  					var op = getOpacity(galDescriptions[j]);
  					if (op != 0) oD[j] = { opacity: [op, 0] }; 
				}
			});
		   fxD.start(oD);
		});
	});
	
 /* Contract all the galleries when the mouse leaves */
	$("findme").addEvent("mouseleave", function(event) {
	var oD = {};
	gals.each(function(gal, i) {
			oD[i] = { opacity: [getOpacity(galDescriptions[i]), 0]
			       };
	   });
		fxD.start(oD);
	});      
};

window.addEvent('load', function()
{
   initGallerySelectors();
});

