var Across = {

	actual : 0,

	definedURL : false,
	working    : true,

	parepareLinks : function ()
	{
		$('a.nav').unbind('click');
		var points = $('a.nav').click(function() 
		{
			Across.getSubPage(this.href);

			this.blur();
			return false;
		});
	},

	getSubPage : function (url)
	{
		Across.working = true;
		
		var Host =  window.location.protocol + '//' + window.location.host;
		
		Across.activeURL = '#' + url.replace(Host, '');

        $.post(url,
            'EzGET=getPage',
            function(data) {

				$('#data').html(data.text);

				window.location = '#' + url.replace(Host, '');

				var loc = window.location.href.split('#', 2);
				
				Across.definedURL = loc[1];
				Across.parepareLinks();
				Across.working = false;
				
				if (data.gallery) 
				{
					// init gallery: Gallery.init(imageHolder, imageWrapperWidth, imageCountHolder, nextButton, prevButton)
					Gallery.init($("div#image-holder"), 630, $('#count'), $("a#next-image"), $("a#previous-image"));
				}

            },
            "json"
		);
	},

	checkDefinedUrl : function ()
	{
		var loc = window.location.href.split('#', 2);

		if (loc[1])
		{
			if (loc[1] != Across.definedURL)
			{
				if (!Across.working)
				{
					Across.getSubPage(loc[1]);
				}

			}
		}
	},

	getDefinedURL : function () 
	{
		var loc = window.location.href.split('#', 2);

		if (loc[1])
		{
			Across.definedURL = loc[1];
			Across.getSubPage(loc[1]);
		}
/*
		t = setTimeout(function() {
			Across.checkDefinedUrl();
		}, 100); 
*/
	},

    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"
		);
    },
	
    clearField : function (item)
    {
        $(item).attr('value', '');
    },
	swapimg :function(obj,img)
	{
		$(obj).attr('src',img);
	},
	defswap : function(obj,img)
	{
		$(obj).attr('src',img);
	}
};

$(window).ready(function () {
//	Across.parepareLinks();
//	Across.getDefinedURL();
});
