// JavaScript Document

jQuery(document).ready(function($) {
	
	var position = $('#footer').position();
	var posFooter = position.top;
	var winHeight = $(window).height();
	
	if(posFooter < winHeight)
	{
		var footerMargin = winHeight - posFooter - 60;
		footerMargin = footerMargin + "px";
		$('#footer').css("margin-top", footerMargin);
	}
	
	//clear search text
	$('.search-box input').val("");
	
	//cycle throghu images on homepage
	if($('.main-image-item').length > 1) {
		$('#main-image-container').cycle({ 
			fx:     'scrollHorz', 
			speed: 	 400, 
			timeout: 6000, 
			easing: 'easeInOutExpo',
			next:   '.main-arrow-right', 
			prev:   '.main-arrow-left' 
		});
	}
	
	// fade in & out scrolling image nav
	$('.main-arrow-right,.main-arrow-left')
	.mouseover(function(){
		$(this).stop().animate(
			{opacity:"1"}, 
			{duration:500})
		})
	.mouseout(function(){
		$(this).stop().animate(
			{opacity:"0.6"}, 
			{duration:500})
	});
	
	//hide search title and set focus when clicked on
	$('.search-box input,.title-search')
	.click(function(){
		$('.title-search').hide();
		$('.search-box input').focus();
	});
	
	
	//open & close venues on festival-info
	$('.venue-close').click(function() {
	  	$(this).siblings('.venue-lineup').slideUp('slow');
		$(this).hide();
		$(this).siblings('.venue-open').show();
	});
	
	$('.venue-open').click(function() {
	  	$(this).siblings('.venue-lineup').slideDown('slow');
		$(this).hide();
		$(this).siblings('.venue-close').show();
	});
	
	$('.venue-title').toggle(function() {
		$(this).siblings('.venue-lineup').slideDown('slow');
		$(this).siblings('.venue-open').hide();
		$(this).siblings('.venue-close').show();

		}, function() {
		$(this).siblings('.venue-lineup').slideUp('slow');
		$(this).siblings('.venue-close').hide();
		$(this).siblings('.venue-open').show();
	});	

	// If we're on the Manchester page, and have a hask in the URL
	// Open that venue
	var $hash = window.location.hash;
	if($hash.substring(1, 7) == 'venue-') {
		$($hash).find('.venue-title').click();
	}
});
