// JavaScript Document
// 2011 Roof Spec Inc.
// By First Scribe




// Sets equal height for floated divs with class of .column
// Set as global function so it is available to run in specific pages twice if needed
function setEqualHeight(){
	var column = $('.column');
	var heightsColumns = [];
	column.addClass('js');
	column.each(function(i, e) {
		heightsColumns.push(parseInt(parseFloat($(e).height())));
	});
	var tallestColumn = Math.max.apply( null, heightsColumns );
	column.height(tallestColumn);
}

$(window).load(function(){
	setEqualHeight();	// Webkit needs this here
});

$(document).ready(function() {
// Sets active class on sidebar link which matches the URL
// Uses the jquery.url plug-in
function setActive(){
	var location = $.url.attr('path')
	$('#sidebar-left li a').each(function(){
		var href = $(this).attr('href');
		if (location == href) { 
		$(this).addClass('active');
		$(this).parent('li').parent('ul').parent('li').addClass('active');
		}
	});
}
setActive();


// Projects sidebar navigation control
// Shows and hides menus appropriately
$('#sidebar-left ul ul li').not('#sidebar-left ul ul li.active').click(function(e){
	var visible = $(this).children('ul').hasClass('visible'),
	font = $(this).children('font'),
	menu = $(this).children('ul');
	$('#sidebar-left ul.visible').removeClass('visible').prev('font').removeClass('open');	
	if (visible !== true) { 
		font.addClass('open');
		menu.addClass('visible');}
	else { 
		font.removeClass('open');
		menu.removeClass('visible');}
	e.stopPropagation();
});

// Hides any open sidebar menu (except with the current page) when clicking off of it
$(document).click(function(){
	$('#sidebar-left ul.visible').removeClass('visible').prev('font').removeClass('open');	
});


// Search value rewrites
var searchQuery = $('#search-form input[type="text"]')
searchQuery.bind('click change focus', function() {
	var str = $(this).val();
	if (str == "Site Search") {searchQuery.val("");}
});
searchQuery.blur(function(){
	var str = $(this).val();
	if (str == "") { searchQuery.val("Site Search");}
}); 

// Adds jQuery animations to menu items
$('#nav ul.main-nav li').addClass("js");
$('#nav ul.main-nav li').hoverIntent(function() {
	$(this).children('ul').stop(true, true).fadeIn("fast");
	}, function() {
	$(this).children('ul').stop(true, true).fadeOut("fast");
});



});
