/*
-------------------------------------------------------------------
Advent School - Site re-design -- JavaScript functions
author:   web@spacewalk.com
version:  2009.07.22
-------------------------------------------------------------------
*/

/* START JQUERY-DEPENDENT CODE */

$(document).ready(function(){


	
/* open anchors with class="new-window" in a new window, rather than using the non-validating target="_blank" */
$('a.new-window').click(function(){
	window.open(this.href);
	return false;
});

	/* SUPERFISH DROP-DOWN MENUS */
    $("ul.sf-menu").supersubs({ 
        minWidth:    6,   // minimum width of sub-menus in em units 
        maxWidth:    27,   // maximum width of sub-menus in em units 
        extraWidth:  1     // extra width can ensure lines don't sometimes turn over 
                           // due to slight rounding differences and font-family 
    }).superfish({
            delay:       500, // delay on mouseout 
			autoArrows	: false,
			dropShadows : true,
			speed: "fast"
    
    });  // call supersubs first, then superfish, so that subs are 
                     // not display:none when measuring. Call before initialising 
                     // containing tabs for same reason. 
    
    // shift rightmost menu left
	$("li.shift-1 ul").css("margin-left", "-120px");
	$("li.shift-2 ul").css("margin-left", "0");
	$("li.shift-3 ul").css("margin-left", "-150px"); /* needs 20px extra in case there's no window scroll bar */
/* 	$(".sf-menu a.top.last + ul").css("margin-left", "-160px"); */
	
	
	/* CROSS-FADE EFFECT FOR HOME PAGE BLOCKS */
	$(function() {
		// set opacity to nill on page load
		$("ul#home-blocks span").css("opacity","0");
		// on mouse over
		$("ul#home-blocks span").hover(function () {
			// animate opacity to full
			$(this).stop().animate({
				opacity: 1
			}, "slow");
		},
		// on mouse out
		function () {
			// animate opacity to nill
			$(this).stop().animate({
				opacity: 0
			}, "slow");
		});
	});
	
	
	/* SCROLL FOR NEWS PAGE SIDEBAR */
	
	// Easing equation, borrowed from jQuery easing plugin
	// http://gsgd.co.uk/sandbox/jquery/easing/
	jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	};

	$('#news-slideshow-holder').serialScroll({
/* 		target: '#news-slideshow', */
		items:'div.news-slideshow-item',
		prev:'a.prev',
		next:'a.next',
		offset: 0, //when scrolling to photo, stop 230 before reaching it (from the left)
		start:0, //as we are centering it, start at the 2nd
		duration:1000,
		force:true,
		stop:true,
		lock:false,
		cycle:true, //don't pull back once you reach the end
		easing:'easeOutQuart', //easing equation above
		jump: false //click on the images to scroll to them
	});
	
});//end document.ready

/* END JQUERY-DEPENDENT CODE */