var med = 500;
var slow = med * 2;
var ini = true;
var isEleborate= false;
$(document).ready(function()
{
	$('body').css('background', '#fcfcfc');

$('#nav li').hover(function(){showNavMenu(this)}, function(){hideNavMenu(this)});
$('#nav li').click(function(){showNavMenu(this)});

	$('#post').click(function(event){
	event.preventDefault();
	if($('#name').val() != 'Your name' && $('#name').val() != '' && $('#feed').val()!='Your message..' && $('#feed').val()!='')
	{
	$.post(
	'feedback',
	{
	name:$('#name').val(),
	email:$('#email').val(),
	website:$('#website').val(),
	feed:	$('#feed').val()
	},
	function(response)
	{
	//
	}
	)
	}
	});

	$('#mystiqa').click(function(){elaborate();});
	$('#elaborate td').click(function(){
	$('#elaborate').fadeOut(med, function(){isEleborate = false;});});
	newQuote();
});
var timeout;
function newQuote()
{
	(timeout == 'undefined') ? null : clearTimeout(timeout);
	(ini == true) ? $('body').css('background', '#ebebeb') : null;
	$('#centre td').fadeOut(slow * 2, function(){
	$('#centre td').load('quote.php', function() {
			if(ini == true)
			{
				ini = false;
				$('#bg').fadeIn(slow, function(){
				$('body').css('background', '#729899');
				$('td').css('display', 'none');
				$('#footer').fadeIn(slow, function(){
				$('#ban').animate({
				opacity: 'toggle',
				height: 'toggle'
				}, slow, function() {
				$('#mystiqa').animate({
				opacity: 'toggle',
				height: 'toggle'
				}, slow * 2, function() {
				$('td').fadeIn(slow * 3, function(){
					timeout = setTimeout(function(){newQuote();}, slow * 5);
					});});
				});
				});
				});
			}
			else
			{
				$('td').fadeIn(slow * 2, function() {
					timeout = setTimeout(function(){
					newQuote();
					}, slow * 7);
					});
			}
	});
	});
}

function elaborate()
{
	if(isEleborate == false)
	{
	isEleborate = true;
	$('#elaborate .chapter').html($('#centre .chapter').html() == '' ? null : $('#centre .chapter').html() + ' : ');
	$('#elaborate .episode').html($('#centre .episode').html());
	$('#elaborate .canto').html($('#centre .canto').html() == '' ? null : ' Canto ' + $('#centre .canto').html());
	$('#elaborate blockquote').html($('#centre blockquote').html());
	$('#elaborate').fadeIn(med);
	}
	else
	{
		$('#elaborate').fadeOut(med, function(){isEleborate = false;});
	}
}

function showNavMenu(e)
{
	$(e).find('div').fadeIn(slow);
	$(e).find('.ima').stop(true, false).fadeTo(med, 0);
}
function hideNavMenu(e)
{
	$(e).find('div').fadeOut(med);
	$(e).find('.ima').stop(true, false).fadeTo(slow, 1);
}

function fadeIN(e, speed, fn)
{
	e.fadeIn(speed, fn);
}
function fadeOUT(e, speed, fn)
{
	e.fadeOut(speed, function(){fn();});
}

function x(){}
