// Load jQuery
/*
google.load("jquery", "1");

window.synOnLoadCallbacks = [];
google.setOnLoadCallback(function() {
	if (synOnLoadCallbacks.length > 0) setTimeout(function() { (synOnLoadCallbacks.shift())(); }, 1);
});

synOnLoadCallbacks.push(function() {
	*/
	try {
		$(function() {
			// Set up changing message in the header
			$(".fadingMessages").each(function() {
				var container = $(this),
				    children = container.children(),
				    delay = 3000;
				container.height(Math.max.apply(Math, children.map(function() { return $(this).height(); }).get()));
				children.not(":first").hide().css("visibility", "visible").end();
				setInterval(function() {
					var visible = children.filter(":visible").fadeOut(),
					    next = visible.next();
					(next.length > 0 ? next : children.filter(":first"))["fadeIn"]();
				}, delay);
			});
			
			// Change search page text
			$("#searchFormArea blockquote").empty()
			  .html("<h3 style='float: none;'>Well, this is embarrassing.</h3>" +
			  "<p>Brushlove is having trouble finding your search results. Please try again using different search words.</p>");

			// Set up fader on homepage
			$(".fader").each(function() {
				var obj = $(this),
				    children = obj.children(),
				    current = children.filter("*:visible"),
				    index = children.index(current),
				    timer = null;
				obj.bind("mouseenter", function() {
					if (timer) {
						clearInterval(timer);
					}
				}).bind("mouseleave", function() {
					timer = setInterval(function() {
						var next = $(children.get(++index % children.length));
						obj.append(next);
						next.fadeIn("slow");
						current = next;
					}, 5000);
				}).trigger("mouseleave");
			});
		});
	} catch(e) {
		if (window.console) console.log(e);
	}
	/*
	if (synOnLoadCallbacks.length > 0) setTimeout(function() { (synOnLoadCallbacks.shift())(); }, 1);
});
*/

