link_click = 0;

$(document).ready(function() {
	//CALENDAR PAGE: Lightbox
	$("a.calendar").fancybox({
			'height'        :   610,
			'hideOnOverlayClick': false,
			'overlayOpacity':   0.8,
			'overlayShow'   :   true,
			'padding'       :   10,
			'speedIn'	    :   600, 
			'speedOut'	    :   200, 
			'transitionIn'  :   'elastic',
			'transitionOut' :   'elastic',
			'type'          :   'iframe',
			'width'         :   830
	});
	
	
	//MAIN PAGE: Show one of the slider panes at random
	var rand = Math.ceil( Math.random() * 3 );
	
	$( '.sliderContent' ).hide( tSpeed );
	
	if( rand === 1 ) {
		$( '.sliderContent:first' ).show( tSpeed );
	}
	else if ( rand === 2 ) {
		$( '.sliderContent:first' ).next().next().show( tSpeed );
	}
	else {
		$( '.sliderContent:last' ).show( tSpeed );
	}
	
	// MAIN PAGE: Allow the slider panes to toggle on click
	var tSpeed = 'slow';
	$( '.sliderHandle' ).click(function(){
		$( '.sliderContent' ).animate( {width:'hide'}, tSpeed );
		
		if( $( this ).attr('id') == 1 && $(this).next().is(':visible') )//first is clicked and visible )
		{
			$( '#2b' ).animate( {width:'show'}, tSpeed );
		}
		else if ( $( this ).attr('id') == 2 && $(this).next().is(':visible') )
		{
			$( '#1b' ).animate( {width:'show'}, tSpeed );
		}
		else if ( $( this ).attr('id') == 3 && $(this).next().is(':visible') )
		{
			$( '#2b' ).animate( {width:'show'}, tSpeed );
		}
		else if ( $( this ).next().not( ':visible' ).length !== 0 )
		{
			$( this ).next().animate( {width:'show'}, tSpeed );
		}
	});
	
	//MAIN PAGE: slideshow in slider
	$('.waf').cycle({timeout:5000});
	
	//ALL PAGES: header navbar hover over effect
	$( '#navBar ul li a' ).each( function( index, element ){
		$( element ).bind( 'mouseover', function(){
			$( '#navBar ul li a.active' ).removeClass( 'active' );
			$( element ).addClass( 'active' );
		});
		
		$( element ).bind( 'mouseout', function(){

			$( '#navBar ul li a.active' ).removeClass( 'active' );
			$( '#navBar ul li a#active' ).addClass( 'active' );
		});
	});
	
	//ABOUT PAGE: vertical accordion for about page
	$( '#school' ).next().animate( {height:'show'}, tSpeed );
	$( '#dirContainerSchool' ).animate( {height:'show'}, tSpeed );
	
	$( '.verticalAccordionSlider' ).click(function(){
		if ( link_click !== 1 )
		{
			var x = 0;
			if( $( this ).next().not( ':visible' ).length !== 0 ) {
				x = 1;
			}
			
			//Close all open sub-menus
			$( '.verticalAccordionContent' ).animate( {height:'hide'}, tSpeed );
			
			if( x === 1 ) {
				// This is what causes the sub-menu to show
				$( this ).next().animate( {height:'show'}, tSpeed );
			}
		}
		else
		{
			link_click = 0;
		}
	});
	
	
	//ABOUT PAGE: Shows the sub-menus under 'Staff' in the about page
	$( '.verticalAccordionSliderStaff' ).click(function(){
		var x = 0;
		if( $( '.verticalAccordionContentDark' ).not( ':visible' ).length !== 0 ) {
			x = 1;
		}
		
		$( '.verticalAccordionContentDark' ).animate( {height:'hide'}, tSpeed );
		$( '.verticalAccordionContent' ).animate( {height:'hide'}, tSpeed );
		
		if( x === 1 ) {
			//$( this ).next().show( tSpeed );
			$( '.verticalAccordionContentDark' ).animate( {height:'show'}, tSpeed );
		}
	});
	
	//ABOUT PAGE: Show the listings under the sub-menu's for the 'Staff' section
	$( '.verticalAccordionContentDark' ).click(function(){
		var x = 0;
		if( $( this ).next().not( ':visible' ).length !== 0 ) {
			x = 1;
		}
		
		$( '.verticalAccordionContent' ).animate( {height:'hide'}, tSpeed );
		
		if( x === 1 ) {
			//$( this ).next().show( tSpeed );
			$( this ).next().animate( {height:'show'}, tSpeed );
		}
	});
});

