/* NAVIGATION FUNCTIONS */

// alert('change_content.js loaded');

/* CHANGE CONTENT FUNCTION 
 *
 * SEE EXPLANATION AT BOTTOM!!
 *
*/
 

var fadeOut_speed = 300;
var fadeIn_speed = 200;  
var demo_setting = readCookie('demo');        



switch (demo_setting) {
	
	/* * * * * * * * * FANCY * * * * * * * * */
	case 'fancy': {  

        //alert('fancify');

		
		// DOCUMENT READY
		$(document).ready(function(){ 
	
			$('body:not(.ie) #main_content').css('display','none');  
				// for #gallery, fadeIn() immediately or else jcarousel fails  

		});


		// WINDOW.ONLOAD - runs after everything has downloaded
		window.onload = function(){
	
			// alert('onload function'); 

			// FADE IN CONTENT
			$('#main_content').fadeIn('300');  

			// PLAY PAGE MUSIC | BUT NOT ON RECORDINGS PAGE
			if ( (page_music_setting != 'disabled') && ( $('body').attr('id') != 'recordings' ) ) {
				page_music(); 	// footer.js    
		    }  else { 
				// alert('music disabled'); 
			}
	
		};

	

		function change_content (page_request,article_request,option1,option2) {

			var this_page = $('body').attr('id'); // find current page (using the body id)
			var this_article = $('#article>div').attr('id'); // find current article (using the id of its decendent div)
				if (article_request == null) {article_request = 'default';} // set article_request to default
			var current_stats = 'CURRENT PAGE:\n' + this_page + '/' + this_article
	
	
			// ****************************  
				// BUG: Same page, NEW content... CREATES MULTIPLE ITERATIONS OF FUNCTIONS
				// current doesn't display...
			// ****************************   
	
	
	 
		   // THE SAME PAGE ****************************************************
			if (page_request == this_page) {

				// SAME PAGE, SAME ARTICEL - NO CHANGE
				if (article_request == this_article) {
					// alert(current_stats + '\n\nNO CHANGE');
				}
				// SAME PAGE, CHANGE ARTICLE
				else {
				   	// alert(current_stats + '\n\nSAME PAGE, CHANGE ARTICLE request. loading: \n' + article_request); 
					$('#main_content').fadeOut('200',function(){
 	   			            

							// **************************** 
								//BUG: THIS IS WHERE MULTIPLE ITERATIONS HAPPENS  
							// ****************************    
					
						
							$('#article').load('_' + article_request).ajaxComplete(function(){   
							//alert('complete')
							$('#main_content').fadeIn('200');
						});  
					});
					this_article = $('#article>div').attr('id'); // BUG:        D S STHIS IS FOR 'CURRENT-' WHICH CURRENTLY DOESN'T WORK!!!!!!!  
				}
			}
	
			// A DIFFERENT PAGE  ****************************************************
			else if (this_page != page_request) {  
		
				// FADE OUT MUSIC FOR A DIFFERENT PAGE
		   		if (document.QT_page_music) {
					fadeOut_music();
					// FUNCTION DEFINED footer.js
				}              

				// 	FADE + SCROLL CONTENT
				$('#main_content').fadeOut('200');
				$.scrollTo('#wrapper','300', { 
			
					onAfter:function() {     
				
						// NEW PAGE, DEFAULT ARTICLE
						if (article_request == 'default') {
							//alert(current_stats + '\n\nNEW PAGE, DEFAULT ARTICLE request. loading: \n' + page_request + '/(default)');
							document.location.href = '/' + page_request + '/';
						}     
				
						// NEW PAGE, ARTICLE 
						else {
							//alert(current_stats + '\n\nNEW PAGE, ARTICLE request. loading: \n' + page_request + '/' + article_request);
							document.location.href = '/' + page_request + '/' + article_request;
							// document.location.href = '/' + page_request + '/' + page_request + '.php?article=' + article_request;
							// FUTURE PROJECT
							// need .htaccess rule to remove the query string.
						}     
				
		  			} // close onAfter();
			
			   }); // close scrollTo(); 		
				
			} // close else (DIFFERENT PAGE)   

		}  // close changeContent();	  
         
	} break;
		
    

	/* * * * * * * * * STRIPPED * * * * * * * * */
	default: {
		
		//alert('stripped');
		
		
		// DOCUMENT READY
		$(document).ready(function(){ 


		});


		// WINDOW.ONLOAD - runs after everything has downloaded
		window.onload = function(){

			// alert('onload function'); 



			// PLAY PAGE MUSIC | BUT NOT ON RECORDINGS PAGE
			if ( $('body').attr('id') == 'home' ) {
				page_music(); 	// footer.js    
		    }  else { 
				// alert('music disabled'); 
			}   

		};



		function change_content (page_request,article_request,option1,option2) {

			var this_page = $('body').attr('id'); // find current page (using the body id)
			var this_article = $('#article>div').attr('id'); // find current article (using the id of its decendent div)
				if (article_request == null) {article_request = 'default';} // set article_request to default
			var current_stats = 'CURRENT PAGE:\n' + this_page + '/' + this_article


			// ****************************  
				// BUG: Same page, NEW content... CREATES MULTIPLE ITERATIONS OF FUNCTIONS
				// current doesn't display...
			// ****************************   



		   // THE SAME PAGE ****************************************************
			if (page_request == this_page) {

				// SAME PAGE, SAME ARTICEL - NO CHANGE
				if (article_request == this_article) {
					// alert(current_stats + '\n\nNO CHANGE');
				}
				// SAME PAGE, CHANGE ARTICLE
				else {
				   	// alert(current_stats + '\n\nSAME PAGE, CHANGE ARTICLE request. loading: \n' + article_request); 
					$('#article').load('_' + article_request)
			    }
			}

			// A DIFFERENT PAGE  ****************************************************
			else if (this_page != page_request) {  

		   		if (article_request == 'default') {
					//alert(current_stats + '\n\nNEW PAGE, DEFAULT ARTICLE request. loading: \n' + page_request + '/(default)');
					document.location.href = '/' + page_request + '/';
				}     

				// NEW PAGE, ARTICLE 
				else {
					//alert(current_stats + '\n\nNEW PAGE, ARTICLE request. loading: \n' + page_request + '/' + article_request);
					document.location.href = '/' + page_request + '/' + article_request;
					// document.location.href = '/' + page_request + '/' + page_request + '.php?article=' + article_request;
					// FUTURE PROJECT
					// need .htaccess rule to remove the query string.
				}   	

			} // close else (DIFFERENT PAGE)   

		}  // close changeContent();    
		
		
    } break;

}
	


