// Cufon Related code
Cufon.replace('h1, h2, h3, h4, .staffOverlay p, .rabbitContent h3, .accordLeft h2, .formSuccess h3');
Cufon.replace('#crumbs .linobg', { color: '#0C0C0C' });
Cufon.replace('#crumbs a, #share a, #shareAlt a, #sortMenu a, #footerDetails, #jsddm a, .altMainTitle h6, .altMainTitle a, .altRightTitle h6, .altRightTitle a, .bookingLinks a, .programmeLinks a, .switchBookingLinks a', { hover: true });

Cufon.replace('.makeHover a', {
	hover: true
});
Cufon.replace('.content h5 a', {
	hover: true
});


//if you also wanted a drop shadow you could use the option below
Cufon.replace('.newsitem a.linkspecial', {
	color: '-linear-gradient(red, 0.7=#DB3519)', 
	hover: true, 
	textShadow: '1px 1px rgba(0, 0, 0, 0.2)' 
	});
	
	
//navigation + menu fade

$(function () {
	if ($.browser.msie && $.browser.version < 7)
		return;

	$('#navigation li')
		.removeClass('highlight')
		.find('a')
		.append('<span class="hover" />').each(function ()
		{
			var $span = $('> span.hover', this).css('opacity', 0);
			
			$(this).hover(function ()
			{
				// on hover
				$span.stop().fadeTo(400, 1);
			},
			function ()
			{
				// off hover
				$span.stop().fadeTo(1500, 0);
			});
		});
});


//Carousel Prev / Next buttons
$(function () {
	if ($.browser.msie && $.browser.version < 7)
		return;

	$('#carouselControlsB li')
		.removeClass('highlight')
		.find('a')
		.append('<span class="hover" />').each(function ()
		{
			var $span = $('> span.hover', this).css('opacity', 0);
			
			$(this).hover(function ()
			{
				// on hover
				$span.stop().fadeTo(400, 1);
			},
			function ()
			{
				// off hover
				$span.stop().fadeTo(1500, 0);
			});
		});
		
		
});





//Subscribe to the site button
$(function () {
	if ($.browser.msie && $.browser.version < 7)
		return;

	$('#subscribeLink li')
		.removeClass('highlight')
		.find('a')
		.append('<span class="hover" />').each(function ()
		{
			var $span = $('> span.hover', this).css('opacity', 0);
			
			$(this).hover(function ()
			{
				// on hover
				$span.stop().fadeTo(300, 1);
			},
			function ()
			{
				// off hover
				$span.stop().fadeTo(300, 0);
			});
		});
});


//General Fade Buttons
$(function () {
	if ($.browser.msie && $.browser.version < 7)
		return;

	$('#fadeButton li')
		.removeClass('highlight')
		.find('a')
		.append('<span class="hover" />').each(function ()
		{
			var $span = $('> span.hover', this).css('opacity', 0);
			
			$(this).hover(function ()
			{
				// on hover
				$span.stop().fadeTo(800, 1);
			},
			function ()
			{
				// off hover
				$span.stop().fadeTo(1500, 0);
			});
		});
});




//Private Hire Buttons
$(function () {
	if ($.browser.msie && $.browser.version < 7)
		return;

	$('#hireButton li')
		.removeClass('highlight')
		.find('a')
		.append('<span class="hover" />').each(function ()
		{
			var $span = $('> span.hover', this).css('opacity', 0);
			
			$(this).hover(function ()
			{
				// on hover
				$span.stop().fadeTo(800, 1);
			},
			function ()
			{
				// off hover
				$span.stop().fadeTo(1500, 0);
			});
		});
});
			
			

