$(function()
{
	$('.navigation li').hover(function ()
	{
		$(this).find('ul:first').css({'visibility': 'visible', 'display': 'none'}).show();
	}, function ()
	{
	    $(this).find('ul:first').css({'visibility': 'hidden'});
	});
	
	$('form').live('submit', function(event)
	{
		if (this.method != 'post')
		{
			return;
		}
		event.preventDefault();
		var form = $(this);
		$('.error').attr('original-title', '');
		$('.error').attr('title', '');
		$('.error').removeClass('error');
		form.find('#submit').parent().append('<div class="loader"></div>');
		form.find('input[type=submit]').attr('disabled', true);
		$.post(this.action, $(this).serialize(), function(data)
		{
			alert(data.message);
			if(data.return_value)
			{
				window.location.reload();
			}
			else
			{
				$.each(data, function(id, msgs)
				{
					$.each(msgs, function(type, msg)
					{
						if (typeof(msg) == 'object')
						{
							form.find('#'+type).addClass('error');
							$.each(msg, function (type_2, msg_2)
							{
								form.find('#'+type).attr('title',msg_2);
							});
						}
						else
						{
							form.find('#'+id).addClass('error');
							$.each(msgs, function (type_2, msg_2)
							{
								form.find('#'+id).attr('title',msg_2);
							});
						}
					});
					$('.error').tipsy({gravity:'w',fade:true,live:true});
				});
			}
			form.find('input[type=submit]').removeAttr('disabled');
			$('.loader').remove();
		}, 'json');
	});
	
	if ($('.col-left').height() < $('#main').height())
	{
		$('.col-left').height($('#main').height());
	}
	if ($('.col-right').height() < $('#main').height())
	{
		$('.col-right').height($('#main').height());
	}
	
	$('.latest-blog-post').cycle({
		fx: 'fade'
	}); 
	
	$('.footer-slide ul').cycle({
		fx: 'fade'
	}); 
	
});
