
// JavaScript Document
$(document).ready(function() {
			//variables
			$homeLink = $('a.homelink');
			$extLoaderLink = $('a.ext-loader');
			$content = $('div#content-loader'); //This Div must be defined in the main html
			$extLoaderLink.click(function(ev) { //the "ev" in brackets states the event for the link as an arguement - useful for the ev.preventDefault()
						ev.preventDefault(); //disables default action
						$content.fadeOut();
						$urlLink = $(this).attr("href");  //Get the link to the file
						$urlParameters = $(this).attr("name"); //Collect the URL parameters via the "name" attribute.
						//alert($urlLink);
						$('div#homeContentBody').fadeOut('slow');  //fade out the main screen (intro, thumbnails, and stats)
						//$('#preloader').append($('<div id="loading" align="center"><img src="images/ajax-loader.gif"></div>'));
						$('#preloader').show(); //show the preloader
						
						//Start Loading external page
						$content.find('#content-body').load($urlLink + '?random=' + $.random(2000) + '&' + $urlParameters, function(responseText,textStatus,req){  //begin loading external document
					if (textStatus == 'error') { //if there's an error (like file not found or not loaded)
					//alert('Problem - File not found');
					$content.delay(500);  //delay action for 0.5 seconds
					$('#preloader').hide();  //hide the preloader
					$content.find('#content-body').empty();  //flush any content currently inside the externally loaded file - useful for subsequent clicks
					$content.find('#content-body').append($('<h1 style="color:#990000;">Sorry, the page you are looking for is currently not available</h1><p>The page has mostly likely been moved or under construction. Click the Homepage link above to go to the homepage</p><br clear="all" />')); //attach error message
					$content.fadeIn('slow'); //show the container loader
					$content.animate({marginTop: '50px'}, 300);
					}
					else { //if there is no error, proceed as expected.
						$content.delay(500);
						$content.fadeIn('slow');
						$content.animate({marginTop: '50px'}, 300);
						$('#preloader').hide();
						//$('#preloader').detach();
						}
				});// end of load
						
					});
			$homeLink.click(function(ev) {
					ev.preventDefault();
					$content.fadeOut('slow');
					$content.delay(800);
					$content.find('#content-body').empty();  //flush any content currently inside the externally loaded file - useful for subsequent clicks
					$('div#homeContentBody').delay(800).fadeIn('slow');
				});
			
			
			
			
			$extLoaderLink.live('click', function(ev) {
 //the "ev" in brackets states the event for the link as an arguement - useful for the ev.preventDefault()
						ev.preventDefault(); //disables default action
						$content.fadeOut();
						$urlLink = $(this).attr("href");  //Get the link to the file
						$urlParameters = $(this).attr("name"); //Collect the URL parameters via the "name" attribute.
						//alert($urlLink);
						$('div#homeContentBody').fadeOut('slow');  //fade out the main screen (intro, thumbnails, and stats)
						//$('#preloader').append($('<div id="loading" align="center"><img src="images/ajax-loader.gif"></div>'));
						$('#preloader').show(); //show the preloader
						
						//Start Loading external page
						$content.find('#content-body').load($urlLink + '?random=' + $.random(2000) + '&' + $urlParameters, function(responseText,textStatus,req){  //begin loading external document
					if (textStatus == 'error') { //if there's an error (like file not found or not loaded)
					//alert('Problem - File not found');
					$content.delay(500);  //delay action for 0.5 seconds
					$('#preloader').hide();  //hide the preloader
					$content.find('#content-body').empty();  //flush any content currently inside the externally loaded file - useful for subsequent clicks
					$content.find('#content-body').append($('<h1 style="color:#990000;">Sorry, the page you are looking for is currently not available</h1><p>The page has mostly likely been moved or under construction. Click the Homepage link above to go to the homepage</p><br clear="all" />')); //attach error message
					$content.fadeIn('slow'); //show the container loader
					$content.animate({marginTop: '50px'}, 300);
					}
					else { //if there is no error, proceed as expected.
						$content.delay(500);
						$content.fadeIn('slow');
						$content.animate({marginTop: '50px'}, 300);
						$('#preloader').hide();
						//$('#preloader').detach();
						}
				});// end of load
						
					});
			
			
			
	
		});

