function validateMail(address)
{
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

	if(reg.test(address) == false)
		return false;
	else
		return true;
}

function overlay()
{
	if(!$('.overlay').width())
	$('body').append('<div class="overlay"></div>');
	
	$('.overlay').height($(document).height()).css('opacity', '0.8');
	
	$('.overlay').fadeIn();
}

function jmap_load(coorx, coory)
{
	$('#map').jmap('init', {'mapType':'map','mapCenter':[coorx, coory], 'mapZoom':14});
	$('#map').jmap('AddMarker', {'pointLatLng': [coorx, coory]});
}

link = document.URL.split('/');

var language = link[3];
var folder = link[4];
var module = link[5];
var action = link[6];

$(document).ready(function() {

	if(folder=='galeria' || folder=='referencje')
	$('.gallery a').lightBox();
	
	if(folder=='kontakt' || folder=='dostawca' || folder=='odbiorca')
	{
		$('#oferta').hide();
		$('#dojazd').show();
	}
	else
	{
		$('#oferta').show();
		$('#dojazd').hide();
	}


	$('#round_1').flash({
		src: 'media/'+language+'/flash/1.swf',
		width: 159,
		height: 240,
		wmode: 'transparent' 
	});

	$('#round_2').flash({
		src: 'media/'+language+'/flash/2.swf',
		width: 159,
		height: 240,
		wmode: 'transparent' 
	});
	$('#round_3').flash({
		src: 'media/'+language+'/flash/3.swf',
		width: 159,
		height: 240,
		wmode: 'transparent' 
	});
	$('#round_4').flash({
		src: 'media/'+language+'/flash/4.swf',
		width: 159,
		height: 240,
		wmode: 'transparent' 
	});
	$('#round_5').flash({
		src: 'media/'+language+'/flash/5.swf',
		width: 159,
		height: 240,
		wmode: 'transparent' 
	});
	$('#round_6').flash({
		src: 'media/'+language+'/flash/6.swf',
		width: 159,
		height: 240,
		wmode: 'transparent' 
	});




	$('.new_window').click(function() {
	
		$(this).attr('target', '_blank');

	});

	$('.menu_4').mouseover(function() {
		$('#sub').css('display', 'block');
	});
	
	$('#sub').mouseleave(function() {
		$(this).hide();
	});

	$('.btn_send').livequery('mouseover', function() {
		$(this).css('backgroundPosition', '0px -30px');
	});

	$('.btn_send').livequery('mouseout', function() {
		$(this).css('backgroundPosition', '0px 0px');
	});

	$('.btn_resize').click(function() {

		overlay();

		loc = document.URL.split('#');
		
		if($.browser.msie)
		$('.map_handler').css({'left': '50%'});
		else
		$('.map_handler').animate({'left': '50%'});

		return false;
		
	});

	$('.map_close').click(function() {
		$('.overlay').fadeOut();
		$('.map_handler').css('left', '-50%');
		return false;
	});


	$('.btn_send').livequery('click', function() {
		req = 'module='+module+'&';
		error=false;
		$('input, textarea').not('.btn_send').each(function(i) {
			if($(this).val()=='')
			{
				$(this).parent().css('backgroundPosition', '0px -100%');
				error=true;
			}
			else
			$(this).parent().css('backgroundPosition', '0px 0px');
			
			value = this.value;
			value = value.replace('&', '$amp;');
			req += this.name+'='+value+'&';
			
		});

		if(!validateMail($('input[name=email]').val()))
		{
			$('input[name=email]').parent().css('backgroundPosition', '0px -100%');
			error=true;
		}
		

		if(error==false)
		{
			$('form').fadeOut();
			$('.loading').fadeIn();

			$.ajax({
				type: "POST",
				url: "extras/send.php",
				data: req+'&language='+language,
				success: function(data){
					$('.loading').fadeOut('normal', function(){$(this).after('<p>'+data+'</p>')});
				}
			});
		}
		return false;

	});

	jmap_load(50.262324, 19.094056);

});

function getLink(id)
{
	$.history.load(id);
}