$(document).ready(function() {
	
	$('.image-div a').lightBox();
	
	
	$("#contact").submit(function() {
		
		var stop = 0;
		
		$('.required').each(function () {
			
			if($(this).val() == '') {
				alert('Proszę wypełnić wszystkie pola.');
				stop = 1;
				return false;
			}
		
		});

		if(stop) {
			return false;
		}
		
		var email = $('input[name="email"]').val();
		
		r = /^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i;
		
		
		if(!r.test(email)) { 
			alert('Nieprawidłowy adres email');
			return false;
		}
		
		$.post('/contact/', $(this).serialize(), function(data) {
			alert(data);
		});
		
		return false;
			
	});
	
	$("#newsletter").submit(function() {
		
		var email = $('input[name="email"]').val();
		
		r = /^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i;
		
		
		if(!r.test(email)) { 
			alert('Nieprawidłowy adres email');
			return false;
		}
		
		$.post('/newsletter/', $(this).serialize(), function(data) {
			alert(data);
		});
		
		return false;
			
	});
});



function flvPreview(id, width, height){

        var wleft = (screen.width - width) / 2;
        var wtop = (screen.height - height) / 2;

        window.open('/flash/play/'+id+'/','video_preview','top='+wtop+',left='+wleft+',width='+(width+50)+',height='+(height+100));
}

