var Across = {

    oldLink     : false,
    oldLayer    : false,
    NewLink     : '',
	headerDelay : 4,
	actual      : 0,

	back : function ()
	{
		history.go(-1);
	},

	setMenuBgs : function ()
	{
		var items = $('#main-menu a');

		for (var i=0; i<items.length; i++ )
		{
			$(items[i]).hover(
				function () 
				{
					var id = this.id.substr(5,6);
					id++;

					if ( $('#menu-' + id) )
					{
						$('#menu-' + id).addClass('none');
					}
				}, 
				function () 
				{
					var id = this.id.substr(5,6);
					id++;

					if ( $('#menu-' + id) )
					{
						$('#menu-' + id).removeClass('none');
					}
			});
		}
	},

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

		for (var i=0;i < items.length; i++)
		{
			$(items[i]).hover(
				function () 
				{
					$(this).addClass('ShowItems');
				}, 
				function () 
				{
					$(this).removeClass('ShowItems');
				});
		}
	},

	Toggle : function (id)
	{
		$('#'+id).toggle();
	},

    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"
		);
    },

	popwin : function (url,width,height)
	{
		if ( !width ) width = '800';
		if ( !height ) height = '540';

	    var popupWin = window.open(url,'popupWin','width='+width+'px,height='+height+'px,left=100,top=100,menubar=no,status=no,toolbar=no,scrollbars=yes,resizable=no,screenX=100,screenY=100,directories=no,location=no');

		popupWin.focus();
        return false;
	},

    printView : function ()
    {
        Across.popwin('?print');
    },

	reload : function ()
	{
		window.location = window.location.href;
	},

	clearField : function (item)
	{
		$(item).attr('value', '');
	},



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

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

				if (data.error)
				{
					jQuery.each(data.items, function(i, val) {
						$('#newsletter_' + i).val(val);
				    });
				}
				else
				{
					Across.actualForm.reset();
					alert(data.message);
				}
			},
			"json"
		);
    },
		
	setHeaderAnim : function ()
	{
		Across.actual++;

		if (Across.actual >= HeadImages.length)
		{
			Across.actual = 0;
		}

		for (var i=0; i<HeadImages.length; i++ )
		{
			if (i == Across.actual)
			{
				$('#header_image').attr('src', '/uploads/headers/' + HeadImages[i]);
			}
		}
	}

/*
    toggle : function(point) {

        var points = document.getElementsByClassName('sub-menu');
        
        for (i=0;i<points.length;i++) 
        {
            if (points[i].id != point)
            {
                points[i].style.display = 'none';
            }
        }

        $(point).toggle();
        return false;
    },
*/
};

$(window).ready(function () {
	Across.setMenuBgs();
	Across.setMenu();
	setInterval(Across.setHeaderAnim,6000);
});