/// <reference path="jquery-1.4.4-vsdoc.js" />
// squirrel-functions.js - requires jquery.js 1.5+
// created by Kyle Weems
// created: Feb 12, 2011
// modified: Sep 15, 2011

var cloud = 0;
var mountain = 0;
var hill = 0;
var forest = 0;

$(document).ready(function(){
	scrollLandscape();
	bindSearch();
	groundFooter();
	//var t = setTimeout("$('.js #content p a, .js #content li a').css({display: 'inline'});", 200);
});


function scrollLandscape() {
		$("footer").bind('mouseenter',function(e) {
			var initial = forest;
			cloud = cloud*4-e.clientX;
			mountain = mountain*3-e.clientX;
			hill = hill*2-e.clientX;
			forest = forest-e.clientX;
		});
		$("footer").mousemove(function(e) {
			mouseX = e.clientX;
			var cssString = Math.floor((mouseX+forest)%800) + "px 0, " + Math.floor((mouseX+hill)/2%800) + "px 0, " + Math.floor((mouseX+mountain)/ 3%652) + "px 0, " + Math.floor((mouseX+cloud)/ 4%800) + "px 0";
			$("footer").css("background-position", cssString);
		});
} 

function bindSearch() {
	$('#social-list .search input').bind('focus', function(){
		if($(this).attr('value')=="Enter Search Term") {
			$(this).attr('value', "");
		}
	});
	$('#social-list .search input').bind('blur', function(){
		if($(this).attr('value')=="") {
			$(this).attr('value', "Enter Search Term");
		}
	});	
	$('#social-list .search button').bind('click', function(){ runSearch();});
	$('#social-list .search input').bind('keypress', function(e){
		var code = (e.keyCode ? e.keyCode : e.which);
		if(code == 13){
			runSearch();
		}
	});
	$('#contact input[type="text"]').bind('focus', function(){
		if($(this).attr('value') == "Email Address"){
			$(this).attr('value', '');
		}
	});
	$('#contact input[type="text"]').bind('blur', function(){
		if($(this).attr('value')=="") {
			$(this).attr('value', "Email Address");
		}
	});
	$('#contact textarea').bind('focus', function(){
		if($(this).html() == "Enter Message Here"){
			$(this).html('');
		}
	});
	$('#contact textarea').bind('blur', function(){
		if($(this).html()=="") {
			$(this).html('Enter Message Here');
		}
	});
}

function runSearch(){
	var s = $('#social-list .search input').attr('value');
	s = s.replace(/ /gi, "+");
	window.location = "/blog/?s=" + s;
}

function groundFooter(){
	var h = $('header[role="banner"]').outerHeight();
	var f = $('footer').outerHeight();
	var c = $('#content').height();
	var d = $(window).height() - (f + h + 31);
	if(c < d) {
		$('#content').css('min-height',d+'px');
	}
}
