function setImg(imatge){
		
	//REMOVE CONTENT DIV
	$('#visor').html('');
	//SET LOADING
	$('#visor').addClass('loading');
	var srcImg='./img-apartat-310-245-1-0/'+imatge;
	var img = new Image();
	
	$(img).load(function () {
	    //$(this).css('display', 'none'); // .hide() doesn't work in Safari when the element isn't on the DOM already
	    $(this).hide();
	    var link='<a href="./upload/apartat/'+imatge+'" class="fansi"></a>';
	    $('#visor').append(link);
	    $('#visor').removeClass('loading');
	    $('#visor a').append(this);
	    $(this).fadeIn();
	    $("a.fansi").fancybox({ 'zoomSpeedIn': 300, 'zoomSpeedOut': 300});
	}).error(function () {
	    // notify the user that the image could not be loaded
	}).attr('src', srcImg);
}
function paginaGaleria(id,apt){
	$.get("llistat_fotos.php?pag="+id+"&apartat="+apt,function(data){
		$('#llistaFotos').html(data);
	} );
}
function veureGaleria(){
	$('#llistaFotos').slideDown(10,function(){
		$('#scroll, #prodsLoad').jScrollPane({showArrows:false, scrollbarWidth: 10});	
	});	
}
function veureVideo(video){
	var srcVideo='<object width="310" height="245"><param name="movie" value="http://www.youtube.com/v/'+video+'&hl=en&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'+video+'&hl=<?=$lang?>&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="310" height="245"></embed></object>';
	$('#visor').html(srcVideo);
}

function setProd(id,lang,imga){
	$('#producte').html('');
	$('#producte').addClass('loading');
	$.get("lib/fitxa_producte_lateral.php?id="+id+"&lang="+lang,function(data){
			var srcImg='./img-producte-308-175-1-0/'+imga;
			var img = new Image();
			$(img).load(function () {
				$('#producte').removeClass('loading');
				$('#producte').hide();
				$('#producte').html(data).fadeIn(500);
				$("a.fansi").fancybox({ 'zoomSpeedIn': 300, 'zoomSpeedOut': 300});
				
			}).error(function () {
	    	// notify the user that the image could not be loaded
			}).attr('src', srcImg);

		
	} );
	
}
function filter(opcio,lang,apt){
	var valor;
	if(opcio=='typ'){
		valor=$('#tipus').val();
		$('#color').find('option:first').attr('selected', 'selected').parent('select');
		$('#ordenar').find('option:first').attr('selected', 'selected').parent('select');
	}
	if(opcio=='col'){
		valor=$('#color').val();
		$('#tipus').find('option:first').attr('selected', 'selected').parent('select');
		$('#ordenar').find('option:first').attr('selected', 'selected').parent('select');
	}
	if(opcio=='ord'){
		valor=$('#ordenar').val();
		$('#tipus').find('option:first').attr('selected', 'selected').parent('select');
		$('#color').find('option:first').attr('selected', 'selected').parent('select');
	}
	if(valor==''){valor='res';}
	$.get("lib/llista_productes.php?op="+opcio+"&val="+valor+"&apt="+apt+"&lang="+lang,function(data){
		$('#prodsLoad').html(data);
	});
}

function veureDadesEntrega(el) {
	if (el.checked==true) {
		$("#dadesentrega").slideUp('fast');
	}
	else {
		$("#dadesentrega").slideDown('fast');
	}
	
}


function addFav(num) {
	//Amago el link que he clicat
    $("#wish"+num).animate({ opacity:0 }, 1500);
   
   //Inserto a la sessiÃ³
	$.ajax({
		type: "GET",
		async: false,
		url: "http://"+location.hostname+"/ajax_addwish.php",
		data: "wish="+num,
		success: function(msg){
			if (msg>0) {
				//Actualitzo el nÃºmero de desitjos
				$("#desitjos span").html(msg);
			}
		}
	});
}

function dialeg(id,lang) {
	
	
}

function addCarro(lang) {
	var quantitat=$('#quantitat').val();
	var id=$('#preuMidaFitxa').val();
	var color=$('#combinacio').val();
	$.ajax({
		type: "GET",
		async: false,
		url: "http://"+location.hostname+"/lib/ajax_carritu.php",
		data: "op=add&id="+id+"&col="+color+"&quant="+quantitat+"&lang="+lang,
		success: function(msg){
			if (msg>0) {
				//Actualitzo el nÃºmero de desitjos
				$("#totalCarro").html(msg+"&euro;");
			}
		}
	});
	
	activaPopup(id,lang)
}

function addFav(lang) {
	var id=$('#preuMidaFitxa').val();
	$.ajax({
		type: "GET",
		async: false,
		url: "http://"+location.hostname+"/lib/ajax_carritu.php",
		data: "op=favorit&id="+id+"&lang="+lang,
		success: function(msg){
			if (msg!=0) {
				//Actualitzo el nÃºmero de desitjos
				$("#dialog").html(msg);
				$('#pantalla').fadeIn('fast');
				$('#dialog').fadeIn('fast');
			}
		}
	});
	
	
}

function activaPopup(id,lang){
	$.ajax({
		type: "GET",
		async: false,
		url: "http://"+location.hostname+"/lib/ajax_carritu.php",
		data: "op=confirmed&id="+id+"&lang="+lang,
		success: function(msg){
			if (msg) {
				//Actualitzo el nÃºmero de desitjos
				$("#dialog").html(msg);
				$('#pantalla').fadeIn('fast');
				$('#dialog').fadeIn('fast');
			}
		}
	});
}

function tancaPopup(){
	$('#pantalla').fadeOut('fast');
	$('#dialog').fadeOut('fast');
	$('#fancy_outer').fadeOut('fast');
}

function veurePais(camp,div,op){
	if(op==1){
		var pais=$('#idPais'+div).val();
		var comunitat=$('#idComunitat'+div).val('');
		var provincia=$('#idProvincia'+div).val('');
	}
	var pais=$('#idPais'+div).val();
	var pais2=pais.split('-');
	var comunitat=$('#idComunitat'+div).val();
	if(comunitat!='' && comunitat!=undefined){
		var comunitat2=comunitat.split('-');
		var comun=comunitat2[0];
	}else{
		var comun=comunitat;
	}
	var provincia=$('#idProvincia'+div).val();
	$.get("../lib/paisos.php?div="+div+"&camp="+camp+"&pais="+pais2[0]+"&comunitat="+comun+"&provincia="+provincia,function(data2){
		$('#'+div).html(data2);
		if(pais!='' && pais!=undefined){
			$('#'+camp).val(pais2[0]);
			if(pais2[1]==1){reset(camp);}
		}else{
			//PER FER UN RESET A LES OPCIONS
			$('#'+camp).val('');
		}
		if(comunitat!='' && comunitat!=undefined){
			$('#'+camp).val(comunitat2[0]);
			if(comunitat2[1]==1){reset(camp);}
		}
		if(provincia!='' && provincia!=undefined){
			$('#'+camp).val(provincia);
		}
	});
	
	$('#scroll').jScrollPane({showArrows:false, scrollbarWidth: 10});
}
function reset(camp){
	$('#'+camp).val('');
}
