$(document).ready(function(){

var sectionsArray = ["home","dirs","contacts","about","carea"];
//THIS ARRAY MUST MATCH THE ARRAY WITH SAME NAME IN BASIC_PAGE.PHP


//------------------------------------------------------------------------------------------------//
//define var for currentSection
var currentURL = location.pathname.substring(1); //get URL of current page
var lastSlashPos = currentURL.lastIndexOf('/'); //determine location of last slash - filename start
var lastDotPos = currentURL.lastIndexOf('.') //determine location of last dot - filename extension start
var currentSection = currentURL.slice(lastSlashPos+1,lastDotPos); //extract just filename without ext == section name

//alert(currentSection);
//------------------------------------------------------------------------------------------------//

//------------------------------------------------------------------------------------------------//
//POSITIONING OF WHOLE SITE AS RELATIVE TO VIEWPORT SIZE
if(currentSection.lastIndexOf('client_area') == -1){ //if we are not in the client area

	$('body').css({
		
		'overflow-y':'hidden',
		'overflow-x':'hidden'
		
	}); //end $('body').css
	
	
	function onm_basecamp_position(){
	
		var windowHeight = $(window).height();
		var windowWidth = $(window).width();
		//MAKE SURE THIS IS CONSISTENT WITH THE CSS STYLESHEET FOR THIS ITEM
		var basecampHeight = 1092; //$('#basecamp_main_div').height();
		var basecampWidth = 1600; //$('#basecamp_main_div').width();
		
		var heightDifference = windowHeight - basecampHeight;
		var widthDifference = windowWidth - basecampWidth;
		
		var bottomPosition;
		var leftPosition;
		
		var basePositionOffset = -260;
		
		var positionlimitDoubled = basePositionOffset * 2;
		
		if (heightDifference >= 0){
			bottomPosition = 0;
		}; //end if (heightDifference >= 0)
		
		if (heightDifference < 0){
		
			if(heightDifference < positionlimitDoubled){ //if else formula would cut content from viewframe
				
				bottomPosition = basePositionOffset;
			
			}
			
			else {
				
				bottomPosition = heightDifference/2;
			
			}; //end if(heightDifference < positionlimitDoubled)
			
			
		}; //end if (heightDifference >= 0)
		

		if (widthDifference >= 0){
		
			leftPosition = (windowWidth-basecampWidth)/2;
		
		}; //end if (widthDifference >= 0)
		
		
		if (widthDifference < 0){
		
			if(widthDifference < positionlimitDoubled){//if else formula would cut content from viewframe
			
				leftPosition = basePositionOffset;
			
			}
			
			else {
			
				leftPosition = (windowWidth-basecampWidth)/2;
			
			}; //end if(widthDifference < positionlimitDoubled)
						
		}; //end if (widthDifference >= 0)		
		
		
		
		
		
		$('#basecamp_main_div').css({
			
			'bottom':bottomPosition,
			'left':leftPosition
		
		}); //end $('#basecamp_main_div').css
	
	
	}; //end function onm_basecamp_position()
	
	onm_basecamp_position();
	
	
	$(window).resize(function() {
	  onm_basecamp_position();
	});

}; //end if(currentSection.lastIndexOf('client_area') == -1)
//------------------------------------------------------------------------------------------------//

//------------------------------------------------------------------------------------------------//
/*
function onm_remove_intro(){
	
	
	
	$('#skip_intro_div').hide();
	$('#basecamp_intro_div_video').hide();
	$('#video_mask_upper').hide();
	$('#video_mask_lower').hide();
	$('#basecamp_intro_div').fadeOut(3000);
	
}; //end function onm_remove_intro()

function onm_add_event_listener(object, event, handlerfunction, capture_bool){

        if ( document.addEventListener )
            {object.addEventListener(event, handlerfunction, capture_bool)}
        else
            // IE
            {object.attachEvent('on' + event, handlerfunction)};
            
}; //end function onm_add_event_listener(object, event, handlerfunction, capture_bool)


var listener_object = $('#intro_movie_obj').get(0);

if (!listener_object){
	
	listener_object = $('#intro_movie_embed').get(0);

}; //end if (!listener_object)

onm_add_event_listener(listener_object, 'qt_ended', onm_remove_intro, false);

$('#skip_intro_div').click(function() {
	
	onm_remove_intro();

});

*/
//------------------------------------------------------------------------------------------------//

//------------------------------------------------------------------------------------------------//
if($('#carea_link').attr('target') == 'blank'){ //if we are coming back to the site from the carea link generation forms
	
	//$('#skip_intro_div').hide();
	//$('#basecamp_intro_div_video').hide();
	//$('#video_mask_upper').hide();
	//$('#video_mask_lower').hide();
	$('#basecamp_intro_div').hide();
	
}; //end if($('#carea_link').attr('target') == 'blank')
//alert("the client area link target is " + $('#carea_link').attr('target'));
if($('#carea_link').attr('target') != 'blank'){ //if we are not coming back to the site from the carea link generation form

//"basecamp_night.jpg","logo_large.gif", //taken out of image array

	var image_path_array = ["basecamp_intro.jpg","basecamp_front_snow.gif","basecamp_bg.jpg","basecamp_about_normal.gif","basecamp_carea_normal.gif", "basecamp_contacts_normal.gif", "basecamp_dirs_normal.gif", "basecamp_home_normal.gif", "basecamp_shadow.gif", "ice_window.gif"];
	
	for(var i = 0; i < image_path_array.length; i++){
		
		image_path_array[i] = 'images/'+ image_path_array[i];
		//alert(image_path_array[i]);
		
	}; //end for(var i = 0; i < image_path_array.length; i++)
	
	
	function onm_preload_image(path){
		
		//alert(path);
		var image = new Image();
		
		image.src = path;
		
		//alert(image);
		return image;
	
	}; //end onm_preload_images(image_path_array, currentIndex, lastIndex)
	
	var image0 = new Image();
	
	image0.src = image_path_array[0];
	//alert(image0.src);
	image0.onload = function() {
		
		//alert('image 0 loaded');
		var image1 = onm_preload_image(image_path_array[1]);
	
		
		image1.onload = function() {
			
			//alert('image 1 loaded');
			var image2 = onm_preload_image(image_path_array[2]);
	
			image2.onload = function() {
				
				//alert('image 2 loaded');
				var image3 = onm_preload_image(image_path_array[3]);
	
				image3.onload = function() {
					
					image4 = onm_preload_image(image_path_array[4]);
	
					image4.onload = function() {
						
						image5 = onm_preload_image(image_path_array[5]);
	
						image5.onload = function() {
							
							image6 = onm_preload_image(image_path_array[6]);
	
							image6.onload = function() {
								
								image7 = onm_preload_image(image_path_array[7]);
	
								image7.onload = function() {
									
									image8 = onm_preload_image(image_path_array[8]);
	
									
									
									image8.onload = function() {
									
									//alert('Image 8 loaded!');
										
										image9 = onm_preload_image(image_path_array[9]);
										
										
	
										
										image9.onload = function() {
											
											$('#basecamp_intro').fadeOut(4000);	
											
											/*
											image10 = onm_preload_image(image_path_array[10]);
	
											image10.onload = function() {
												
												$('#fire_logo').fadeOut();
												$('#basecamp_night').fadeOut(4000);		
											
											}; //end image10.onLoad = function()			
										*/
										}; //end image9.onLoad = function()
												
									
									}; //end image8.onLoad = function()
									
												
													
								}; //end image7.onLoad = function()			
							
							}; //end image6.onLoad = function()			
						
						}; //end image5.onLoad = function()			
					
					}; //end image4.onLoad = function()			
				
				}; //end image3.onLoad = function()	
						
			
			}; //end image2.onLoad = function()			
		
		}; //end image1.onLoad = function()	
		
	
	}; //end image0.onLoad = function()
	
	//var currentIndex = 0;
	
}; //end if($('#carea_link').attr('target') != 'blank')

//SET UP INITIAL CONDITIONS ON ALL PAGES
$('#section_name_div img').hide();
$('.page_content_inner').hide();
$('#x_button').hide();
$('#x_light').hide();
$('#sound_player').hide();
//------------------------------------------------------------------------------------------------//


//------------------------------------------------------------------------------------------------//
//NAVIGATION STUMP TABLE CODE

//***NOTE***
//IN ORDER FOR STUMP IMAGES TO HAVE NO BORDER OR PADDING, THEY MUST BE DISPLAYED AS BLOCK
//THUS WE ARE REPLACING THE .show(); FUNCTION WITH 
/*
.css({
	
		'display':'block'
		
}); //show
*/
//***NOTE***

$('.nav_image_anim').hide();
$('.nav_image_light').hide();

var oldActiveSection = 'none';
var activeSection = 'index';
var icingState = 'down';

if($('#carea_link').attr('target') == 'blank'){

	//SET UP INITIAL CONDITIONS RETURNING TO CLIENT AREA AFTER PASSWORD SUBMISSION REFRESH
	
	$('#fire_logo').hide();
	$('#basecamp_night').hide();
	$('#icing_div').animate({
			    bottom: 300},
			     100); //end $('#icing_div').animate	
	$('#icing_div').fadeTo( 100, 0.7);
	$('#x_button').fadeTo(100, 1);
	$('#sound_player').fadeTo(100, 1);
	
	$('#carea_title_image').fadeTo(100, 1);
	$('#carea_section_content').fadeTo(100, 1);
	
	$('#basecamp_carea_image_normal').hide();
				
	$('#basecamp_carea_image_anim').css({
	
	    	'display':'block'
	    	
	}); //show
	
	icingState = 'up';
	activeSection = 'carea';
}; //end if($('#carea_link').attr('target') != 'carea_link')

//STUMP MOUSEOVER AND MOUSEOUT TRANSITIONS
$('#basecamp_stub_table img').mouseover(function(event){ //selector must define event handler on elements existing at document load, event object passes the image mouse event is triggered on
		
		//alert(activeSection);
		
		var target = $(event.target);
		
		if(target.attr('src') != undefined && 
			target.attr('src').lastIndexOf('light') == -1 && 
			target.attr('src').lastIndexOf('anim') == -1){ 	  //for images in normal state		
			
			var imagePath = target.attr('src'); //get image file path
			var sectionNameStart = imagePath.lastIndexOf('/basecamp_')+10; //terget section start
			var sectionNameEnd = imagePath.lastIndexOf('_') //determine location of last dot - filename extension start
			var targetSection = imagePath.slice(sectionNameStart,sectionNameEnd); //extract just filename without ext == section name

			if(targetSection != activeSection){
			
				var newImageID = '#basecamp_' + targetSection + '_image_light';
				
				var oldImageID = '#basecamp_' + targetSection + '_image_normal';
				
				$(oldImageID).hide();
				
				$(newImageID).css({
				
						'display':'block'
						
				}); //show
			
			}; //end if(targetSection != activeSection)
			
		}; //end if(target.attr('src') != undefined && 
			//target.attr('src').lastIndexOf('shadow') == -1 && 
			//target.attr('src').lastIndexOf('anim') == -1){
			
		
		
});//end $('.stump_inner img').mouseover(function(event)

$('#basecamp_stub_table img').mouseout(function(event){ //selector must define event handler on elements existing at document load, event object passes the image mouse event is triggered on
		
		//alert(activeSection);
		
		var target = $(event.target);
		
		//alert('mouseout' + target.attr('id'));
		
		if(target.attr('src') != undefined &&
			target.attr('src').lastIndexOf('normal') == -1 &&
			target.attr('src').lastIndexOf('anim') == -1){ 	  //for images in light state	
			
			var imagePath = target.attr('src'); //get image file path
			var sectionNameStart = imagePath.lastIndexOf('/basecamp_')+10; //terget section start
			var sectionNameEnd = imagePath.lastIndexOf('_') //determine location of last dot - filename extension start
			var targetSection = imagePath.slice(sectionNameStart,sectionNameEnd); //extract just filename without ext == section name
			
			if(targetSection != activeSection){
			
				var newImageID = '#basecamp_' + targetSection + '_image_normal';
				
				var oldImageID = '#basecamp_' + targetSection + '_image_light';
				
				
				$(oldImageID).hide();
				$(newImageID).css({
				
						'display':'block'
						
				}); //show
			
			}; //end if(targetSection != activeSection)
			
		}; //end if(target.attr('src') != undefined && 
			//target.attr('src').lastIndexOf('shadow') == -1 && 
			//target.attr('src').lastIndexOf('anim') == -1){
			
		
		
});//end $('.stump_inner img').mouseover(function(event)
//END STUMP MOUSEOVER AND MOUSEOUT TRANSITIONS

//CONTENT SWAPPING AND TRANSITION CODE
$('#basecamp_stub_table img').click(function(event){ 

	var target = $(event.target);
	
	if(target.attr('src') != undefined &&
		
		target.attr('src').lastIndexOf('anim') == -1){ 	  //for images not currently active
		
		var imagePath = target.attr('src'); //get image file path
		var sectionNameStart = imagePath.lastIndexOf('/basecamp_')+10; //target section start
		var sectionNameEnd = imagePath.lastIndexOf('_') //determine location of last dot - filename extension start
		var targetSection = imagePath.slice(sectionNameStart,sectionNameEnd); //extract just filename without ext == section name
		
		oldActiveSection = activeSection;
		activeSection = targetSection;
		
		//NAVIGATION IMAGE SWAPPING CODE
		for(var i = 0; i < sectionsArray.length; i++){ //make sure that all images are at default state before highlighting active link
		
			var lightImageID = '#basecamp_' + sectionsArray[i] + '_image_light';//highlighted images
			var animImageID = '#basecamp_' + sectionsArray[i] + '_image_anim';//animated images
			var normalImageID = '#basecamp_' + sectionsArray[i] + '_image_normal';//normal images
			
			$(lightImageID).hide();//hide all highlighted images
			$(animImageID).hide();//hide all animated images
			
			if(sectionsArray[i] != activeSection){ //excluding the one we are about to hide
			
				$(normalImageID).css({
				
				    	'display':'block'
				    	
				}); //show all normal images
			
			}; //end if(sectionsArray[i] != activeSection)
			
		}; //end for(var i = 0; i < sectionsArray.length; i++)
		
		

		
		var newImageID = '#basecamp_' + targetSection + '_image_anim';
		
		var oldImageID = '#basecamp_' + targetSection + '_image_normal';
		

		$(oldImageID).hide();
		$(newImageID).css({
	
		    	'display':'block'
		    	
		}); //show
		//END NAVIGATION IMAGE SWAPPING CODE
		
		var oldActiveContentTitle = '#' + oldActiveSection + '_title_image';
		var oldActiveContentDiv = '#' + oldActiveSection + '_section_content';		
		
		var activeContentTitle = '#' + targetSection + '_title_image';
		var activeContentDiv = '#' + targetSection + '_section_content';
		
		//PAGE CONTENT SWAPPING CODE
		if(icingState == 'down'){//if the icing has been hidden or we are on the first page
		
			$('#icing_div').animate({
			    bottom: 300},
			     1200,
			     
			      function() {// make contents visible
			      	
			      	icingState = 'up';
			      	
			    	$('#icing_div').fadeTo( 1200, 0.7);
			    	$('#x_button').fadeTo(1200, 1);
			    	$('#sound_player').fadeTo(1200, 1);
			    	$(activeContentTitle).fadeTo(1200, 1);
					$(activeContentDiv).fadeTo(1200, 1);
					
			    	
			}); //end $('#icing_div').animate
			
		
		}; //end if(icingState == 'down')
		
		if(icingState == 'up'){ //if the icing is up
			
			$('#x_button').fadeOut(600);
			$('#sound_player').fadeOut(600);
			$(oldActiveContentTitle).fadeOut(600);
			$(oldActiveContentDiv).fadeOut(600, function(){
			
				$('#icing_div').fadeTo( 1000, 1, function(){
				
					$('#icing_div').fadeTo( 400, 0.7); //end $('#icing_div').fadeTo
					
					$('#x_button').fadeTo(400, 1);
					$('#sound_player').fadeTo(400, 1);
					$(activeContentTitle).fadeTo(400, 1);
					$(activeContentDiv).fadeTo(400, 1);
					
				}); //end $('#icing_div').fadeTo
			
			}); //end $(oldActiveContentDiv).fadeOut
			      	
			
		
		}; //end if(icingState == 'down')
		
		//END PAGE CONTENT SWAPPING CODE
			
	}; //end if(target.attr('src') != undefined && 
	    //target.attr('src').lastIndexOf('shadow') == -1 && 
	    //target.attr('src').lastIndexOf('anim') == -1){

});//end $('#basecamp_stub_table img').click(function(event)

$('#x_dark').mouseover(function(event){
	
	$('#x_dark').hide();
	$('#x_light').show();

}); //end $('#x_dark').mouseover(function(event)

$('#x_light').mouseout(function(event){
	
	$('#x_dark').show();
	$('#x_light').hide();
	
}); //end $('#x_light').mouseout(function(event)


$('#x_button').click(function(event){ 
	
	var activeContentTitle = '#' + activeSection + '_title_image';
	var activeContentDiv = '#' + activeSection + '_section_content';
	
	$('#icing_div').fadeTo( 600, 1);
	$('#x_button').fadeOut(600);
	$('#sound_player').fadeOut(600);
	$(activeContentTitle).fadeOut(600);
	$(activeContentDiv).fadeOut(600, function(){

		$('#icing_div').animate({
				    bottom: -300},
				     1200,
				     
		      function() {// make contents invisible
		      	
		      	icingState = 'down';
		      	
		 }); //end $('#icing_div').animate	
	
	});
	
	
}); //end $('#x_button').click(function(event)
//END CONTENT SWAPPING AND TRANSITION CODE
//------------------------------------------------------------------------------------------------//

//------------------------------------------------------------------------------------------------//
$('#sound_player').click(function(event){ 
	
	var target = $(event.target);
	
	var sound_on_html = '<embed id="sound_player_sound" src="sound/wind.mp3" loop="true" autostart="true" hidden="true" />';
	var sound_off_html = '';
	
	var current_html = target.html();
	
	//alert(current_html);
	
	//$('#sound_player_sound').fadeTo( 600, 1);
	
	if(current_html.lastIndexOf('sound on') == -1){ //if the sound is on
			
		target.html('sound on');
		$('#sound_player_sound_div').html(sound_off_html);		
		
	}; //end if(current_html.lastIndexOf('sound off') == -1)
	
	if(current_html.lastIndexOf('sound off') == -1){ //if the sound is on
			
		target.html('sound off');		
		$('#sound_player_sound_div').html(sound_on_html);	
		
	}; //end if(current_html == sound_off_html)
	
}); //end $('#x_button').click(function(event)
//------------------------------------------------------------------------------------------------//

//------------------------------------------------------------------------------------------------//
//ABOUT PAGE CODE
$('#about_list li').mouseover(function(event){
	
	var target = $(event.target);
	
	if(target.attr('id').lastIndexOf('_li') != -1){ //if this is a _li element and not spans within
	
		$(event.target).addClass('about_highlight');
		
	};//end if(target.attr('id').lastIndexOf('_li') != -1)
		
});//end $('#about_list li').mouseover

$('#about_list li').mouseout(function(event){
	
	var currentClass = $(event.target).attr('class');
	//alert(currentClass);
	if(currentClass.lastIndexOf('active_li') == -1){
	
		$(event.target).removeClass('about_highlight');
		
	}; //end if(currentClass.lastIndexOf('active_li') == -1)
		
});//end $('#about_list li').mouseout

//set up initial conditions
$('.about_divs').hide();
$('#about_pepper_li').addClass('active_li');
$('#about_pepper_li').addClass('about_highlight');


$('#about_pepper_div').show();
//end set up initial conditions


$('#about_list li').click(function(event){
	
	var target = $(event.target);
	
		 
		
	var tergetID = target.attr('id'); //get ID
	
	//alert(tergetID);
	if(target.attr('id').lastIndexOf('_li') != -1){ //if this is a _li element and not spans within
	
		var sectionNameStart = tergetID.lastIndexOf('about_')+6; //target section start
		var sectionNameEnd = tergetID.lastIndexOf('_li'); //determine location of last dot - filename extension start
		var targetSection = tergetID.slice(sectionNameStart,sectionNameEnd); //extract just filename without ext == section name
		
		var targetLi = '#about_'+ targetSection +'_li';
		var targetDiv = '#about_'+ targetSection +'_div';
		
		$('.active_li').removeClass('about_highlight');
		$('.active_li').removeClass('active_li'); 
		
		
		$(targetLi).addClass('active_li');
		$(targetLi).addClass('about_highlight');
		
		$('.about_divs').hide();
		$(targetDiv).show();
	
	};//end if(target.attr('id').lastIndexOf('_li') != -1)
		
});//end $('#about_list li').click(function(event)

//------------------------------------------------------------------------------------------------//

//------------------------------------------------------------------------------------------------//
//ACTIVATE MUSIC PLAYER
/*
$('#music_player img').click(function(event){ //event object passes the object mouse event is triggered on

		var target = $(event.target);
		
		//var trackName = target.attr('id'); //id of image
		var imageID = target.attr('id'); //id of image
		
		lastUnscor = imageID.lastIndexOf('_'); //determine location of last underscore - _s.jpg start
		
		uniqueAudioID = imageID.slice(lastUnscor+1);
		
		var imageSrc = target.attr('src'); //src of image
		
		//alert(imageSrc == 'images/play.jpg');
		
		var musicPlayerHtml;
		
		//var imageState;
		
		if(imageSrc == 'images/play.jpg'){ //if play button is available == nothing is playing on that track...
			
			//alert('if code is running...');
			$('#music_player span').css({
			
				'color':'#fae6c3'
			
			}); //end $('#music_player img').css
		
		
			
			
			$('#track_title_' + uniqueAudioID).css({
			
				'color':'#666666'
			
			}); //end $('#music_player img').css
			
			//'<audio id="html5_player" src="tracks/' + trackName + '.mp3" controls="controls" autoplay="autoplay"></audio>'
			
			
			
			if($.browser.webkit){
			
      			musicPlayerHtml = '<audio id="html5_player" src="retrieve_audio.php?uniqueAudioID=' + uniqueAudioID + '" controls="controls" autoplay="autoplay"></audio>';
      			
      			    			  			
  			 }else{
  			 
  			 	musicPlayerHtml = '<embed src="retrieve_audio.php?uniqueAudioID=' + uniqueAudioID + '" width=380 height=20>';
      			
   			};
			
			$('#player_container').html(musicPlayerHtml);
			
			$('.pause_button').hide();
			$('.play_button').show();
			
			$('#pause_button_' + uniqueAudioID).show();
			$('#play_button_' + uniqueAudioID).hide();
			
			//alert($('#play_button_' + uniqueAudioID).attr('src'));
			
		};//end if(imageSrc == 'images/play.jpg')
		
		if(imageSrc == 'images/pause.jpg'){ //if pause button is available == something is playing on that track...
			
			$('#music_player span').css({
			
				'color':'#fae6c3'
			
			}); //end $('#music_player img').css
		
		
			$('.pause_button').hide();
			$('.play_button').show();
			
			musicPlayerHtml = '';
			
			$('#player_container').html(musicPlayerHtml);
			
		};//end if(imageSrc == 'images/pause.jpg')
		
		
		
});//end $('#music_player img').click
*/

//------------------------------------------------------------------------------------------------//

}); //end $(document).ready