$(document).ready(function(){

	//$("#homeUnit").css('opacity', 0.5);

	jQuery('#sortMenu').lavaLamp({fx: 'swing', speed: 333});

	var panel = jQuery('#panel');
	var panelHeight = panel.height();
	var subForm = jQuery('#subscribeWrapper');
	var subFormHeight = subForm.height();

	panel.css("height", 0);
	subForm.css("height", 0);

	var openTimer;
	var closeTimer;

	function doOpenSubNav()
	{
		panel.stop().animate({ height:panelHeight }, 600, "easeInOutSine");
		return false;
	}
	
	function openSubNav()
	{
		window.clearTimeout(closeTimer);
		openTimer = window.setTimeout(doOpenSubNav, 150);
	}

	function doCloseSubNav()
	{
		var toClose = panel;
	
		if(subForm.height())
		{
			toClose = toClose.add(subForm);
		}
	
		toClose.stop().animate({ height:0 }, 600, "easeInOutSine");
		return false;
	}

	function closeSubNav()
	{
		window.clearTimeout(openTimer);
		closeTimer = window.setTimeout(doCloseSubNav, 600);
	}

	jQuery("#navigationContainer").hover(openSubNav, closeSubNav);
	//// ---- 
	
	

	/* Ritchie Edit */
	
	//subscribe form js
	$('a[href$=#subscribe-by-mail]').click(function(evt)
	{
		evt.preventDefault();
		
		if(subForm.height() == 0)
		{
			subForm.stop().animate({ height:subFormHeight }, 600, "easeInOutSine");
		}
		else
		{
			subForm.stop().animate({ height:0 }, 600, "easeInOutSine");
		}
	});
	
	/* Ritchie Edit End */
	
	//RABITHOLE
	//$('#rabbitHole').hide();
	// click function that shows the form and hides the trigger button
	//$("#rabbitHoleHolder").click( function() {
	//$("#rabbitHole").fadeIn({ easing: 'easeOutSine', duration:300 });
	//});
	// click function that reverses the click function above
	//$(".closeRabbit a:last").click( function() {
	//$("#rabbitHole").fadeOut({ easing: 'easeOutSine', duration: 1000 });
	//});
	
	
	// SEND TO A FRIEND
	// hide the div witht the form
        $('#sendToFriend').hide();
        if (window['showSendToFriend']) {
            $('#sendToFriend').show();
        }
			
	// click function that shows the form and hides the trigger button
	$("#sendTo").click( function() {
	$("#sendToFriend").slideDown({ easing: 'easeOutSine', duration:600 });
        $('#sendToFriend #id_name').focus();
	});
			
	// click function that reverses the click function above
	$("#sendToFriend a:last").click( function() {
	$("#sendToFriend").slideUp({ easing: 'easeOutSine', duration: 1000 });
	}); 
	
	
	// SHARE THIS CONTENT DEFAULT
	// hide the div witht the form
	$('#shareContent').hide();
			
	// click function that shows the form and hides the trigger button
	$("#shareWith").click( function() {
	$("#shareContent").slideDown({ easing: 'easeOutSine', duration:600 });
	});
			
	// click function that reverses the click function above
	$("#shareContent a:last").click( function() {
	$("#shareContent").slideUp({ easing: 'easeOutSine', duration: 1000 });
	});
	
	
	// SEARCH + WHATS ON TAGS BOX
	// hide the div witht the form
	$('#searchTags').hide();
			
	// click function that shows the form and hides the trigger button
	$(".tags").click( function() {
	$("#searchTags").slideDown({ easing: 'easeOutSine', duration:600 });
	});
			
	// click function that reverses the click function above
	$("#searchTags a:last").click( function() {
	$("#searchTags").slideUp({ easing: 'easeOutSine', duration: 1000 });
	});
	 
	
	// SHARE THIS NEWS
	// hide the div witht the form
	$('.shareContentNews').hide();
			
	// click function that shows the form and hides the trigger button
	$(".shareWithNews").click( function() {
	$(".shareContentNews").slideDown({ easing: 'easeOutSine', duration:600 });
	});
			
	// click function that reverses the click function above
	$(".shareContentNews a:last").click( function() {
	$(".shareContentNews").slideUp({ easing: 'easeOutSine', duration: 1000 });
	});
	
	//Staff Page
	
	// find the div.staff elements and hook the hover event
  	$('div.staff').hover(function() {
    // on hovering over, find the element we want to fade *up*
    var fade = $('> div.staffOverlay', this);
    
    // if the element is currently being animated (to a fadeOut)...
    if (fade.is(':animated')) {
      // ...take it's current opacity back up to 1
      fade.stop().fadeTo(250, 1);
    } else {
      // fade in quickly
      fade.fadeIn(250);
    }
  }, function () {
    // on hovering out, fade the element out
    var fade = $('> div', this);
    if (fade.is(':animated')) {
      fade.stop().fadeTo(3000, 0);
    } else {
      // fade away slowly
      fade.fadeOut(3000);
    }
  });
	
	
	
	// POST COMMENT FORM
	// hide the div witht the form
	$('#publicForm').hide();
			
	// click function that shows the form and hides the trigger button
	$("h5#commentTrigger").click( function() {
	$("#publicForm").slideDown({ easing: 'easeOutSine', duration:600 });
	});
			
	// click function that reverses the click function above
	$("#publicForm a:last").click( function() {
	$("#publicForm").slideUp({ easing: 'easeOutSine', duration: 1000 });
	});
	
	// Featured Events Box - controll the title box opacity.
	$(".featuredEventInfo h5").css('opacity', 0.6);
	$(".featuredEventInfo p").css('opacity', 0.6); 

	
/* ritchie added this section for the boxes on the home page */

	var homeBoxes = jQuery("#homeAltMain, #altRightOne, #altRightTwo");

	var overHomeBoxTimer;
	var outHomeBoxTimer;

	jQuery("#homeAltMain, #altRightOne, #altRightTwo").mouseover(function()
	{
		window.clearTimeout(outHomeBoxTimer);
		
		var activeBox = jQuery(this);
		
		overHomeBoxTimer = window.setTimeout(function()
		{
			doHomeBoxOver(activeBox);
		}, 100);
	});
	
	function doHomeBoxOver(activeBox)
	{
		homeBoxes.each(function()
		{
			if(jQuery(this).attr("id") != activeBox.attr("id"))
			{
				jQuery(this).stop().animate({opacity: .3}, 600);
				jQuery(this).find("div.altMainBookButton").stop().animate({top: 0}, 600);
			}
		});
		
		
		activeBox.stop().animate({opacity: 1}, 600);
		
		//console.log(activeBox.find("div.altMainBookButton"));
		
		activeBox.find("div.altMainBookButton").stop().animate({top: "-40px"}, 600);
	}
	
	jQuery("#homeAltMain, #altRightOne, #altRightTwo").mouseout(function()
	{
		window.clearTimeout(overHomeBoxTimer);
		
		outHomeBoxTimer = window.setTimeout(function()
		{
			doHomeBoxOut(jQuery(this));
		}, 100);
	});
	
	function doHomeBoxOut(activeBox)
	{
		
		homeBoxes.stop().animate({opacity: 1}, 600);
		homeBoxes.find("div.altMainBookButton").stop().animate({top: 0}, 600);
			
	}
	
	/* end ritchie added code for homepage boxes */
	
	/* start ritchie listing zoom code */
	jQuery("img.zoomImg").zoomHoverImage();
	/* end ritchie listing zoom code */

	/* Flash carousel code */
	setupFlashCarouselEvents();
	/* end of Flash carousel code*/
	
	// safari 3 layout fix
	jQuery(window).resize(function(){
		jQuery("#navSuperWrapper, #footer").css({width:jQuery("#wrapperSpacer").width()});
	});
	
	jQuery(window).resize();
});	

