$(document).ready(function(){

//insert overlay box
$('#inner-content').before('<div id="overlaycontainer"><div id="overlaycontainer-border"><div id="overlaycontainer-close"></div></div></div>');

//open sections via deeplink
if(pgname!="") {
	openSection(pgname);
}	

	//open sections via nav
	$('a').click(function(){	

		var rel = $(this).attr('rel');	
		var href = $(this).attr('href');
		
			if(rel=='overlay'){

				if ($('#overlaycontainer').is(':hidden')) {
					openSection(href);
					return false;
				} else {
					transitionSection();	
					switchSection(href);
					return false;
					 //$('#overlaycontainer-iframe').attr('src',href);
				};	
			};
	});
	
	//close button
	$('#overlaycontainer-close').click(function(){
		closeSection();
		$('#index-about').fadeIn('fast');
	});

});

function openSection(href) {
		//$('#inner-content').fadeTo("slow", 0.4);
		$('#index-about').hide();
		$('#overlaycontainer').fadeIn('fast', function() {								   
			$("#overlaycontainer-border").append('<iframe id="overlaycontainer-iframe" src="' + href + '" scrolling="no" frameborder="0"></iframe>');
		});		
};

function switchSection(href) {
		$('#overlaycontainer').fadeIn('fast', function() {								   					   
			$("#overlaycontainer-border").append('<iframe id="overlaycontainer-iframe" src="' + href + '" scrolling="no" frameborder="0"></iframe>');
		});
};

function closeSection() {
	if ($("#overlaycontainer").is(":visible")) {
		$('#overlaycontainer').hide();
		$('#overlaycontainer-iframe').remove();
		$('#index-about').fadeTo("fast", 1.0);
	};
};

function transitionSection() {
	if ($("#overlaycontainer").is(":visible")) {	
			$('#overlaycontainer').fadeOut(200);
			$('#overlaycontainer-iframe').delay(200).remove();	
	};
};