$(function() {
	//remove the noJS class from topNav - to fallback nicely
	$('#topNav').removeClass('noJS');
	
	$(window).load(function(){
		$('#topNav').magicLine({
			'currentClass' : 'currentNavItem',
			'color' : '#000000',
			'height' : '8',
			'position' : 'top'
		});
	});	
	
	
	//Locations Page
	
	$('#locationsMap .region').bind('mouseenter', function() {
		var region = $(this).children('a').addClass('hoverRegion').attr('rel');
		$('#locationsHeading .headingDescription').html(region);
	    return false;
	});
	
	$('#locationsMap .region').bind('mouseleave', function() {
		$(this).children('a').removeClass('hoverRegion')
		$('#locationsHeading .headingDescription').html('Please select a region');
	    return false;  
	});
	
	$('#locationsMap a').bind('click', function(e) {
		e.preventDefault();
		if (!$('#locationPopup').is(':visible')) {
			//Make the footer disappear
			$('#footer').animate({ opacity: "hide" }, "slow");
	    
			if (typeof(noLocationFade) !== 'undefined') { //force through when IE6 or 7
				return true;
			}
			
			var selectedRegion = $(this).attr('rel');
		
			$(this).addClass('selectedRegion');
			$('#locationPopup h1').html(selectedRegion);
			
			$.post(
				"/locations", { "ajaxFetchOffices": selectedRegion },
				function(officeHTML){
					$('#loadingIcon').slideUp();
					$('#ajaxLoadContent').append(officeHTML).slideDown();
				}	
			);
			
			$('#locationsHeading').fadeOut();
			$('#locationPopup').fadeIn();
		}
	});
	
	
	$('#closePopup').bind('click', function() {
		if (typeof(noLocationFade) !== 'undefined') { //force through when IE6 or 7
			return true;
		}
		$('.selectedRegion').removeClass('selectedRegion');
		$('#ajaxLoadContent').slideUp(function() {
			$(this).empty();
		});
		$('#locationsHeading').fadeIn();
		$('#locationPopup').fadeOut(function() {
			$('#loadingIcon').show();
		});
		
		$('#footer:hidden').animate({ opacity: "show" }, "slow");
		return false;
	});




	
	//lightBox imageView
	$("a[rel^='lightbox']").lightBox({
		imageLoading: '/img/lightbox/lightbox-ico-loading.gif',
		imageBtnClose: '/img/lightbox/lightbox-btn-close.gif',
		imageBtnPrev: '/img/lightbox/lightbox-btn-prev.gif',
		imageBtnNext: '/img/lightbox/lightbox-btn-next.gif',
		imageBlank: '/img/lightbox/lightbox-blank.gif'
	});
	
	
	//Slide animation for news item on the home page
	$('#newsPanel').hide();
	$('#container').ready(function() {
	
    $('#newsPanel').slideDown('slow', function() {
    	//Animation complete.
    });
});
    //Slide animation for news item on the news page
	$('#newsSlider').hide();
	$('#container').ready(function() {
	
    $('#newsSlider').slideDown('slow', function() {
    	//Animation complete.
    });
});

});
