function fixBg()
{
	left_position = ($(document).width() / 2) - (1920 / 2);
	bottom_position = $(document).height() - 1200;
	$('body').css({'backgroundPosition': left_position + 'px ' + bottom_position + 'px'})
}

var obj = null;

function checkHover() {
	if (obj) {
		obj.find('ul').fadeOut('fast');
		obj.find('a').removeClass('active');
	}
}

$(document).ready(function(){
	var myOpen = function(hash){ hash.o.fadeIn('slow'); hash.w.fadeIn('slow'); };
	var myClose = function(hash){ hash.o.fadeOut(500); hash.w.fadeOut(500); };
	$('#contacts').jqm({onShow : myOpen, onHide: myClose});

	$('.show_contacts').click(function(e){
		e.preventDefault();
		$('#contacts').jqmShow();

	});

	$('#contacts form input, #contacts form textarea').focus(function(){
		$(this).val('');
	});

	fixBg();
	$(window).resize(fixBg);

	$('.navigation li ul li a').each(function(i){
		$(this).width($(this).parent().parent().parent().children('a').width());
	});
	$('.navigation > li ul').hide();

	$('.navigation > li').hover(function() {
		if (obj) {
			obj.find('ul').animate({opacity:'hide', height:'hide'}, 400);
			obj = null;

			$('.navigation > li a').removeClass('active');
		}

		$(this).find('ul').animate({opacity:'show', height:'show'}, 400);
		$(this).find('a').addClass('active');
	}, function() {
		obj = $(this);
		setTimeout(
			"checkHover()",
			300);
	});

    //Mail form validation
    $('#mail_form').submit(function(e){
        $('.required').removeClass('error');

        var errors = 0;

        $('.required').each(function(){
            if($(this).val() == '')
            {
                e.preventDefault();
                
                $(this).addClass('error');
                $(this).focus();
            }
        });
    });
});