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

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

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

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

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

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

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

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

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

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

	setMap : function (top)
	{
		$('#map-anim').css('backgroundPosition', '0px '+top+'px');
	},
	restoreMap : function ()
	{
		$('#map-anim').css('backgroundPosition', '0px 4192px');
	},
	
	setCounties : function ()
	{

		$('area').click(function() 
		{

			if ( $('#county_'+this.id).attr('checked') )
			{
				$('#county_'+this.id).attr('checked', false);
				$('.s_'+this.id).hide();
			}
			else
			{
				$('#county_'+this.id).attr('checked', true);
				$('.s_'+this.id).show();
			}		
		});
	}
};

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