var baseURL = 'http://www.carraminyana.com/projecte';
			var seccioActiva = '<?= $seccioActiva ?>';
			$(document).ready(function() {
				initImatges();

				$("#seleccionat a").click(function (event) {
					$("#menu ul").slideToggle("slow");

					event.stopPropagation();
					event.preventDefault();
					return false; 
				});
				$("#menu ul li a").click(function (event) {
					$("#menu ul").slideToggle("fast");
					var htmlStr = '<a href="'+this.href+'" title="'+this.title+'" id="'+this.id+'" class="actiu">'+this.title+'</a>';
					seccioActiva = this.id;
					if( seccioActiva != 'links' ) {
						$("#seleccionat a").replaceWith(htmlStr);
						$("#seleccionat a").click(function (event) {
							$("#menu ul").slideToggle("slow");						
							event.stopPropagation();
							event.preventDefault();
							return false; 
						});
						$("#quadritus a.actiu").each(function (i) {
							this.className = this.className.replace('actiu','');
						});	
						$("#quadritus a[rel*="+this.id+"]").each(function (i) {
							this.className+=" actiu";
						});	
						$("#quadritus a").each(function (i) {
							url = this.href.split('/');
							this.href = baseURL + '/' + url[5] + '/' + seccioActiva;
						});
						event.stopPropagation();
						event.preventDefault();
						return false; 
					}
				});

				$("#quadritus a").tooltip({showURL: false, track: true, delay: 0});
				/*$("#quadritus a:not(.inactiu)").click(function (event) {
					parar();
					$.getJSON('/karra/json/projecte/' + this.id,
						function(data){
							$("#textClient").text(data.client);
							$("#textProjecte").text(data.projecte);
							if(data.url != '' ) {
								$("#linkProjecte").text(data.projecte);
								$("#linkProjecte").attr('title', data.projecte);
								$("#linkProjecte").attr('href', data.url);
								$("#linkProjecte").show();
							}
							else
							{
								$("#linkProjecte").hide();
							}
							$("#projecte_imatge ul").empty();
							$.each(data.imatges, function(i,item){								
								if( i == 0 ) var li = $('<li id="imatge'+i+'" class="primer">');
								else var li = $('<li id="imatge'+i+'">');
								$("#projecte_imatge ul").append(li.append($('<img width="500" height="390"/>').attr("src", item.imatge)));
							});
							initImatges();
					});
					event.stopPropagation();
					event.preventDefault();
					return false; 
				});*/
			});

			/*jQuery.fn.simpleGallery = function(contenidor, settings) {
				// define defaults and override with options, if available
				// by extending the default settings, we don't modify the argument
				settings = jQuery.extend({
					sentit: 'endavant',
					temps_imatge: 4000,
					boto_anterior: 'button#anterior',
					boto_seguent: 'button#seguent',
					indicador_numero: 'span#primer',
					animation: {opacity: "hide"},
					animationOptions: { duration:500 }
				}, settings);

				.animate(settings.animation), settings.animationOptions;
				.animate({opacity: 't'}, { duration:500 } );
			}*/

			var imatge_actual;
			var imatge_anterior;
			var total_imatges;
			var interval_reproduir;
			var reproduint = false;
			var parat = false;
			var reproduir = true;
			var sentit = 'endavant';
			var imatges;
			var temps_fade_in = 1000;
			var temps_fade_out = 1000;
			var temps_imatge = 4000;
			var boto_anterior = 'button#anterior';
			var boto_seguent = 'button#seguent';
			var indicador_numero = 'span#primer';
			var contenidor = '#projecte_imatge';	
			var imatge_a_mostrar = null;					

			function initImatges() {
				// Inicialitzar variables

				imatge_actual = 0;
				imatge_anterior = 0;	
				interval_reproduir = null;
				reproduint = false;
				parat = false;
				reproduir = true;
				sentit = 'endavant';
				imatges = $(contenidor + ' ul li');
				total_imatges = imatges.length;
				imatge_a_mostrar = null;			

				$('#primer').text('1');
				$('#segon').text(total_imatges);
				$('#segon').text(total_imatges);
				$('#segon').attr('title', total_imatges );
				if( total_imatges > 1 ) 
				{
					$("#paginacio").show('fast');
					$("#numeros").show('fast');
					iniciar();
					if ( boto_anterior != null ) {
						$(boto_anterior).click(function (event) {
							anterior();
							event.stopPropagation();
							event.preventDefault();
							return false; 
						});
					}

					if ( boto_seguent != null ) {
						$(boto_seguent).click(function (event) {
							seguent();
							event.stopPropagation();
							event.preventDefault();
							return false; 
						});
					}
				}
				else
				{
					$("#paginacio").hide('fast');
					$("#numeros").hide('fast');
				}
			}

			function playpause() {
				if(reproduir) 
				{
					imatge_a_mostrar = imatge_actual;
					parar();
				}
				else
				{	
					slideShow();
					iniciar();
				}
			}

			function iniciar() {
				interval_reproduir = setInterval('slideShow()', temps_imatge);
				reproduir = true;
			}

			function parar() {
				clearInterval(interval_reproduir);
				parat = true;
				reproduir = false;		
			}	

			function seguent() {				
				if ( reproduir ) {
					imatge_a_mostrar = imatge_actual;
					parar();				
					setTimeout('seguent()',temps_fade_out+50);
				} else {	
					if ( imatge_a_mostrar != null) {
						imatge_actual = imatge_a_mostrar;			
						imatge_a_mostrar = null;
					}
					if( seguentImatge() ) canviarImatge();
				}
			}

			function anterior() {
				if ( reproduir ) {
					imatge_a_mostrar = imatge_actual;
					parar();				
					setTimeout('anterior()',temps_fade_out+50);
				} else {			
					if ( imatge_a_mostrar != null) {
						imatge_actual = imatge_a_mostrar;			
						imatge_a_mostrar = null;
					}	
					if( anteriorImatge() ) canviarImatge();
				}
			}

			function seguentImatge() {
				imatge_anterior = imatge_actual;
				imatge_actual += 1;
				if ( imatge_actual > (total_imatges-1) ) {
					imatge_actual = 0;
				}
				return true;
			}

			function anteriorImatge() {
				imatge_actual = imatge_anterior;
				imatge_anterior -= 1;
				if ( imatge_anterior < 0 ) {
					imatge_anterior = (total_imatges - 1);
				}
				return true;
			}

			function canviarImatge() {		

				reproduint = true;

				if(imatge_anterior==0) {
					$(imatges[imatge_anterior]).attr('class','');
				}

				$(imatges[imatge_anterior]).fadeOut(temps_fade_out, function()
					{
						$(imatges[imatge_actual]).fadeIn(temps_fade_in, function() { reproduint = false; } );
					}
				);				
				/*$(imatges[imatge_anterior]).animate('fade', temps_fade_out);
				$(imatges[imatge_actual]).animate('fade', temps_fade_in, null, function() { reproduint = false; } );*/
				if ( indicador_numero != null ) {
					$(indicador_numero)[0].title = (imatge_actual+1);
					$(indicador_numero).html((imatge_actual+1));
				}
			}

			function slideShow() {
				if ( total_imatges > 1 ) {
					if ( sentit == 'endavant') {
						seguentImatge();
					} else {
						anteriorImatge();
					}
					canviarImatge();
				}
			}			