// Sugar.
// (c) 2009 Phillip Ridlen for Diverse Suspension Technologies
// All Rights Reserved
//
// Sugar is all about the little things that aren't terribly important
// but make the site a lot more fun to use. :)
//
// Sugar tastes good.


// $(document).ready
// do all this stuff once the document has loaded.

$(document).ready( function() {
	
	// search boxes
	dummyText($("input.search"), "Search by Part or Vehicle", "inactive");
	
	details();
	
	$(".boxwrap").equalizeBottoms();
	
	collapse_list("recent");
	
	// otherinfo collapsed list
	$("ul.otherinfo ul").hide();
	$("ul.otherinfo li").click( function() {
		$(this).children("ul").slideToggle(100);
	});
		
	
});


// Dummy text
// accepts a collection of input text boxes and per-
// forms "dummy text" operations on it. Applies the
// class "dummy" to the element(s)
// =================================================
function dummyText( textBoxes, inactiveText, inactiveClass ) {
	
	textBoxes.addClass(inactiveClass);
	textBoxes.attr("value", inactiveText);

	textBoxes.focus( function() {
		if( $(this).attr("value") == inactiveText ) {
			$(this).attr("value","");
			$(this).removeClass(inactiveClass);
		}
	});
	
	textBoxes.blur( function() {
		if( $(this).attr("value") == "" ) {
			$(this).addClass(inactiveClass);
			$(this).attr("value",inactiveText);
		}  
	});	
}

function collapse_list(id) {
	$("li#"+id).children("ul").hide();
	$("li#"+id+" a").click( function() {
		$(this).parent().children("ul").slideToggle(75);
	});
}

// Details, details, details
// Hides any non-anchor elements with class "details"
// and finds the nearest anchor with the same class
// to trigger its display
// ==================================================

function details() {
	$(".details:not(a)").hide();
	$(".details:not(a)").addClass("notice");
	
	$(".details:not(a)").css({
		'position':'absolute', 
		'width':'300px'
	});
	
	$("a.details").attr("title","");
	$("a.details").hover( 
		function() {$(".details:not(a)").show();},
		function() {$(".details:not(a)").hide();}
	);
	
	$("a.details").show();
}


// Equalize Column bottoms
// uses jQuery equalizeBottoms
// by "Cowboy" Ben Alman
function equalize() {
	$(".boxwrap").equalizeBottoms();
}



// x 
// empty, good-for-nothing couch potato
function x() {}

