function loadScripts(){
	loadFrontPage();
}


function loadFrontPage(){
	var $speed = 150;
	
	sequentFadeIn( '.section', 0, 2, {opacity:'show', marginTop:'0px'}, 500);
	
	$('.section')
		.mouseover(function(){
			$(this).animate({ marginTop: '-20px', opacity:'1.00' }, $speed)
		})
		.mouseout(function(){
			$(this).animate({ marginTop: '0px', opacity:'.70'}, $speed);
		});
	
}



function loadAboutPage(){

	aboutDetect();
	
	
	$(' ul li a').click(function(){
	
		$el = $(this).attr('href').replace('#','');
		
		
		
		$('.contact-page.selected').animate({height:'hide'},  function(){ 
			$(this).removeClass('selected');
			
			$('ul li a.selected').removeClass('selected');
							
			$('.contact-page.'+$el).animate({height:'show'},  function(){ 
				$(this).addClass('selected');
				$('a[href="#'+$el+'"]').addClass('selected');
			});
			
			
		});
		
	});
	
}

function aboutDetect(){

		var $el = window.location.hash.replace('#', '');
			
		if( window.location.hash == '#contact' || window.location.hash == '#directions'){
		


			$('.contact-page.'+$el).addClass('selected');
			$('a[href="#'+$el+'"]').addClass('selected');
			
			
		} else {

			$('.contact-page.about').addClass('selected');
			$('ul li:eq(0) a').addClass('selected');
		}
		
		$('.contact-page.'+$el+'').show();
			$('.contact-page.'+$el+'').siblings('div.contact-page').hide();

}

function loadGalleryNav(){
	if(window.location.hash != ''){
		
		var $hash = window.location.hash;

		$('ul li a#selected').attr('id','');
		$('ul li a[href="'+$hash+'"]').attr('id','selected');
		gallerySlideDetect( $hash, false );
		
	} else  {
	
		$('ul li a#selected').attr('id','');
		$('ul li a[href="#all"]').attr('id','selected');
		gallerySlideDetect( '#all', false );

	}
	
	$('ul[id!=""] li a').click(function(){
		
		$this = $(this).attr('href');
	
		$('ul li a#selected').attr('id','');
		
		$('ul li a[href="'+$this+'"]').attr('id','selected');
		
		gallerySlideDetect( $this, true );
	
		
	});
}

function gallerySlideDetect( $which, $anim ){
	
	if( $which == '#info'){
	
		if( $anim == false ){
			$('.all, .faq, .featured').hide();
			$('.info').show();
		} else {
			$('.all, .faq, .featured').animate({opacity:'hide'}, function(){
				$('.info').animate({opacity:'show'});
			});
		}
	
	}
	if( $which == '#faq'){
		
		if( $anim == false ){
			$('.all, .info, .featured').hide();
			$('.faq').show();
		} else {
			$('.all, .info, .featured').animate({opacity:'hide'}, function(){
				$('.faq').animate({opacity:'show'});
			});
		}
	
	}
	if( $which == '#all'){
	
		$('.info, .faq, .featured').animate({opacity:'hide'});
		$('.all').animate({opacity:'show'});
		
		initThumbs( $which );
		initCycle( $which );
		
	} 
	if( $which == '#featured'){
	
		$('.info, .faq, .all').animate({opacity:'hide'});
		$('.featured').animate({opacity:'show'});
		
		initThumbs( $which );
		initCycle( $which );
		
	}
					
}

function initThumbs( $which ){

	$($which.replace('#', '.') + ' * .items').html(' ');
	
	$('#gallery').unbind('cycle');
	$('#scroll').unbind('scrollable');
			
	if($which == '#featured'){
		$('.all').hide();
		$('.featured').show();
	} else  {
		$('.featured').hide();
		$('.all').show();
	}
	
}

function initCycle( $gal ){
	var $gal = $gal.replace('#','.');
	var scrollableParams = { loop : true, size:16 };
	
	if( $gal == '' ){ 
		$gal = '.all'; 
	}
			
	$($gal + ' #gallery').cycle({
		fx: 'fade', 			
		pager:  $gal + ' * .items',
		next: '.next',
		prev: '.prev',
		cleartype: true,
		cleartypeNoBg: true,
		timeout: 5000
	});
	
	$.each( $($gal).find('.items a'), function(){

		var $id = parseInt( $(this).html() );
		$img = $($gal).find('#image-'+$id).attr('src').split('/');
		$img = $img[0] + '/' + $img[1] + '/tn/' + $img[2];
		
		var $html = $('<img>').attr({
			src: $img 
		});
			
		$(this).html(' ');
			
		$(this).append( $html );
	});
	
	$("div#scroll").scrollable(scrollableParams); 

}





function sequentFadeIn( $el, $i, $max, $params, $speed) {
	if ($i <= $max) {
		$( $el+':eq('+$i+')').animate($params, $speed, function() { 
			sequentFadeIn($el, ++$i, $max, $params, $speed ) 
		});
	}
}


