var Across = {

	actual : 0,

	setMenu : function () 
	{
		var items = $('#main-menu .menuHeader');

		for (var i=0;i < items.length; i++)
		{
			$(items[i]).hover(
				function () 
				{
					$(this).addClass('ShowItems');
					//$('.ShowItems .sub-menu').css('top', -($('.ShowItems .sub-menu').height()));
				}, 
				function () 
				{
					$(this).removeClass('ShowItems');
				});
		}
	},
	

    sendM : function (thisFom)
    {
        Across.actualForm = thisFom;

        $.post("/",
            'Func=contacts.sendMessage&'+$(thisFom).serialize(),
            function(data) {

                if (data.error)
                {
                    jQuery.each(data.items, function(i, val) {
                        $('#'+i).val(val);
                    });
                }
                else
                {

                    Across.actualForm.reset();
                    alert(data.message);
                }
            },
            "json"
            );
    },
	
    newsletterSubscibe: function(thisFom)
    {
        Across.actualForm = thisFom;

        $.post("/", 'Func=newsletter.subscribe&' + $(thisFom).serialize(), function(data)
        {

            if (data.error)
            {
					var string = '<ul>';
					
					jQuery.each(data.items, function(i, val) {
						string += '<li><label for="newsletter_'+i+'">'+val+'</label></li>';
				    });
					
					string += '</ul><br/>';

					$('#subs-errors').html(string);
            }
            else
            {
                $('#subs-errors').html(data.message);
            }
        }, "json");
    },
	
    clearField : function (item)
    {
        $(item).attr('value', '');
    },

	addGuest : function (thisFom)
    {
        Across.actualForm = thisFom;

		$.post("/", 
			'Func=guestbook.addGuest&'+$(thisFom).serialize(), 
			function(data) {

				if (data.error)
				{
					if ( data.message )
					{
						Across.actualForm.reset();
						$('#guest-errors').html('<p><strong>'+data.message+'</strong></p>');
					}
					else
					{
						var string = '<ul>';

						jQuery.each(data.items, function(i, val) {
							string += '<li><label for="'+i+'">'+val+'</label></li>';
						});


						$('#guest-errors').html(string + '</ul>');
					}
				}
				else
				{
					Across.actualForm.reset();
					$('#guest-errors').html('<p><strong>'+data.message+'</strong></p>');
				}
			},
			"json"
		);
	},
	
	addComment : function (post_id, thisFom)
    {
        Across.actualForm = thisFom;

		$.post("/", 
			'Func=blog.addComment&post_id='+post_id+'&'+$(thisFom).serialize(), 
			function(data) {

				if (data.error)
				{
					if ( data.message )
					{
						Across.actualForm.reset();
						$('#guest-errors').html('<p><strong>'+data.message+'</strong></p>');
					}
					else
					{
						var string = '<ul>';

						jQuery.each(data.items, function(i, val) {
							string += '<li><label for="'+i+'">'+val+'</label></li>';
						});


						$('#guest-errors').html(string + '</ul>');
					}
				}
				else
				{
					Across.actualForm.reset();
					$('#guest-errors').html('<p><strong>'+data.message+'</strong></p>');
				}
			},
			"json"
		);
	}

};

$(window).ready(function () {
	Across.setMenu();
});
