	var viewportwidth;
	var viewportheight;
	
	var overlayBox;
$(document).ready(function(){
	//Global animations placed at bottom of page
	$('#topContent, #content, #footer').animate({opacity:1}, 600);
	$('ul#submenu').slideDown(500, "easeOutCubic", function(){
		tellSize(1500,false);
	});
	
	var url_end = document.location.href.substr(document.location.href.lastIndexOf("/"));
	if(url_end == "/"){
		setTimeout("tellSize(1500);", 80); //delay so slideshows don't mess with height
	}else{
		setTimeout("tellSize(1500,false);", 80); //delay so slideshows don't mess with height
		animateDashedLine();
	}
	
	//Overlay Code
	$("a[rel], div[rel]").overlay({
		mask: {
			color: '#9d958c',
			loadSpeed: 200,
			opacity: 0.73
		},
		onBeforeLoad: function() {	
			var wrap = this.getOverlay().find(".contentWrap");
			wrap.load(this.getTrigger().attr("href"));
		}		
	});
	
});
	
$(window).resize($.debounce(tellSize, 400));
	
function tellSize(dur, animate){
	setSize();
	computeScroll();
	
	dur = typeof(dur) != 'undefined' ? dur : 400; //set default value
	animate = typeof(animate) != 'undefined' ? animate : true; //set default value
	
	//compute buffer height
	var backToMobile = $('#backToMobile').height();
	var marginTop = $('#wrapper').css('marginTop').replace("px",'');
	var marginBottom = $('#wrapper').css('marginBottom').replace("px",'');
	var contentHeight = $('#content').height()+$('#topContent').height()+Number(marginTop)+Number(backToMobile);
	var navHeight = $('div#leftContainer').height()+Number(marginTop);
	
	var bufferHeight = viewportheight - contentHeight - marginBottom;
	var scroll = false;
	if(navHeight > contentHeight){
		if(viewportheight < navHeight){
			//alert(1);
			bufferHeight = navHeight - contentHeight +20;
			scroll = true;
		}else{
			//alert(2);
			bufferHeight = viewportheight - contentHeight - marginBottom;			
		}
	}else{
		if(viewportheight < contentHeight){
			//alert(3);
			bufferHeight = 40;
			scroll = true;
		}else{
			//alert(4);
			bufferHeight = viewportheight - contentHeight - marginBottom;			
		}
	}
	
	
	if(bufferHeight<40)
		bufferHeight = 40;
		
	//compute footer width extension
	var footerExtension = (viewportwidth/2) - 400 + 587;
	if(footerExtension< 587)
		footerExtension = 587;
	if(scroll){
		footerExtension = footerExtension - 10;
	}
	
	if(animate){
		$("#footer").animate({width: footerExtension+"px"}, dur, "easeOutCubic");
		setTimeout("$('#bottom_space_buffer').animate({height: '"+bufferHeight+"px'}, "+dur+", 'easeOutCubic');", 450);
		
	}else{
		$("#bottom_space_buffer").css('height', bufferHeight+"px");
		$("#footer").css('width', footerExtension+"px");
	}
	
	
}

function computeScroll(){
	//Custom scrollbar
	var scrollpaneheight = viewportheight - 340;
	if(scrollpaneheight < 550)
		scrollpaneheight = 550;
	$('.scroll-pane').css('height', scrollpaneheight+'px');
	$('.scroll-pane').jScrollPane({
		verticalDragMinHeight: 50,
		verticalDragMaxHeight: 50
	});
}
	
function setSize(){		
	if (typeof window.innerWidth != 'undefined')		{
		viewportwidth = window.innerWidth,
		viewportheight = window.innerHeight
	} else if (typeof document.documentElement != 'undefined'	&& typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0){
		viewportwidth = document.documentElement.clientWidth,
		viewportheight = document.documentElement.clientHeight
	} else {
		viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
		viewportheight = document.getElementsByTagName('body')[0].clientHeight
	}
}
	
	
function focusDefaultText(elem, text){
	var currentText = $(elem).val();
	if(currentText==text){
		$(elem).val('');
		$(elem).attr('class','');
	} 
}
function blurDefaultText(elem, text){
	var currentText = $(elem).val();
	if(currentText==''){
		$(elem).val(text);
		$(elem).attr('class','default');
	} 
}


//this variable is for the two different pages where
// this function is called.  In the overlay window it
// requires a shorter width buffer.
var specifiedWidth = -1;
function nextHighlight(id, slideLeft, width){
	if(specifiedWidth==-1)
		specifiedWidth = width;
	if(slideLeft){
		$('div#highlight_content').animate({right: specifiedWidth+'px'}, 700, function(){
			$.ajax({ type:'GET', url:"/posts/ajaxView/"+id+"/true", async:false, success: function(data){
				$('div.contentWrap').html(data);
				$('div#highlight_content').fadeIn();
				}
			});
		});
	}else{
		$('div#highlight_content').animate({right: '-'+specifiedWidth+'px'}, 700, function(){
			$.ajax({ type:'GET', url:"/posts/ajaxView/"+id+"/true", async:false, success: function(data){
				$('div.contentWrap').html(data);
				$('div#highlight_content').fadeIn();
				}
			});
		});	
	}	
}
	
	
