/*
 botched-on-top of existing.
 so we fading through 3 images. 2 ims, 1 bg. 
 
 */
fade_order_ids = new Array (
	'#headerimage2',
	'#headerimage1',
	'#headerimage2',
	'#headerimage1'
)
	
fade_order_opac = new Array (
	0,
	0,
	1,
	1
)
fade_order_time = new Array(
	2000,
	4000,
	4000,
	2000
)

fade_counter = 0;

function newcycle(){
	if ($( fade_order_ids[fade_counter] + ':not(.hidden)').length) {
		$(fade_order_ids[fade_counter]).stop().animate({
			opacity: fade_order_opac[fade_counter]
		}, 1000).addClass('hidden');
	}else{
		$(fade_order_ids[fade_counter]).stop().animate({
			opacity: fade_order_opac[fade_counter]
		}, 1000).removeClass('hidden');
	}
	if (fade_counter >3){
		fade_counter = 0;
	}else{
		fade_counter ++;
	}
	repeater();
}

$(function() {
	setTimeout ("newcycle()", 4000 ); // just initialises it
});

function repeater(){
	setTimeout ("newcycle()", fade_order_time[ fade_counter] );
}



var config = {
	opacity: { 
		img: 0.3,
		text: 1,
		overlay: 0.5,
		overlay_off: 0
	},
	duration: 200
};


$(function() {
	
	// Set default opacity
	$('#activities li').css({
		cursor: 'pointer'
	});
	$('#centres div').css({
		cursor: 'pointer',
		opacity: config.opacity.img
	});
	$('#markers div').css({
		cursor: 'pointer',
		opacity: config.opacity.img
	});
	$('#overlays div').css({
		cursor: 'pointer',
		opacity: config.opacity.overlay
	});
	
	function highlight_centre(centre) {
		$('#centres .' + centre).stop().animate({ opacity: 1 }, config.duration);
		$('#markers .' + centre).stop().animate({ opacity: 1 }, config.duration);
	}
	
	function unhighlight_centre(centre) {
		$('#centres .' + centre).stop().animate({ opacity: config.opacity.img }, config.duration);
		$('#markers .' + centre).stop().animate({ opacity: config.opacity.img }, config.duration);
	}

	function highlight_activities(centre) {
		$('#overlays .' + centre).stop().animate({ opacity: config.opacity.overlay_off }, config.duration);
	}

	function unhighlight_activities(centre) {
		$('#overlays .' + centre).stop().animate({ opacity: config.opacity.overlay }, config.duration);
	}
	
	$('#markers div, #centres div').hover(function(){
		highlight_centre($(this).attr('class'));
		highlight_activities($(this).attr('class'));
	}, function() {
		unhighlight_centre($(this).attr('class'));
		unhighlight_activities($(this).attr('class'));
	});
	
	$('#activities li, #overlays div').hover(function() {
		var classes = $(this).attr('class').split(' ');
		for(var i = 0; i < classes.length; i++) {
			highlight_centre(classes[i]);
		}
		$(this).stop().animate({ opacity: config.opacity.overlay_off }, config.duration);
	}, function() {
		var classes = $(this).attr('class').split(' ');
		for(var i = 0; i < classes.length; i++) {
			unhighlight_centre(classes[i]);
		}
		$(this).stop().animate({ opacity: config.opacity.overlay}, config.duration);
	});
});














