var activepanel = null;

$(document).ready(function(){

	// Extra Content
	var extrastitle = $('.Extras h4');
	if(extrastitle.length > 0){
		$('.MainCollumnWrap').append('<div class="ExtraContentButton">' + extrastitle.text() + '</div>');
		extrastitle.remove();
		$('.ExtraContentButton').click(function(){
			$('.Extras').slideToggle();									
		});
		$('.Extras').hide();
	}
	
	// UK Map
	$(document).mousemove(function(e){
		if(activepanel != null){
			activepanel.css({'top': e.pageY - 155, 'left': e.pageX - 238}).show();
		}
	}); 
	$('.MapAreaBox').find('li:first').addClass('Heading');
	/* Scotland */
	$('.MapArea1').hover(function(e){
		$('.UKMap').css({'backgroundPosition': '-316px -378px'});
	});
	/* Northern Ireland */
	$('.MapArea2').hover(function(){
		$('.UKMap').css({'backgroundPosition': '-948px -378px'});
	});
	/* Midlands */
	$('.MapArea3').hover(function(){
		$('.UKMap').css({'backgroundPosition': '0px -378px'});
		activepanel = $('.MapAreaBox3');
	});
	/* South East */
	$('.MapArea4').hover(function(){
		$('.UKMap').css({'backgroundPosition': '-948px 0px'});
		activepanel = $('.MapAreaBox1');
	});
	/* South West */
	$('.MapArea5').hover(function(){
		$('.UKMap').css({'backgroundPosition': '-632px 0px'});
		activepanel = $('.MapAreaBox2');
	});
	/* North */
	$('.MapArea6').hover(function(){
		$('.UKMap').css({'backgroundPosition': '-316px 0px'});
		activepanel = $('.MapAreaBox5');
	});
	/* Wales */
	$('.MapArea7').hover(function(){
		$('.UKMap').css({'backgroundPosition': '-632px -378px'});
		activepanel = $('.MapAreaBox4');
	});
	$('area').mouseout(function(){
		$('.UKMap').css({'backgroundPosition': '0 0'});
		activepanel = null;
		$('.MapAreaBox').hide();
	});
	/* Add commas to end of each map area name */
	$('.MapAreaBox').find('li:not(:first,:last)').each(function(){
		$(this).text($(this).text() + ",");
	});
	
	// Scrolling Background
	var count = 1;
	$('.SiteBackground img').each(function(){
		$(this).addClass('Balloon' + count);
		count++;
	});
	if($('.Animation').length > 0){
		picturemove();
		balloonmove1();
		balloonmove2();
		balloonmove3();
	}
	
	// Advanced menu dropout
	$('.MainMenu ul ul').not('.MainMenu ul ul ul').makeacolumnlists({cols:2,colWidth:0,equalHeight:false,startN:1});
	$('.li_container').addClass('Dropout');
	/* Add commas to end of each third level item */
	$('.Dropout ul ul').find('li:not(:last) a').each(function(){
		$(this).text($(this).text() + ",");
	});
	
	// Testimonials Fade
	$('.Feature3 .Enhance2NewsFeedArticles').cycle({ 
		fx: 'fade', 
		speed: 1500,
		timeout: 8000,
		pause: true,
		slideExpr: '.Enhance2NewsFeedArticle'
	 });
	 
	/* Hide flash on second load only */
	var referrer = document.referrer;
	var correctreferrer = referrer.indexOf('goballooning.co.uk')
	if(correctreferrer != -1){
		$('.Home .LeftCollumn object, .Home .LeftCollumn embed').remove();
	}

});

function picturemove(){
	$('.SiteBackground').css({'backgroundPosition': '0 0'}).animate({'backgroundPosition': "-2000 0"}, 200000, 'linear', picturemove);
}

function balloonmove1(){
	$('.Balloon1').animate({'left': '-150px', 'top': '-70px'}, 7000)
	.animate({'left': '-250px', 'top': '-35px'}, 7000)
	.animate({'top': '0px'}, 7000, balloonmove1);
}

function balloonmove2(){
	$('.Balloon2').animate({'top': '30px'}, 10000)
	.animate({'left': '100px', 'top': '60px'}, 10000)
	.animate({'left': '0px', 'top': '0px'}, 5000, balloonmove2);
}

function balloonmove3(){
	$('.Balloon3').animate({'right': '-500px', 'top': '-100px'}, 30000)
	.animate({'right': '-100px'}, 30000)
	.animate({'top': '-400px'}, 10000, balloonmove3);
}
