var loader = jQuery('<div style="z-index:9999996; position:absolute; top:0; left:0; text-align:center; width:100%; height:100%; background:#fff;"></div><div style="z-index:9999997; background:#fff;position:absolute;top:0; left:0;text-align:center;  width:100%; height:100%;"><img style="margin-top:50px; border:none;" src="images/loader.gif" width="508px;" height="381px;"></div>');

$(document).ready(function() {
	$('BODY').bgStretcher({
		images: ['images/4_Saxon_FS.jpg', 'images/5_Larchmont Gables_FS.jpg', 'images/6_Sutton_FS.jpg', 'images/7_Sanborn_FS.jpg', 'images/1_Main-St_FS.jpg', 'images/2_Chambers_FS.jpg'],
		imageWidth: 2160, 
		imageHeight: 1620, 
		nextSlideDelay: 7000,
		slideShowSpeed: 'slow',
		slideShow: true,
		transitionEffect: 'fade',
		anchoring: 'center center',
		anchoringImg: 'center center'
	});
	
	loader.appendTo('body');
	$('body').append('<div id="gray"></div>');
	$("#gray").hide(0);
	
	
	var hash = window.location.hash.substr(1);
	var href = $('.nav li a').each(function(){
		var href = $(this).attr('href');
		if(hash==href.substr(0,href.length-0)){			
			var toLoad = hash+'.html';
			$("#"+'hash').load(toLoad)
		}
		else {
		$("#home").load("home.html");
		}	
	});
	
	$('ul.menu a').click( function() {
		var al = $('ul.menu a');
		var all = $('div.interface');
		var selected = $(this).attr('href');
	  
		al.removeClass('selected');
		$(this).addClass('selected');
		  
		all.fadeOut(550);
		all.empty();
		$(selected).fadeIn(1500);
		$(selected).addClass('selected');
		$("#gray").empty();
 	});
	
	$("a.home").click(function() {
		$("#gray").hide(0);
		$("#home").load("home.html");
		return false;
		window.location = $(this).attr('href').substr(0,$(this).attr('href').length-0);
	});
	
	
  	$("a.abt").click(function() {
		$("#gray").hide(0);
		$("#about").load("about.html");
		return false;
		window.location = $(this).attr('href').substr(0,$(this).attr('href').length-0);
		$(document).attr("title", "About Caspi Development");
	});
	
	
  	$("a.con").click(function() {
		$("#gray").hide(0);
		$("#contact").load("contact.html");
		return false;
		window.location = $(this).attr('href').substr(0,$(this).attr('href').length-0);
	});
	
	
  	$("a.comm").click(function() {
		$("#gray").show(0);
		$("#commercial").load("commercial.html");
		return false;
		window.location = $(this).attr('href').substr(0,$(this).attr('href').length-0);
	});
	
	
  	$("a.hot").click(function() {
		$("#gray").show(0);
		$("#hotel").load("hotel.html");
		return false;
		window.location = $(this).attr('href').substr(0,$(this).attr('href').length-0);
	});
	
	
  	$("a.res").click(function() {
		$("#gray").show(0);
		$("#residential").load("residential.html");
		return false;
		window.location = $(this).attr('href').substr(0,$(this).attr('href').length-0);
	});
	
	var height = $(document).height();
	$("div#footer-container").css("Margin-top","50px");
	});	
		

jQuery(window).load(function(){
    loader.fadeOut(500);
});













	
	/*$('a').click( function() {
		  var all = $('div.interface');
		  var selected = $(this).attr('href');
		  all.removeClass('selected');
		  $(selected).addClass('selected');
		  div.filter(':not(.selected)').hide();
		  div.filter('.selected').show();
		  return false;  // stop the link from being taken
	 });*/
