// JavaScript Document
function ocultarMinis(){
	$(document.getElementById("miniProjectes")).hide("fast");
	$(document.getElementById("miniPerfil")).hide("fast");
}

function mostrarMini(div){
	ocultarMinis();
	$(document.getElementById(div)).show("normal");
}

function ocultar_todo(){
	$("#contacto").hide();
	$("#links").hide();	
	$("#colaboracions").hide();	
	$("#serveis").hide();	
	$("#perfil").hide();
	$("#presentacio").hide();
	$("#j2ee").hide();
	$("#loading1").hide();
	$("#projectes").hide();
}

function obrir(este){
var url = este+".html";
var div = "#"+este;
ocultar_todo();
$(div).show("normal", function(){
$(div).load(url, function(){
$(div).corner();
});
})
}

function obrir2(este){
	var url = este+".html";
var div = "#"+este;
ocultar_todo();
ocultarMinis();
$(div).show("normal", function(){
$(div).load(url, function(){
$(div).corner();
});
})
}



function obrirp(este){
var div = "#"+este;
ocultar_todo();
ocultarMinis();
$(div).show("normal");
}

function cerrar(este){
var div = "#"+este;
$(div).hide("normal");
}

function validarEmail(valor){
    re=/^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$/
    if(!re.exec(valor))    {
        return false;
    }else{
        return true;
    }
}

function preLoadImages(ruta) {
  var cache = [];
    // Arguments are image paths relative to the current page.
      var cacheImage = document.createElement('img');
      cacheImage.src = ruta;
      cache.push(cacheImage);

}

function inicio(){
	
		//formulari web ajax
	$().ajaxStart(function() {
		$(document.getElementById("loading1")).show("fast");
		$(document.getElementById("result1")).hide("fast");
		$(document.getElementById("button1")).hide("fast");
    }).ajaxStop(function() {
        $(document.getElementById("loading1")).hide("fast");
		$(document.getElementById("button1")).show("fast");
       // $(document.getElementById("result1")).fadeIn('slow');
    });


   // Interceptamos el evento submit
    $("#formWeb").submit(function() {	
		   if ((document.getElementById("nom").value.length < 4)||(validarEmail(document.getElementById("email").value) == false)||(document.getElementById("missatge").value.length < 10)){
			   alert("Error els camps amb el signe (!) són obligatoris, el email ha de ser valid.");
			   document.getElementById("nom").style.backgroundColor = "red";			   
			   document.getElementById("email").style.backgroundColor = "red";
			   document.getElementById("missatge").style.backgroundColor = "red";
			  document.getElementById("nom").style.color = "white";			   
			   document.getElementById("email").style.color = "white";
			   document.getElementById("missatge").style.color = "white";
			    return false;	
		   }else{
     	   $.ajaxSetup({ cache: false });
		 $.ajax({
                            contentType: "application/x-www-form-urlencoded",
                            beforeSend: function(objeto) {
                           document.getElementById("result1").innerHTML='Buscant servidor...';
						    $("#loading1").show("fast");
					        $("#button1").hide("fast");
							 },
                            type: "get",
                            url: "http://www.fecoal.org/form/envio.php",
							 error: function(objeto, quepaso, otroobj){
							  document.getElementById("result1").innerHTML='<b style="color:red;"> Error, no s\'ha pogut enviar el formulari.</b> Error: '+ quepaso +' Descripció: ' + otroobj +'<br>Pot enviar un email a <a href="mailto:info@ac-aplicacionsinformatiques.com">info@ac-aplicacionsinformatiques.com </a>';
							    $("#loading1").hide("fast");
								$("#button1").show("fast");
							},
                            data:  $("#formWeb").serialize(),
                            success: function(datos){
                                document.getElementById("result1").innerHTML='<img src="../images/ok.jpg" align="absmiddle"> Les seves dades s\'han enviat correctament.</b><br/> S\'ha enviat una copia a la seva direcció. </b>';
							    $("#loading1").hide("fast");
								$("#button1").show("fast");
								//$(document.getElementById("result1")).fadeIn('slow');
								  return false;
                                }
                    });  	
								
	}
			  return false;					
    });
	
	$("#contacto").hide();
	$("#links").hide();	
	$("#colaboracions").hide();	
	$("#serveis").hide();	
	$("#perfil").hide();
	$("#presentacio").hide();
	$("#j2ee").hide();
	$("#loading1").hide();
	$("#projectes").hide();
	$("#minilogos").hide();
	$("#emailBanner").hide();
	ocultarMinis();
	$(".links").corner();
	$(".contacto").corner();
	$(".colaboracions").corner();
	$(".projectes").corner();
	$(".serveis").corner();
	$(".contacto").corner();
	$(".perfil").corner();
	$(".idioma").corner();
	$(".negre").corner();
	$(".presentacio").corner();
	$(".j2ee").corner();
	$(".loading1").corner();
	
preLoadImages("../images/projectes/1.jpg");
preLoadImages("../images/projectes/2.jpg");
preLoadImages("../images/projectes/3.jpg");
preLoadImages("../images/projectes/4.jpg");
preLoadImages("../images/projectes/5.jpg");
	
		$("#minilogos").show(2000);
	$("#emailBanner").show(2000);
	}

function activarFotos(este) {
var url = este+".html";
var div = "#"+este;
ocultar_todo();
$(div).show("normal", function(){
$(div).load(url, function(){
$(div).corner();
galeria();
});
})
}

function galeria(){
	
	$('#slider').nivoSlider({
		effect:'random', //Specify sets like: 'fold,fade,sliceDown'
		slices:15,
		animSpeed:500,
		pauseTime:3000,
		startSlide:0, //Set starting Slide (0 index)
		directionNav:true, //Next & Prev
		directionNavHide:false, //Only show on hover
		controlNav:true, //1,2,3...
		controlNavThumbs:false, //Use thumbnails for Control Nav
        controlNavThumbsFromRel:false, //Use image rel for thumbs
		controlNavThumbsSearch: '.jpg', //Replace this with...
		controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
		keyboardNav:true, //Use left & right arrows
		pauseOnHover:true, //Stop animation while hovering
		manualAdvance:false, //Force manual transitions
		captionOpacity:0.8 //Universal caption opacity
		/*beforeChange: function(){},
		afterChange: function(){},
		slideshowEnd: function(){} //Triggers after all slides have been shown*/
	});
	//$(document.getElementById("projectes")).hide();
	

}


