var Across = {

	expressInstall : '/layout/swf/express_install.swf',
	flashVersion : '9.0.0',

	prepareContainer : function (container)
	{
		$('#'+container).empty();
        $('#'+container).append('<div id="flash_content"></div>');

		return 'flash_content';
	},

	installAnim : function (container, xml)
	{
		var flashfile = '/layout/swf/header.swf';
		var flashvars = {
			txtXml : xml
		};

		var params = {
			scale: "showall",
			//wmode : 'gpu',
            wmode : 'opaque',
			play : 'true',
			loop : 'true',
			allowFullScreen : 'false',
			allowScriptAccess : 'sameDomain'
		};

		var attributes = {
			id:"animation",  
			name:"animation"
		};

		swfobject.embedSWF(flashfile, Across.prepareContainer(container), "854", "502", Across.flashVersion, Across.expressInstall, flashvars, params, attributes);
	},

    getOffice : function(item, address, title, text)
	{
		$('#map_selector').css('display', 'none');

		if (arguments[4])
		{
			Across.getMap(address, title, arguments[4]);
		}
		else
		{
			Across.getMap(address, title);
		}

		$('div.office').hide().filter('#'+text).show();
        $('.contacts-list ul li a').css('fontWeight', 'normal').filter('#'+item).css('fontWeight', 'bold');
	},

    getMap : function (address, title) {

		if (arguments[2])
		{
			a = arguments[2];

			var latlng = new google.maps.LatLng(a[0], a[1]);

			Across.ShowMap(latlng, address, title)
		}
		else
		{
			var geocoder = new GClientGeocoder();

			geocoder.getLatLng(
				address,
				function(point) {

					if (!point) 
					{
						$('#map_canvas').css('visibility', 'hidden');
					}
					else 
					{
						Across.ShowMap(point, address, title);
					}
			});
		}
    },

	ShowMap : function (point, address, title)
	{
		var map = new GMap2(  document.getElementById('map_canvas') );

		map.setCenter(point, 13);
		var marker = new GMarker(point);
		map.addOverlay(marker);
		marker.openInfoWindowHtml('<strong>' + title + '</strong><br/> '+address);

		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());

        $('#map_canvas_frame').css('position', 'relative');
        $('#map_canvas_frame').css('top', '0px');
        $('#map_canvas_frame').css('left', '0px');
        //$('#map_canvas_frame').css('display', 'block');
		$('#map_canvas').css('visibility', 'visible');

	},

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