(function($) {
	$.fn.equalHeights = function(minHeight, maxHeight) {
		tallest = (minHeight) ? minHeight : 0;
		this.each(function() {
			if($(this).height() > tallest) {
				tallest = $(this).height();
			}
		});
		if((maxHeight) && tallest > maxHeight) tallest = maxHeight;
		return this.each(function() {
		//	$(this).height(tallest).css("overflow","hidden");
		});
	}
})(jQuery);

var mapsSwapBg = new Array();
mapsSwapBg['ulverston'] = '/img/map/ulverston_hover.jpg';
mapsSwapBg['barrow'] = '/img/map/barrow_hover.jpg';

var $scrollingDiv = $("#refine-search");

$(function() {
		
	$('.main_nav').superfish({
		animation: {height:'show'},
		autoArrows: false
	});
	
	$('.slider').anythingSlider({
	   	resizeContents      : false,
		enableStartStop		: false,
		autoPlay			: true
	});
	
	
	$('.ctas a').click(function(event) {
		event.stopPropagation();		
	}).each(function() {
		var $this = $(this);
		$this.closest('li').click(function() {
			document.location = $this.attr('href');	
			return false;
		});
	});
	
	$('.accordion').accordion({
		autoHeight: false
	});
	
	
//	$('img[usemap]').maphilight();

	$('area').fancybox();
	
	$('.address a').click(function(event) {
		event.stopPropagation();		
	}).each(function() {
		var $this = $(this);
		$this.closest('li').click(function() {
			document.location = $this.attr('href');	
			return false;
		});
	});

	$('.scroll').jScroll({
		top:30
	});
	
	
	var $scrollables = $('#thumbnailcarousel').scrollable({
		items: '#thumbs',
		circular: true,
		prev:'#previous',
		next:'#next'
	});

		$scrollables.each(function() {
			var $itemsToClone = $(this).scrollable().getItems().slice(1);
			var $wrap = $(this).scrollable().getItemWrap();
			var clonedClass = $(this).scrollable().getConf().clonedClass;
			$itemsToClone.each(function() {
				$(this).clone(true).appendTo($wrap)
					.addClass(clonedClass + ' hacked-' + clonedClass);
			})
		});
		
	
		
		
	$('#thumbs li a').click(function() {
		var str = $(this).attr('id');
		var thumbnail = parseInt(/thumbnail-(\d+)/.exec(str)[1], 10);
		$('#mainphoto').attr('src', images[thumbnail]);
		return false;
	});
	
	$('#thumbs').each(function() {
		var $this = $(this);
		var number = $('li',this).size();
		var width = number*140;
		return $this.width(width);
	});

});
