$(document).ready(function() {

// hide subnav initially
	$('#subnav').hide();

// toggle the sub nav when mouse goes in and out
	$("#exhibitions").mouseover(function(){
		$('#subnav').show();
		$("#exhibitions a").addClass("showing");
    })
    $('#exhibitions, #subnav').mouseout(function(){
		$('#subnav').hide();
		$("#exhibitions a").removeClass("showing");
  });
    
// initiate cycle plugin
	$('#slideshow, .slideshow').cycle({
	    prev:   '#prev', 
	    next:   '#next', 
	    timeout: 4000
	});
	
// toggle effect for the artist page	
	$('#images .slideshow:first').show();
	$('#artists .artist .bio').hide();
	
	$('#artists .artist h2 a').click(function() {
		$artist = $(this).parents('.artist');
		
		var i = $('#artists .artist').index( $(this).parents('.artist') );
		
		$('#images .slideshow:not(:eq(' + i + '))').slideUp();
		$('#images .slideshow:eq(' + i + ')').slideDown();

		$('#artists .artist:not(:eq(' + i + ')) .bio').slideUp();
		$artist.find('.bio').slideToggle();
		
		$('#artists').addClass('active');

		$('#artists h2 a.current').removeClass('current');
		$(this).toggleClass('current');
							
    // return false;
	})

  var artist = window.location.hash.split('/').pop();
  artist = '#' + artist.replace(/-/g,'');
  // console.log(artist);

  $(artist).trigger('click');

  $('.slide > a').click(function(){

    // $('#spinner').fadeIn();

    ImageUrl = $(this).attr('rel');

    $('<img />',{src:ImageUrl}).load(function(){


		// $('#spinner').fadeOut();

      cssBackground = "rgba(255,255,255,.67) url('" + ImageUrl + "') no-repeat center center";
      $('#gin_lane_box').css('background',cssBackground).fadeIn(400,function(){
        $('#spinner').fadeOut();
      }).click(function(){
        $(this).fadeOut();
              	        // $('#spinner').fadeOut();

      });


    });
    
    // return false;
  });

  var opts = {
    lines: 12, // The number of lines to draw
    length: 4, // The length of each line
    width: 2, // The line thickness
    radius: 4, // The radius of the inner circle
    color: '#000', // #rbg or #rrggbb
    speed: 1.1, // Rounds per second
    trail: 60, // Afterglow percentage
    shadow: false // Whether to render a shadow
  };
  var target = document.getElementById('spinner');
  var spinner = new Spinner(opts).spin(target);

});
