var blackscreen = {
	disable_close: false,
	opened: false,
	dom_used: '',
	dom_html: '',

	wait: function()
	{
		this.msg_open( '<div style="text-align: center; color: black; font-size: 18px; width: 600px;">Palaukite...</div>' );
		$("#blackscreen_close, .bs_close").hide();
	},

	close: function()
	{
		$("#blackscreen_bg").fadeOut('slow');
		$("#blackscreen_msg").fadeOut('slow');
		$("#blackscreen_close").slideUp();

		this.disable_close = false;
		this.opened = false;

		if( this.dom_used != '' )
		{
			$('#'+this.dom_used).html( this.dom_html );
		}

		this.dom_used = '';
		this.dom_html = '';
	},

	close_click: function()
	{
		if( !this.disable_close )
		{
			this.close();
		}
	},

	open: function()
	{
		if( !this.opened )
		{
			if($.browser.safari || $.browser.chrome) bodyelem = $("body");
			else bodyelem = $("html,body");

			$("#blackscreen_msg").css('top', bodyelem.scrollTop() );
			$("#blackscreen_bg").css('opacity', 0).show().fadeTo('slow', 0.5);
			$("#blackscreen_close").slideDown();
			$("#blackscreen_msg").css('opacity', 0).show().fadeTo('slow', 1);

			this.opened = true;
		}
	},

	dom_open: function( dom, close )
	{
		if( this.dom_used != dom )
		{
			this.dom_used = dom;
			this.dom_html = $('#'+dom).html();
			$('#'+dom).html( '' );

			var html = this.dom_html;
			if( close == true )
			{
				html = '<div class="bs_close" onclick="blackscreen.close();">&nbsp;</div>' + html;
			}


			this.msg_open( html );
		}
		else
		{
			location.href = $('.email_link:first').attr('href');
		}
	},

	msg_open: function( html )
	{
		this.msg( html );
		this.open();
	},

	msg: function( html )
	{
		$("#blackscreen_msg_inner").html('<div class="bs_close" onclick="blackscreen.close();">&nbsp;</div>'+html+'<div class="clr">&nbsp;</div>');
	},

	heading: function( h1 )
	{
		$("#blackscreen_msg_inner").prepend( '<div class="heading">'+h1+'</div>' );
	},

	show_map: function( addr, message )
	{
		blackscreen.msg_open( '<div id="bs_map" style="width: 600px; height: 400px;"></div>' );
		blackscreen.open();

		// show map
		var myOptions = {
		  zoom: 16,
		  mapTypeId: google.maps.MapTypeId.ROADMAP
		}

		if( document.getElementById(message) )
		{
			message = $('#'+message).html();
		}

		blackscreen.map = new google.maps.Map(document.getElementById("bs_map"), myOptions);

		// geocoder
		var geocoder = new google.maps.Geocoder();

		geocoder.geocode(
			{ 'address': addr },
			function(results, status) {
				if (status == google.maps.GeocoderStatus.OK)
				{
					// set a marker
					var image = 'http://www.komisas.lt/v2_media/needle.png';
					var marker = new google.maps.Marker({
						position: results[0].geometry.location,
						map: blackscreen.map,
						icon: image
					});

					// set info window
					var infowindow = new google.maps.InfoWindow({
						content: message
					});
					infowindow.open(blackscreen.map, marker);

					// set to center
					blackscreen.map.setCenter( results[0].geometry.location );
					blackscreen.map.panTo( results[0].geometry.location );
					blackscreen.map.panBy(100, -50);
				}
			}
		);


	}

}

/*
$(document).ready(function() {

	$("#blackscreen_msg").click(function () {
		blackscreen.close_click();
	});

});
*/
