/*********************************************************************************************************************************/
/* DOCUMENT READY CALLS **********************************************************************************************************/
/*********************************************************************************************************************************/

$(document).ready(function(){
	
	/* EXTERNAL LINKS start ***********************************************************/
	$('a[rel="external"]').click(function(){
		this.target = "_blank";
	});
	/* EXTERNAL LINKS end *************************************************************/
	
	$('html').addClass('js');
	
	/**/
	if($('#links dt a').length > 0){
		$('#links dt a').hover(
			function(){
				
				var $dt = $('dt.' + $(this).attr('rel'));
				var $dd = $('dd.' + $(this).attr('rel'));
				
				if(!$dt.hasClass('active')){
					
					$('#links dt').removeClass('active');
					$('#links dd').removeClass('active');
					
					$dt.addClass('active'); //jquery error... not sure why
					$dd.addClass('active');
				}
			}
		);
	}
	
	if($('#upcoming-events .scroll').length > 0){
		$('#upcoming-events .scroll').jScrollPane({scrollbarWidth:15, scrollbarMargin:0,showArrows:true});
	}
	if($('#page-facilities').length > 0){
		$('#page-facilities .tabs .tab h2').click(
			function(){
				
				var $handle = $(this);
				var $parent = $handle.parent();
				
				if($parent.not('.active')){
					$('#page-facilities .tabs .tab').removeClass('active');
					$parent.addClass('active');
				}		
			}
		);
	}
	/* SLIDESHOW start ***************************************************************/
	/* turned off until client supplies slideshowimages
	if( $('#slideshow span').length > 0){
		var slideshow = setInterval( "slideSwitch()", 5000 );
	}
	*/	
	if( $('#news ul li').length > 0){
		var news = setInterval( "newsRotation()", 5000 );
	}
	/* SLIDESHOW end *****************************************************************/
	
	if( $('#photos').length > 0 ){
		
		var $thumb = $('#photos .thumbs img');
		var $lg_img_parent = $('#photos > .img');
		var $lg_img = $('#photos > .img img');
		$lg_img_parent.append('<span class="l"></span>');
		var $l = $('#photos > .img .l');
		
		$thumb.click(
			function(){
				$lg_img.attr('src',$(this).attr('src'));
			}
		);
		
		$lg_img.mouseover(
			function(){
				$l.css({'display':'block'}).append('<img src="' +$lg_img.attr('src') +'" />');
			}
		).mouseout(
			function(){
				$l.children('img').remove();
			}
		);
		
		
	}
	
		
}); //close document.ready

/*********************************************************************************************************************************/
/* DOCUMENT READY FUNCTIONS ******************************************************************************************************/
/*********************************************************************************************************************************/

/* SLIDESHOW function start *********************************************************/
function slideSwitch(direction) {
	var selector = '#slideshow span';
	var $active = $(selector+'.active');

	if ( $active.length == 0 ) $active = $(selector+':first');	
	
	if(direction == 'Next' || direction == null){ var $next = $active.next('span').length ? $active.next() : $(selector+':first'); }
	else if(direction == 'Previous') { var $next = $active.prev('span').length ? $active.prev() : $(selector+':last'); }	

	$active.addClass('last-active');
	
	$next.css({opacity: 0.0})
			.addClass('active')
			.animate({opacity: 1.0}, 1000, function() {
			 $active.removeClass('active last-active');
	});
}

function newsRotation() {
	var selector = '#news ul li';
	var $active = $(selector+'.active');

	if ( $active.length == 0 ) $active = $(selector+':first');
	
	var $next = $active.next().length ? $active.next() : $(selector+':first');

	$active.addClass('last-active');
	
	$next.css({opacity: 0.0})
			.addClass('active')
			.animate({opacity: 1.0}, 600, function() {
			 $active.removeClass('active last-active');
	});
	
}
/* SLIDESHOW function end ***********************************************************/
