$(document).ready(function() {
	$("#bpbe_staffettaform1").validate({
		errorPlacement : function(error, element) { },
		rules: {
/*			email: {
				required: function(element) {
					if ($('input[name=phone]').val() != '') {
						return false;
					}
					else {
						return true;
					}
				}
			},
			phone: {
				required: function(element) {
					if ($('input[name=email]').val() != '') {
						return false;
					}
					else {
						return true;
					}
				}
			},*/
			bpbe_v: {
				required: true,
				remote: {
					url: "fileadmin/template/php/vcaptcha.php",
					type: "get",
					data: {
						s: function() {
							return $("input[name=bpbe_v]").val();
						}
					}
				}
			}
		}
	});
	$("#bpbe_staffettaform2").validate({
		errorPlacement : function(error, element) { },
		rules: {
/*			email: {
				required: function(element) {
					if ($('input[name=phone]').val() != '') {
						return false;
					}
					else {
						return true;
					}
				}
			},
			phone: {
				required: function(element) {
					if ($('input[name=email]').val() != '') {
						return false;
					}
					else {
						return true;
					}
				}
			},*/
			bpbe_v: {
				required: true,
				remote: {
					url: "fileadmin/template/php/vcaptcha.php",
					type: "get",
					data: {
						s: function() {
							return $("input[name=bpbe_v]").val();
						}
					}
				}
			}
		}
	});
});
$(window).load(function() {
    bgHeight();
    staffettaWidth();
    staffettaAtBottom();
    
    $('#staffetta').backgroundScroll({
        scrollSpeed: 50,
        backgroundImageWidth: 1024
    });
});

$(window).resize(function() {
	bgHeight();
    staffettaAtBottom();
    staffettaWidth();
});

$(window).scroll(function() {
    staffettaAtBottom();
});

function bgHeight(){
    $("#bg").css('height','100%');
	if($("#bg").height()<$(window).height()-$("#bgTop").outerHeight()-150){
        $("#bg").height($(window).height()-$("#bgTop").outerHeight()-150);
    }
}

function staffettaAtBottom(){
    //$("#staffetta").css({position: "absolute",top:($(window).scrollTop()+$(window).height()-$("#staffetta").height())+"px"})
    $("#staffetta").css({position: "absolute",top:($(document.body).height()-$("#staffetta").height())+"px"})
}

function staffettaWidth(){
    $("#staffetta").css('width','100%');
	if($(window).width() < $(document).width()){
 		$("#staffetta").width($(document).width());
 	}
 	else{
 		$("#staffetta").width($(window).width());
 	}
}