$(document).ready(function() {
	splashdots = 0;
	$("#gallery div").cycle({
		fx : "scrollLeft",
		timeout : 5500,
		cleartype: true, 
		cleartypeNoBg: true,
		before : function() {
			if($(".splash .dots").size()==0) $(".splash").prepend("<div class=\"dots\"></div>");
		},
		after : function() {
			$(".dots").css("background-position","0px "+splashdots+"px");
			splashdots -=9;
		}
	});
	
	$(".gallery_slideshow li").prepend("<div class=\"lens\"></div>");
	
	$(".gallery_slideshow li").hover(function() {
		$(this).find(".lens").css("opacity",0.4).show().click(function() {
			aobj = $(this).parent().find("a");
			$.fn.colorbox({
				href : aobj.attr("href"),
				title : aobj.attr("title")
			});
		});;
	}, function() {
		$(this).find(".lens").hide();
	});
	
	$(".section").click(function() {
		if($(this).find("h2").attr("id")!="training_en") {
			location.href = $(this).find("h2 a").attr("href");
		} else {
			alert("Coming soon!");
		}
	});
	
	$(".form .submit button").click(function() {		
	
		$(".error").hide();
		errs = false;
		if($("#nome").val()=="") {
			$("#nome").parent().find("label span").show();
			errs = true;
		}
		if(!emailIsValid($("#email").val())) {
			$("#email").parent().find("label span").show();
			errs = true;
		}
		if($("#info").val()=="") {
			$("#info").parent().find("label span").show();
			errs = true;
		}
		
		if(!errs) $("form").submit();
		
		return false;
	});
	
	$(".form input, .form textarea").focus(function() {
		$(".error").hide();
	});
	
});

function emailIsValid(emailObj) {
	rt = true;
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if(!reg.test(emailObj)) rt = false;
	
	return rt;	
}

function init_map() {
  if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(45.659767,11.408272),6);		

		var mapControl = new GSmallMapControl();
		map.addControl(mapControl);

        var point = new GLatLng(45.659767,11.408272);
        map.addOverlay(new GMarker(point));		
  }
}
