(function ($) {
  // VERTICALLY ALIGN FUNCTION
  $.fn.vAlign = function() {
  	return this.each(function(i){
    	var ah = $(this).height();
    	var ph = $(window).height();
    	var mh = Math.ceil((ph-ah) / 2);

    	$(this).css('margin-top', mh);
  	});
  };
})(jQuery);

$().ready(function() {
  // $('#wrapper').vAlign();

  $('#images .thumbs a').bind("click", function(e) {
    $('#mainpic').attr("src", $(this).attr("href"));

    e.preventDefault();
  });

  $('#images.grid a').hover(function() {
    var img = $(this).children("img");
    var s = img.attr("src");
    img.data("orig-src", s);
    // img.attr("src", s.replace(/-grey/, ""));
    img.attr("src", s.replace(/&grey=1/, ""));

    if ($(this).data("highlight")) {
      $('#content > ul a[data-highlight=' + $(this).data("highlight") + ']').addClass("highlight");
    }

  }, function() {
    var img = $(this).children("img");
    img.attr("src", img.data("orig-src"));

    $('#content > ul a').removeClass("highlight");

  });

  // enable slideshow
  var slideshow = $('.slideshow');

  if (slideshow) {
    slideshow.scrollable({
      circular: true,
      keyboard: false,
      speed: 800

    }).autoscroll({
      autoplay: true,
      interval: 3000,
      autopause: true

    });
  }

});
