$(function() {
		
	$('.rollover').hover(function() {
		if (this.src.indexOf('_h.') != -1) return; // negative lookbehind no worky?
		this.src = this.src.replace(/\.(\w+)$/, '_h.$1');		
	}, function() {
		this.src = this.src.replace(/_h\.(\w+)/, '.$1');
	});

	$('.hideable').hide();
	$('.hider').click(function() {
		$('+ .hideable', this).slideToggle();
		return false;
	});
	
	$(function() {
        $('.slideshow').each(function() {
           var busy = false;
           var list = $('ul', this)[0], self = this;
           var width = list.offsetWidth, height = list.offsetHeight;
           $('.prev', this).click(function() {
               if (busy) return; busy = true;
               $('.caption', self).text($('li:first img', list).attr('alt') || '');
               $('li:first', list).css({left: -width}).remove().appendTo(list).animate({left: 0}, function() {
                   busy = false;
               });
               return false;
           });
           $('.next', this).click(function() {
               if (busy) return; busy = true;
               var newCaption = $('img', $('li:last', list).prev('li')).attr('alt') || '';
               $('.caption', self).text(newCaption);
               $('li:last', list).animate({left: -width}, function() {
                   $(this).remove().css('left', 0).prependTo(list);
                   busy = false;
               });
               return false;
           });
        });
    });

});

$(window).load(function() { $('.slideshow li img').css('display', 'block'); });

window.addHandler = function(evt, func) {
  if (typeof(window[evt]) == 'function') {
    var old = window[evt];
    window[evt] = function() { old(); func(); }
  } else {
    window[evt] = func;
  }
}