/* more Flash carousel code */

// This function finds a movie by name - crossbrowser
function getFlashMovie(movieName)
{
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	return (isIE) ? window[movieName] : document[movieName];
}

var slidesHTML = "";

// this function prepares the flash carousel html and
function setupFlashCarousel()
{
	if(typeof(slides) == "undefined")
		return;
	
	var slidesImages = [];

	for(var i = 0; i < slides.length; i++)
	{
		slidesImages.push(slides[i].path);

		slidesHTML += "<div><h3><a href="+ slides[i].link +">" + slides[i].title + "</a></h3><p>" + slides[i].date + "</p><ul id='carouselButtons'><li class='highlight'><a href="+ slides[i].link +" class='moreInformation'><span>More Info</span></a></li><li class='highlight'><a href="+ slides[i].booking +" class='bookTickets'><span>Book Tickets</span></a></li></ul></div>";

	}

	window.getImagesForCarousel = function (val)
	{	
			return slidesImages;
	}

	var flashvars = {};

	var params = {
		menu: "false",
		scale: "noScale",
		allowFullscreen: "true",
		allowScriptAccess: "always",
		bgcolor: "#0C0C0C",
		quality:"high",
		wmode:"opaque"
		};

	var attributes = {
		id:"FullpageCarousel",
		name:"FullpageCarousel"
		};

	swfobject.embedSWF(media_url + "flash/FullpageCarousel.swf", "flashCarousel", "100%", "100%", "9.0.0", "expressInstall.swf", flashvars, params, attributes);

	
}

function setupFlashCarouselEvents()
{
	if(typeof(slides) == "undefined")
		return;
	
	function callToActionscript(flash, str)
	{
		getFlashMovie(flash).sendToActionscript(str);
	}
	
	var carouselDescWidth = jQuery("#carouselDescription").width();
	var descHolder = jQuery("#carouselDescription>div");
	var carouselActive = false;

	jQuery("a#prevSlide").click(function(evt)
	{
		evt.preventDefault();
		
		if(carouselActive)
			return;
		
		carouselActive = true;
		
		callToActionscript('FullpageCarousel', 'left');
		
		descHolder.css({left:-440});
		descHolder.find(">div:first").before(descHolder.find(">div:last"));
		
		descHolder.animate({left:0}, {duration:600, complete:function()
		{
			carouselActive = false;
		}});
	});

	jQuery("a#nextSlide").click(function(evt)
	{
		evt.preventDefault();
		
		if(carouselActive)
			return;
		
		carouselActive = true;
		
		callToActionscript('FullpageCarousel', 'right');
		
		descHolder.animate({left:-carouselDescWidth}, {duration:600, complete:function()
		{
			descHolder.css({left:0});
			descHolder.find(">div:last").after(descHolder.find(">div:first"));
			
			carouselActive = false;
		}});
	});
	
	descHolder.css("width", carouselDescWidth * slides.length);
	
	descHolder.html(slidesHTML);
	
	Cufon.replace('#carouselDescription h3, #carouselDescription p');
}

function carouselImageLoaded()
{
	
}

setupFlashCarousel();
     			    

//Carousel MORE INFO + BOOK TICKETS buttons
$(function () {
	if ($.browser.msie && $.browser.version < 7)
		return;

	$('#carouselButtons li')
		.removeClass('highlight')
		.find('a')
		.append('<span class="hover" />').each(function ()
		{
			var $span = $('> span.hover', this).css('opacity', 0);
			
			$(this).hover(function ()
			{
				// on hover
				$span.stop().fadeTo(400, 1);
			},
			function ()
			{
				// off hover
				$span.stop().fadeTo(1500, 0);
			});
		});
		
		
});
