(function($) {
	$(document).ready(function() {
		
		function innerlinks() {
			
			$('#courses_sidenav ul li a').each(function () {
				var $this = $(this),
				target = $this.attr('href');
				
				$this.click(function() {
					$('#content').animate({ 'opacity' : 0.2 }, 500, function () {
						$('#content').load(target + ' #content', function () {
							$('#content').animate({ 'opacity' : 1 }, 500);
						});
					})
					return false;
				});
			});

		}
		innerlinks();
		
		function ajaxlinks() {
			$('#next_arrow, #prev_arrow').parent().click(function () {
				var $this = $(this),
					$nav_container = $("#courses_sidenav"),
					url = $this.attr('href');
				
				$nav_container.animate({ 'opacity' : 0.2 }, 500, function () {
					$nav_container.load(url + ' #courses_sidenav', function () {
						$nav_container.animate({ 'opacity' : 1 }, 500);
						ajaxlinks();
						innerlinks();
					});
				});
				return false;
			});
		}
		ajaxlinks();
		
				
		$('.external').click(function() {
			$(this).attr('target', '_blank');
		});
		
		var on = false,
			pm = $("#plus_minus");
			 
		pm.click(function() {
			if(!on) {
				$('#shortcuts').slideDown();
				pm.css( 'background-position', '0 -16px' );
				on = true;
			} else {
				$('#shortcuts').slideUp();
				pm.css( 'background-position', '0 0' );
				on = false;
			}
			
		});	
		
		$('#e_learning, #course_calendar').css('opacity', 0.7).hover(function() { 
			$(this).stop().animate({ opacity: 1 },300);
		 }, function() { 
		 	$(this).stop().animate({ opacity: 0.7 },300)
		  });
		
	}); // end $
	/*

	function resize_think_safety () 
	{
		var ww = $(window).width();
		if (ww < 1424 && ww > 1254) {
			$('#think_safety').attr('src', 'http://localhost:8888/cict2/wp-content/themes/cict/img/think-safety-smaller.png').css('display', 'block');
		}
		else if (ww < 1254) {
			$('#think_safety').css('display', 'none');
		} 
		else if (ww >= 1424); {
			$('#think_safety').attr('src', 'http://localhost:8888/cict2/wp-content/themes/cict/img/think-safety-cict.png').css('display', 'block');
		}	
	}
	
	resize_think_safety();
*/
		
	
	$(window).resize(function() {
	
		var wh = $(window).height(),
			space = wh - 106 - 50 - 42 - 300;
		
		if (wh > 350) {
			$("#contact_canvas").css({
				'margin-top' : (space/2) + 'px'
			});
		}
		else {
			$("#contact_canvas").css({
				'margin-top' : '20px'
			});
		}
				
		resize_think_safety();
	
	}).load(function() {
		
		var wh = $(window).height(),
			space = wh - 106 - 50 - 42 - 300;
		
		if (wh > 350) {
			$("#contact_canvas").css({
				'margin-top' : (space/2) + 'px'
			});
		}
	
	});
	
})(jQuery); // end function($)
