$(document).ready(function(){
	
	//Supressing CSS Fallback for Javascript users
	$("html").addClass("javascript-enabled");
	
	$("ul.sliding-list div").hide('fast');
	
	$("#homepage-locations li a").hover(
	  function () {
	  	$(this).children("span").animate({ 
	        height: "60"}, 200 ); 
	  },
	  function () {
	  	$(this).children("span").animate({ 
	        height: "14"}, 200 ); 
	  }
	);
	
	$("select#exhibition").change(function() {
		document.location = this.value;
	});
	
	$("li.expand a").toggle(
	  function () {
        $("#header").animate({height: "400"}, 200 );
		$('li.expand a').addClass('expanded');
		$('#header .caption').css("display","block");
      },
      function () {
        $("#header").animate({height: "200"}, 200 );
		$('li.expand a').removeClass('expanded');
		$('#header .caption').css("display","none");
      }
    );

	$('ul.sliding-list li h2 a').click(function(event){
		event.preventDefault();
		$(this).parents("li").children("div").slideToggle('fast');
		$(this).parents("li").toggleClass('open');
	});
	
	$('#slideshow').cycle({ 
	    timeout:     7000, 
	    pager:      '#nav', 
	    pagerEvent: 'mouseover', 
	    fastOnEvent: true 
	});
	
	$('.text-columns').columnize({width:318});
	
	$("a.event-booking").fancybox({
			'width': 700,
			'height': 520,
			'autoDimensions' : false
	});
	
	$("a.photo").fancybox();
	
	$("a.mailing-list").fancybox({
		'width': 730,
		'height': 600,
		'type': 'iframe',
		'autoDimensions' : false
	});
	
});

var randomHeader = function(location){
	
	var captions = new Array();
	
	captions['sarvisalo'] = new Array(
		'Sarvisalo, Finland',
		'Sarvisalo, Finland',
		'Sarvisalo, Finland'
	);
	
	captions['new-york'] = new Array(
		'1500 Broadway',
		'1500 Broadway',
		'1500 Broadway'
	);
	
	captions['collection'] = new Array(
		'Gregory Crewdson, Untitled (Forest clearing) (2006)',
		'Mark Titchner, When We Build Let Us Think That We Build Forever (2006)',
		'Daniels William, Still Life (2007)',
		'Sean Dack, Winter Snow (2007)'
	);
	
	captions['london'] = new Array(
		'176 Prince of Wales Road, London',
		'176 Prince of Wales Road, London',
		'176 Prince of Wales Road, London',
		'176 Prince of Wales Road, London'
	);
	

	
	var random = Math.floor(Math.random()*captions[location].length);
	
	var imgPath = '/assets/_images/backgrounds/'+location+'/background'+(random+1)+'.jpg';
	
	$('#header').css('background-image','url('+imgPath+')');
	$('.caption p').html(captions[location][random]);
}

