$(document).ready(function() {

	initNav();
	
	$('#mainNav a').click(function(e) {
				
		e.preventDefault();
		
		$(this).blur();
		
		var position = Number($(this).parent().index());
		
		var target = position * 85;
		
		$('#navHighlight').animate({'left' : target}, 500, 'swing', function() {
			$(this).fadeIn();																	 
		});
		
		
		
		// now deal with the content of the main frame
		
		var thisLink = $(this).attr('rel');
		
		
		$('#mainContent').fadeOut(function() {
			
			$(this).empty();
			
			$(this).load("pageContent.php", {content: thisLink});
			
			$(this).fadeIn();
			
		});
									   
	});
	
	
	
	
	// finding mouse position when hovering over right window
	
	$(document).mousemove(function(e){
		
		var mouseX = e.pageX;
		var mouseY = e.pageY;
		
		
		$('#subNav li').each(function() {
			
			var position = $(this).position();
			
			var width = $(this).width();
			var height = $(this).height();
			
			var distLeft = Math.floor(Math.abs(position.left + (width/3) - mouseX));
			var distTop = Math.floor(Math.abs(position.top + (height/2) - mouseY));
			
			if(distLeft > distTop) {
				var distance = distLeft;
			} else {
				var distance = distTop;
			}
			
			if(distance < 60) {
				
				var fontSize = 16 + 12 - (Math.floor(distance/5) )
				
				$(this).children('a').css("font-size", fontSize);
				
			} else {
				
				$(this).children('a').css("font-size", "16px");
			}
				
			
		});
	  
   }); 
	
	
});


function initNav() {
	// add slider image and remove class 
	$('#mainNav').prepend('<img id="navHighlight" src="images/navHighlight.png" height="7" width="85" alt="" />');
	
	var current = $('#mainNav .current');
	var highlightPos = Number(current.index()) * 85;
	
	current.removeClass('current');
	
	$('#navHighlight').css({'left' : highlightPos});	
};
