$(document).ready(function() {
	//appending spans to create a curve on certain elements
	$("#login h2").append("<span></span>");
	$("#search form").append("<span></span>");
	$("#intro").append("<span></span>");	
	$("#latest").append('<span id="curve-left"></span><span id="curve-right"></span>');

	//this clears out an input field defualt value on click
	$("input").focus( function() { 
		$(this).val(""); 
	});
	
	//creating a neat fade in effect for the home page image navigation
	$("#intro-nav li").hide();
	$("#intro-nav li").fadeIn("slow");
	$("#intro-nav").click(function(){return false});
	
	//fading in the log in error text
	$("p.loginError").hide();
	$("p.loginError").fadeIn("slow");
	
	//If the log in fails, display the error in the expanded box
	function get_url_param(name) {
         name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
		 var regexS = "[\\?&]"+name+"=([^&#]*)";
		 var regex = new RegExp( regexS );
		 var results = regex.exec( window.location.href );
		 if( results == null ) {
			return "";
		 } else {
			return results[1];
		 }
     }
	
	if (get_url_param('login') == "fail"){
		$("#login div.loginBox").show();
		$("#login div.expand a").text("Close");
	}
	
	//showing/hiding login box
	$("#login div.expand a").toggle( 
		function() {
			if ( $.browser.msie ) {
				$("#login div.loginBox").show();
			} else {
				$("#login div.loginBox").slideDown("slow");
			}
			$(this).text("Close");
			return false;
		},
		function() {
			if ( $.browser.msie ) {
				$("#login div.loginBox").hide();
			} else {
				$("#login div.loginBox").slideUp("slow");
			}
			$(this).text("Login");
			return false;
		}
	);
	
	//if you're logged in, you see special news and the background color gradually changes
    $("#latest li.access").animate({ backgroundColor: "#f7ecda" }, 2000);
	
	//jQuery active navigation
	$('#section a').each(function() {
	var navlink = $(this).attr("href");
	if (navlink.toLowerCase()==location.href.toLowerCase()) {
		$(this).parent("li").addClass("selected");
	}
	});
	
	//creates a smooth viewing interface for entry listings separaed by author & fixes the sub-content column height onClick
	$("body.bookstore #content-main ul.entry-listing").hide();
	$("body.bookstore h4[id]").css("cursor","pointer")
	
	$("h4#h4-lawler").click(function(){
		$("#listing-lawler").slideToggle("slow");
		$("#content-main").css("background","url(http://ceo.usc.edu/assets/images/bg-content_main.gif) no-repeat 98.5% 100px");
	});
	
	$("h4#h4-boudreau").click(function(){
		$("#listing-boudreau").slideToggle("slow");
		$("#content-main").css("background","url(http://ceo.usc.edu/assets/images/bg-content_main.gif) no-repeat 98.5% 100px");
	});
	
	$("h4#h4-conger").click(function(){
		$("#listing-conger").slideToggle("slow");
		$("#content-main").css("background","url(http://ceo.usc.edu/assets/images/bg-content_main.gif) no-repeat 98.5% 100px");
	});
	
	$("h4#h4-levenson").click(function(){
		$("#listing-levenson").slideToggle("slow");
		$("#content-main").css("background","url(http://ceo.usc.edu/assets/images/bg-content_main.gif) no-repeat 98.5% 100px");
	});
	
	$("h4#h4-mohrman").click(function(){
		$("#listing-mohrman").slideToggle("slow");
		$("#content-main").css("background","url(http://ceo.usc.edu/assets/images/bg-content_main.gif) no-repeat 98.5% 100px");
	});
	
	$("h4#h4-welbourne").click(function(){
		$("#listing-welbourne").slideToggle("slow");
		$("#content-main").css("background","url(http://ceo.usc.edu/assets/images/bg-content_main.gif) no-repeat 98.5% 100px");
	});
	
	$("h4#h4-worley").click(function(){
		$("#listing-worley").slideToggle("slow");
		$("#content-main").css("background","url(http://ceo.usc.edu/assets/images/bg-content_main.gif) no-repeat 98.5% 100px");
	});
});

// Easing equation, borrowed from jQuery easing plugin
jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
	return -c * ((t=t/d-1)*t*t*t - 1) + b;
};

//viral marketing... e-mail this page to a friend link
function mailpage(){
	mail_str = "mailto:?subject=Check out the " + document.title;
	mail_str += "&body=I thought you might be interested in the " + document.title;
	mail_str += ". You can view it at, " + location.href;
	location.href = mail_str;
}