/**
 * advance main JavaScript
 * @author Yoshiaki Sugimoto <neo.yoshiaki.sugimoto@gmail.com>
 * @create 2010/02/15
 *
 * @note need jQuery
 */

$(document).ready(function() {

	var q = $('input#query').css('color', '#ccc'), def = 'Input Keywords', current;
	function emptyDefault() {
		var v = q.val();
		if (v === def) {
			q.val('').css('color', '#333');
		}
	}

	function checkDefault() {
		var v = q.val();
		if (v == '' || v == def) {
			q.val(def).css('color', '#ccc');
		}
	}

	function blowFish(ev) {
		if (current) { current.css('display', 'none');}
		$(this).find('ul').css('display', 'block');
		current = $(this).find('ul').mouseout(function(){ $(this).css('display', 'none').unbind('mouseout', arguments.callee);});
	}

	function blowFishOff() {
		$(this).find('ul').css('display', 'none');
	}

	function blowFishClear() {
		if (current) { current.css('display', 'none'); }
	}

	// search query defaults
	q.focus(emptyDefault).blur(checkDefault);

	// set blowFish
	$('ul#nav_list > li').mouseover(blowFish).mouseout(function(ev) {
		ev.stopPropagation();blowFishClear();});
	$('ul#nav_list li ul').mouseout(function(ev) { ev.stopPropagation();});
	$('ul#nav_list').mouseout(blowFishClear);
});
