$(function() {
  $('a.small_image').mouseover(function() {
    var source = this.href;
    var med = source.replace(/\/l\//, '/m/');
    var med_img = $('a.medium_image', $(this).parent().parent());
    med_img.get(0).href = source;
    med_img.css('background-image', 'url('+med+')');
  });
  $('a.enlarge_image').click(function() {
    $('a.small_image:first', $(this).parent()).click();
    this.blur();
  });
  $('a.medium_image').bind('click', function(event) {
    var source = this.href;
    $('a.small_image', $(this).parent()).each(function() {
      if(this.href == source) $(this).click();
    })
    this.blur();
    return false;
  });
  $('div.viewer').serialScroll({
		items: 'li',
		axis: 'x',
		prev: 'div#body div.hero a.prev',
		next: 'div#body div.hero a.next',
		navigation: 'div#body div.hero div.navigator a.nav',
		duration: 200,
		force: true,
		onBefore: function(e, elem, $pane, $items, pos) {
			$($('div#body div.hero div.navigator a.nav').removeClass('active').get(pos)).addClass('active');
		}
  });
  $('div#body div.hero a.arrow').click(function() { this.blur(); })
  $('div#body div.hero div.navigator a.nav').click(function() { this.blur(); })
});