$(document).ready(function(){
	$('.menu ul').parent().addClass('parentcat');
	$('.parentcat').each(function(i){
		var hidden = true;
		$(this).find('a:first').prepend('<span class="arrow">&raquo;</span>');
		$(this).hover(
			function () {
				hidden = false;
				posx = $(this).position().left + $(this).width() - 2;
				posy = $(this).position().top;
				elem = $(this).find('ul:first');
				elem.css({'top': posy+'px', 'left': posx+'px', 'width': '0px'}).animate({'opacity': 1},600,function(){ if ( !hidden ) elem.animate({'width': '200px'}, 300, 'swing'); });
			},
			function () {
				hidden = true;
				$(this).find('ul:first').stop(true,true).hide();
			}
		);
	});
	$('#search').click(function(){ $('#quick_find').submit(); });
	$('#quick_find').submit(function(){
		if ( $('#search_input').val() == "" || $('#search_input').val() == "Search" )
		{
			displayMessage("Type in a search phrase.", $('#search_input'), "error");
			return false;
		}
	});
	$('#search_input').focus(function(){
		$(this).css({'background-color': '#fff'});
		if ($(this).val() == 'Search')
			$(this).val('');
	});
	$('#search_input').blur(function(){
		$(this).css({'background-color': '#e9e9ff'});
		if ($(this).val() == '')
			$(this).val('Search');
	});
	$('#search').click(function(){
		$(this).parent('form').submit();
	});

	$('.tooltip').each(function(i){
		var tooltip = "";
		if ( tooltip == "")
		{
			tooltip = $(this).attr('title');
			$(this).removeAttr("title");
			this.alt = '';
		}
		$(this).hover(
			function(){
				posy = $(this).offset().top;
				$('<div />').attr({'id': 'hyp_tooltip'}).css({'top': (posy - 7) + 'px', 'right': '214px', 'width': '0px'}).html(tooltip).appendTo($('body')).hide();
				$('#hyp_tooltip').animate({'opacity': 1},300,function(){ $('#hyp_tooltip').animate({'width': '250px'}, 300, 'swing'); });
			},
			function(){
				$('#hyp_tooltip').remove();
			}
		);
	});

});
function displayMessage(message,element,type) {
	$("<div />").attr({'id': 'hyp_message', 'class': 'hyp_message hyp_message_' + type}).html('<div />' + message).appendTo($('body')).slideDown(100).click(function(){ $(this).fadeOut(function(){$(this).remove()}); }).animate({'opacity': 1},4000,function(){ $(this).fadeOut(function(){$(this).remove()}); });
	eTop = element.offset().top;
	eLeft = element.offset().left;
	eHeight = element.outerHeight();
	$('#hyp_message').css({'top': eTop + eHeight + 10 + 'px', 'left': eLeft});
}