interval_id1 = "";

function loading(capa){
	document.getElementById(capa).innerHTML = '<img src="../img/loading.gif" />';
}

function cargaDadesCapa(dades,capa){
	//$('#'+capa).hide();
	document.getElementById(capa).innerHTML = dades;
	//$('#'+capa).fadeIn('slow');
}


TIME_WATCHING = 5000;

function slideSwitch(){

	clearInterval(interval_id1);

	var $active = $('#slideshow2 div.active');

	if ( $active.length == 0 ) $active = $('#slideshow2 div:last');

	// use this to pull the images in the order they appear in the markup
	var $next =  $active.next().length ? $active.next()
		: $('#slideshow2 div:first');

	$active.addClass('last-active');

	$next.css({opacity: 0.0})
		.addClass('active')
		.animate({opacity: 1.0}, 2000, function() {
			$active.removeClass('active last-active');
			interval_id1 = setInterval( "slideSwitch()", TIME_WATCHING );
		});
}


function activa_Slides(time1){
	interval_id1 = setInterval( "slideSwitch()", time1 );
}




function canviaProducte(quinProducte){
	clearInterval(interval_id1);
	loading('destacats');
	$.ajax({
		type: "POST",
		url: "canviaDestacat.php",
		evalScripts:true,
		data: "ajax=1&quinProducte="+quinProducte,
		success: function(msg){
			cargaDadesCapa(msg,'destacats');
			$('#destacats').fadeIn("slow");
		}
	});
}
