/* function for retreiving all z-index attributes from a set of jquery elements
 - used when relayering */
function get_all_zindices(elements)
{
	var indices = [];
	elements.each(function(i){
		indices[i] = parseInt( $(this).css('z-index') );					
	});
	return indices;
}

/* sort an array */
function highest_to_lowest(a,b) {
  return b - a;
}



$(document).ready(function(){

	var closebutton = '<a href="#" class="close" title="Close this dialogue box">Close dialogue</a>';
	// modal window for login form
	$('#loginLink').click(function() { 
		$.blockUI({ 
			message: $('#loginForm'),
			css: { width: '300px' }
		}); 
		$('.blockOverlay').attr('title','Click to unblock').click($.unblockUI); 
		return false;
	}); 
	// modal window for subscribe form
	$('#subscribeLink').click(function() { 
		$.blockUI({ 
			message: $('#subscribeForm'), 
			css: { width: '300px' }
		}); 
		$('.blockOverlay').attr('title','Click to unblock').click($.unblockUI); 
		return false;
	}); 
	// hide both modal dialogue boxes
	$('#subscribeForm, #loginForm').prepend(closebutton).hide();
	$('.close').click(function(){
		$.unblockUI();
		return false;
	});
	
	// if theres a login problem, show the modal
	var errors = $('.loginForm .loginMessage').text();
	if ( errors.length > 0 ) $.blockUI({ message: $('#loginForm')}); 

	// if theres a subscribe problem, or a successful subscribe, show the modal
	var msg = $('#subscribeForm .error, #subscribeForm .success').text();
	if (msg.indexOf('subscribed') != -1) { $('#subscribeForm form').hide(); } // hide subscribe form if success message appears
	if ( msg.length > 0 ) $.blockUI({ message: $('#subscribeForm')}); 

	// smooth text colour transitions on menu hover
	var navOffCol = $('nav a').css('color');
	var navOnCol = '#ffffff';
	var navTransitSpeed = 350;
	$('nav a').hover(
		function(){ $(this).stop().css('color',navOffCol).animate({"color": navOnCol}, navTransitSpeed); },
		function(){ $(this).stop().css('color',navOnCol).animate({"color": navOffCol}, navTransitSpeed); }
	)


});


