$(function(){
	
	/* Jquery Swap */
		jQuery.fn.swap = function(b) {
		    b = jQuery(b)[0];
		    var a = this[0],
		        a2 = a.cloneNode(true),
		        b2 = b.cloneNode(true),
		        stack = this;
		
		    a.parentNode.replaceChild(b2, a);
		    b.parentNode.replaceChild(a2, b);
		
		    stack[0] = a2;
		    return this.pushStack( stack );
		};

		var screen_width = window.innerWidth;

	/* Search label hide/show */
		$("#search_form input#keywords").focus(function(){
			$("#search_form label").fadeOut();
		}).blur(function() {
			if($('#search_form input#keywords').val() == "")
			{
				$('#search_form label').fadeIn();
			}
		});
		
		$("#search_form label").click(function(){
			$(this).fadeOut();
			$("#search_form input#keywords").focus();
		});
		
		$("#search_form input#keywords").blur(function() {
			if($('#search_form input#keywords').val() == "")
			{
				$('#search_form label').fadeIn();
			}
		});
		
	/* Contact form validation */
		$(".contact_form").validate();
		
	/* View Sections for smaller screens */
		$("#view_nav a").click(function(){
			$('#navigation nav').toggle('slow', function() {
			    // Animation complete.
			});
			return false;
		});
		
	/* Content Placement */
		if(screen_width <= 480)
		{
		
			$(".position_under").each(function(){
				var $this = $(this);
				var $next_element = $this.next();
			
				$(this).swap($next_element);
			});
		}
	
	/* Control the main navigation menus */
	    //$("nav ul.menu").superfish();
	    $(".menu ul").mouseover(function(){
	    	$parent = $(this).parent();
	   		$parent.css({"background-color":"#FFF"});
	    });
	    $(".menu ul").mouseout(function(){
	    	$parent = $(this).parent();
	   		$parent.css({"background-color":"#1D3143"});
	    });
		
	/* Rollover styles for left nav on subpages */
		$(".left_nav.sub li").click(function(){
			var link = $("a",$(this)).attr("href");
			window.location = link;
		});
		
	/* You are now leaving Robbins */
		
		function load_links()
		{
			/*
			$("a").each(function(){
				
				var link = $(this).attr("href");
				
				if(link != "" && link != "undefined" && link != null)
				{
				
					if(link.substring(0,4) == "http")
					{
						if(link.substring(0,15) != "http://robbinsl")
						{
							$(this).addClass("leaving");
						}
					}
				
				}
				
			});
			
			$(".leaving").click(function(){
			
				if(!confirm("You are now leaving The Robbins Library Website, continue?"))
				{
					return false;
				}
			});
			*/
		
		}
		
		load_links();
});