/* NAVIGATION EXPLANATION

== LINKS ==
	Create classes that attached a specific 'change content' function


== INITIAL LOAD ==
	The PHP CONTENT SWITCH loads the default content
		switch ($_article) { default: '_home.php' }

	
== NO SCRIPT ==

	MAP FLAT URLs
		Configure .HTACCESS to map (internally) FLAT URLs to QUERY STRING URLs
			 /home/welcome --> /home/home.php?article=welcome 
		The URL doesn't change
		Place RULES at the bottom of the file (after the CHANGE CONTENT rules)
		
	EXPAND TRUNCATED NAMES
		If files or sub-directoris have truncated names from what you want to show in the URL, remap them here
			RewriteRule ^vintage$ vintage_pop [R,NC]
			RewriteRule ^swings$ a_world_that_swings [R,NC]
		The [R] flag rewrites the URL in the address bar.
		
	PHP CONTENT SWITCH
		Set a relative path for each article
		Prefix article content with an (_) to...
			- Distinguish it from the FLAT URLs
			- Allow the template AND the default content to have the same name 
				home.php | _home.php
			- Easily identify templates from articles
		Articles can be in the same directory or in a sub-directory
			welcome: '_welcome.php'
			hello: '_hello/_hello.php'
		The PHP CONTENT SWITCH will re-load FLAT URLs using the article in the Query String
		
	
== DYNAMIC: CHANGE CONTENT FUNCTION ==

	Initial Page Load as above.
	On click, The CHANGE CONTENT function determines the action.

	FIND 'THIS'
		THIS PAGE is set by finding the id of <body>
			<body id="home">
		THIS ARTICLE is set by finding the id of the article
			#article #default | #article #welcome
	
	SET THE DEFAULT TO DEFALUT (LOL)	
		If the function is passed with only one paramater, set ARTICLE REQUEST to 'default'
			change_content ('gallery')
			if (article_request == null) {article_request = 'default';} 
		
	== SAME PAGE, CHANGE ARTICLE ==
		Load the ARTICLE REQUEST using the built in JQUERY function
			$('#article').load('_' + article_request); 
		Append the (_) to the ARTICLE REQUEST (see FLAT URLs)
		
		HTACCESS	
			Configure .HTACCESS to map _article_request to the correct URL
				RewriteRule ^_default$ _home.php [NC,L]
			Not needed if the name is the same
				_welcome.php | _welcome/ (sub-directory. see next)
	
		HTACCESS FOR SUB DIRECTORIES
			Articles can be in the same directory or in sub-directory.
			When using a sub-directory, add a .HTACCESS file to it and configure it with the article to load
				_welcome/_welcome.php use: DirectoryIndex _welcome.php

	== NEW PAGE, DEFAULT ARTICLE ==
		This simply loads a new PAGE using an ABSOLUTE URL
		The default article is set by the PHP CONTENT SWITCH
			document.location.href = '/' + page_request + '/';
			
	== NEW PAGE, ARTICLE 
		Load the new PAGE and ARTICLE using a FLAT URL
			document.location.href = '/' + page_request + '/' + article_request;
		This has a drawl back in that the url will show the that url after changing content (see below)

		FUTURE PROJECT
			Load the new PAGE and ARTICLE using a QUERY STRING URL
				document.location.href = '/' + page_request + '/' + page_request + '.php?article=' + article_request;
			Configure .HTACCESS to remove the QUERY STRING URLs in the address bar
				- We want to drop the query altogether.


*/
	



