//content pane
function openPane() {	
	if ( $(document).width() < 1265 ) {
		$('.logo').fadeOut();
		$('.advantages').css('width','590px');
	}
	$('.box').fadeOut("slow");
	$('.nav a').animate({ color: "#c9e2a7" }, 1144, function(){ $(this).removeAttr("style"); });
	$('.nav li a.active').animate({ color: "#ffffff" }, 400, function(){ $(this).removeAttr("style"); });
	$('body').removeClass("closePane").addClass("openPane");
	$('#content_bg').animate({ right: 0 }, 1144, function(){				
		$('#content').fadeIn(1144);
	});
};

function closePane() {
	if ( $('body').hasClass("openPane") ) {
		$('.logo').delay(500).fadeIn();
		$('.nav a').animate({ color: "#5d5d60" }, 1200, function(){ $(this).removeAttr("style"); });
		$('.nav li a.active').animate({ color: "#7bbd31" }, 400, function(){ $(this).removeAttr("style"); });
		$('body').removeClass("openPane").addClass("closePane");
		$('#content').fadeOut(400, function(){
			$('#content_bg').animate({ right: -1144 }, 1144);
		});
	}
};

//history pageload
function pageload(hash) {
	if(hash) {
		if($.browser.msie) {
			hash = encodeURIComponent(hash);
		}
		$('body').removeClass("splash");
		$('.nav li a[href="#'+hash+'"]').addClass("active").parent().siblings().children('a').removeClass("active");
		closePane();
		$('#intro').fadeOut(1144,function(){
			$("#load").empty();
			$("#load").load(hash + ".html", function(){
				$('body').removeClass("inside");
				$("#intro").fadeIn(1144);				
			});	
		});
		
	} else {
		// start page
		$('.nav li a[href="#home"]').addClass("active").parent().siblings().children('a').removeClass("active");
		closePane();
		$('#intro').fadeOut(1144,function(){
			$("#load").load("home.html", function(){
				$("#intro").fadeIn(1144);
			});
			
		});		
	}
}

$(document).ready(function(){
	$.historyInit(pageload, "home.html");

	$(window).resize(function() {
		if ( $('body').hasClass("openPane") ) {
			if ( $(document).width() < 1265 ) {
				$('.logo').fadeOut();				
			} else {
				$('.logo').fadeIn();
			}
		}
	});

	//main nav clicks load ajax content via historyLoad
	$(".nav a, a.logo").click(function(){	
		var hash = this.href;
		hash = hash.replace(/^.*#/, '');
		$.historyLoad(hash);
		document.title = "Clean Works BC - " + $(this).text();
		return false;
	});
	
	// $('.closePane #intro h1 a').tooltip();
	
	//hover popups on links in h1 paragraphs
	$('.closePane #intro h1 a:not(".noPop"), .popups a').live('hover', function(e){
		if ( e.type == "mouseenter" ) {
			var hash = this.href;
			hash = hash.replace(/^.*#/, '');
			$('#'+hash).fadeIn();
			$('#'+hash).siblings('.box').fadeOut();
		} else {
			$('.box').fadeOut();
		}		
	});

	//openPane on h1 link clicks (but not on contact page or advantages content)
	$('#intro:not(".contact") h1 a').live('click', function(){		
		openPane();
		return false;
	});
	$('#mailto').live('click', function(){		
		window.location = 'mailto:info@cleanworksbc.com';
		return false;
	});
	$('.contact h1 a').live('click', function(){
		return false;
	});
	$('.advantages ol li a').live('click', function(){
		return false;
	});
	
	//close pane links
	$('.close_pane').live('click', function(){
		closePane();
	});
	
	// //intro hover
	// $('.splash .landing a').hover(function(){
	// 	$(this).addClass('hover');
	// });
	// 
	// //intro click reveals index content
	// $('.splash .landing a').click(function(){
	// 	$('.landing').fadeOut();
	// 	$('#intro').fadeIn("slow");
	// 	$('.logo').fadeIn("slow");		
	// 	$('.nav').fadeIn("slow",function(){
	// 		$('body').removeClass("splash");
	// 	});
	// });
	
	$('#intro').fadeIn("slow");	
	
});