﻿$(function () {
  /*Bind events*/
  //Mouseover
  $('#paintings h2').hover(function (e) {
    $(this).find('img.hover').stop(true, false).animate({
      opacity: 1
    }, 500);
  }, function (e) {
    $(this).find('img.hover').stop(true, false).animate({
      opacity: 0
    }, 1000);
  });
  $('#paintings h2').tooltip({
    bodyHandler: function () {
      return $(this).find('label').html();
    }
  });
  $('#pnlPaintingContainer .tooltip').css({ opacity: 0, display: 'block' });
  $('#pnlPaintingContainer').click(function () {
    this.tooltipvisible == null ? this.tooltipvisible = false : this.tooltipvisible ? this.tooltipvisible = false : this.tooltipvisible = true;
    var opacity = this.tooltipvisible ? 0 : 1;
    $(this).find('.tooltip').stop().animate({
      opacity: opacity
    });
  });
  $('#pnlPaintingContainer .prev, #pnlPaintingContainer .next').click(function (e) {
    e.stopImmediatePropagation();
  });
  //Pre-load images and inject duplicate
  $('#paintings img').each(function () {
    $('<img src="' + $(this).attr('data-hover') + '" class="hover" />').insertBefore(this);
  });
});
function showWelcomeScreen() {
  var images = [
      { image: '/images/welcome_aandeijsel.jpg' },
      { image: '/images/welcome_bolwerkmolen.jpg' },
      { image: '/images/welcome_enkhuizen.jpg' },
      { image: '/images/welcome_haven.jpg' },
      { image: '/images/welcome_marken.jpg' },
      { image: '/images/welcome_verbinding.jpg' },
      { image: '/images/welcome_welle.jpg' },
      { image: '/images/welcome_zonsondergang.jpg' },
      { image: '/images/welcome_spoorbrug.jpg' },
      { image: '/images/welcome_towers.jpg' },
      { image: '/images/welcome_trees.jpg' }
    ];

  $.shuffle(images);

  $.supersized({
    slideshow: 0,
    autoplay: 0,
    transition: 1,
    transition_speed: 100,
    performance: 0,
    vertical_center: 0,
    horizontal_center: 1,
    navigation: 0,
    thumbnail_navigation: 0,
    random: 1,
    slides: images
  });

  //Welcome
  $('#welcome .center,#supersized').click(hideWelcomeScreen);
}
//Hides the welcome screen overlay
function hideWelcomeScreen(e) {
  $('.logo,#wrapper,#footer').css({ visibility: 'visible' });
  $('#welcome .center,#welcome .footer').animate({
    opacity: 0
  }, 500, function () {
    $('#supersized').animate({
      opacity: 0
    }, 500, function () {
      $('#supersized,#welcome').css({ display: 'none' });
    });
  });
  e.preventDefault();
}
//Shuffle plugin
(function ($) {
  $.fn.shuffle = function () {
    return this.each(function () {
      var items = $(this).children();
      return (items.length)
        ? $(this).html($.shuffle(items))
        : this;
    });
  }
  $.shuffle = function (arr) {
    for (
      var j, x, i = arr.length; i;
      j = parseInt(Math.random() * i),
      x = arr[--i], arr[i] = arr[j], arr[j] = x
    );
    return arr;
  }
})(jQuery);
