

var _SERVIDORWEB	=	"www.bewebdisseny.com/";
var _folder			=	"";
var _ruta_base		=	"http://" + _SERVIDORWEB + _folder;


var SELECCIONAT=1;
var quantes_fotos=1;

jQuery(document).ready(function(){ 
	jQuery(".thumb_bn").hover(
		function () { //sobre
			id=jQuery(this).attr("id");
			id=id.substr(2);
			jQuery('#bn'+id).stop(true).animate({opacity: 0},500);
		},
		function () { //fora
			id=jQuery(this).attr("id");
			id=id.substr(2);
			jQuery('#bn'+id).stop(true).animate({opacity: 1},500);
		}
	);
}); 


function sobre_thumb(id){
	jQuery('#bn'+id).stop(true).animate({opacity: 0},500);
}
function fora_thumb(id){
	jQuery('#bn'+id).stop(true).animate({opacity: 1},500);
}

function borde(id){
	jQuery('#thumb'+id).stop(true).animate({opacity: 1},200);
}
function fora_borde(id){
	if(SELECCIONAT!=id){
		jQuery('#thumb'+id).stop(true).animate({opacity: 0},200);
	}
}
function amagar_borde(id){
	jQuery('#thumb'+id).stop(true).animate({opacity: 0},1);
}

function iniciar_borde(projecte, id){
	if(id!=SELECCIONAT){
		amagar_borde(id)
	}else{
		jQuery("#foto_gran").attr("src","imatges/"+projecte+"/"+id+".jpg");	
	}	
}

function canvi_foto(projecte, id){
	if(id!=SELECCIONAT){
		jQuery("#foto_gran").attr("src","imatges/blanc.gif");	
		
		jQuery("#foto_gran").attr("src","imatges/"+projecte+"/"+id+".jpg");	
		jQuery('#thumb'+SELECCIONAT).stop(true).animate({opacity: 0},200);
		SELECCIONAT=id;
	}
}


function amb_tecles(projecte) {
    var e = document;
    
    e.onkeydown = function (evt) {
        /**
         * after this, evt will be a keyboard event
         */
        evt = (evt) ? evt : ((window.event) ? window.event : "");
        
        if (evt) {
            switch (evt.keyCode){
				case 37: 	//anterior
							anterior_foto(projecte);
							break;	
				case 39: 	//seguent
							seguent_foto(projecte);
							break;	
			}
        }
    }
}


function seguent_foto(projecte){
	if(SELECCIONAT<quantes_fotos){
		tmp=parseInt(SELECCIONAT)+1;	
	}else{
		tmp=1;	
	}
	window.location.hash=tmp;
	borde(tmp)
	canvi_foto(projecte, tmp);
}

function anterior_foto(projecte){
	if(SELECCIONAT>1){
		tmp=parseInt(SELECCIONAT)-1;	
	}else{
		tmp=quantes_fotos;	
	}
	window.location.hash=tmp;
	borde(tmp)
	canvi_foto(projecte, tmp);
}


function marcar_input(qui){
	jQuery(qui).removeClass("input-no-actiu").addClass("input-actiu");
}
function sortir_input(qui){
	jQuery(qui).removeClass("input-actiu").addClass("input-no-actiu");
}
function marcar_input2(qui){
	jQuery(qui).removeClass("textarea-no-actiu").addClass("textarea-actiu");
}
function sortir_input2(qui){
	jQuery(qui).removeClass("textarea-actiu").addClass("textarea-no-actiu");
}



function noEnter(oEvento){ 
    var iAscii;      
    if (oEvento.keyCode) 
        iAscii = oEvento.keyCode; 
    else if (oEvento.which) 
        iAscii = oEvento.which; 
    else 
        return false;  
    if (iAscii == 13) {
		oEvento.cancelBubble = true;
		oEvento.returnValue = false;
        return false; 
	}
	return true;
}

function validar_contacte(){
		document.getElementById("contacte_enviar").style.display="none";	
		document.getElementById("contacte_enviant").style.display="block";	
		enviar_comentari();
}

function reiniciar_contacte(){
	document.getElementById("contacte_enviar").style.display="block";	
	document.getElementById("contacte_enviant").style.display="none";	
	document.getElementById("contacte_enviat").style.display="none";
	document.getElementById("contacte_no_enviat").style.display="none";
}

var oXmlHttp;
function enviar_comentari(){
	if(!oXmlHttp){
		oXmlHttp=zXmlHttp.createRequest();
	}else if (oXmlHttp.readyState!=0){
		oXmlHttp.abort();
	}

	cadena=_ruta_base+"php_aux/enviar_contacte.php";
	params = "nom="+document.formulari.nom.value+"&email="+document.formulari.email.value+"&comentaris="+document.formulari.comentari.value+"&telefon="+document.formulari.telefon.value;
	
	oXmlHttp.open("post",cadena,true);
	oXmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	oXmlHttp.setRequestHeader("Content-length", params.length);
	oXmlHttp.setRequestHeader("Connection", "close");
	
	oXmlHttp.onreadystatechange = function(){
		if(oXmlHttp.readyState==4){	
			if(oXmlHttp.status==200){
				var resposta=oXmlHttp.responseText;
				if(resposta=="ok"){
					document.getElementById("contacte_enviant").style.display="none";	
					document.getElementById("contacte_enviat").style.display="block";					
				}else{
					document.getElementById("contacte_enviant").style.display="none";	
					document.getElementById("contacte_no_enviat").style.display="block";	
				}
				setTimeout('reiniciar_contacte()', 2000)
			}else{
				document.getElementById("contacte_enviant").style.display="none";	
				document.getElementById("contacte_no_enviat").style.display="block";
				setTimeout('reiniciar_contacte()', 2000)
			}
		}
	};
	oXmlHttp.send(params);
}

