$(document).ready(function() {
  $(function() {
			 
			 if (jQuery('#scroll li').size() > 5) { jQuery('#scroll').jCarouselLite({
			auto: 1000,
			speed: 1000,
			visible: 7,
			circular: true,
			pauseOnHover: true,
			scroll: 1
			}); } 
			else { jQuery('#scroll').jCarouselLite({
			auto: 1
			}); }
			
			
  });
  
});

/***********************************************
* IFRAME Scroller script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

//Specify speed of scroll. Larger=faster (ie: 5)
var scrollspeed=cache=1

//Specify intial delay before scroller starts scrolling (in miliseconds):
var initialdelay=500

function initializeScroller(){
	if (document.getElementById("datacontainer")){
		dataobj=document.all? document.all.datacontainer : document.getElementById("datacontainer")
		dataobj.style.top="180px"
		setTimeout("getdataheight()", initialdelay)
	}
}

function getdataheight(){
	thelength=dataobj.offsetHeight
	if (thelength==0)
		setTimeout("getdataheight()",10)
	else
		scrollDiv()
}

function scrollDiv(){
	dataobj.style.top=parseInt(dataobj.style.top)-scrollspeed+"px"
	if (parseInt(dataobj.style.top)<thelength*(-1))
		dataobj.style.top="180px"
	setTimeout("scrollDiv()",40)
}

if (window.addEventListener)
	window.addEventListener("load", initializeScroller, false)
else if (window.attachEvent)
	window.attachEvent("onload", initializeScroller)
else
	window.onload=initializeScroller

var actiu=false;
function showGrups(){
	if (!actiu) 
	{
		$("#receptes").load('/empresa/carregarGrups');
		actiu = true;
	}
	else 
	{
		$("#receptes").empty();
		actiu=false;
	}
}
function showFamilies(){
	if (!actiu) 
	{
		$("#families").load('/produccio/produccioCarregarFamilies');
		actiu = true;
	}
	else 
	{
		$("#families").empty();
		actiu=false;
	}
}
function showProductes(id){
	$("#content").load('/produccio/carregarProductes/'+id);
	$("#menuProductes").addClass("selected");
	$("#menuNoticies").removeClass("selected");
	$("#menuPresentacio").removeClass("selected");
	$("#menuLocalitzacio").removeClass("selected");
}

function showReceptes(id){
	$("#content").load('/empresa/carregarReceptes/'+id);
	$("#menuRecepta").addClass("selected");
	$("#menuNoticies").removeClass("selected");
	$("#menuPresentacio").removeClass("selected");
}

function cercarProductesDistribucio(){
	obj = document.getElementById('text').value;
	if(obj != "") 
	{
		document.getElementById("resultat").innerHTML = "";
		$("#taulaDistProductes").hide();
		$("#contenidorProductes").load('/distribucio/cercarProductes/'+obj);
	}
	else document.getElementById("resultat").innerHTML = "Has d'introduir un text al cercador";
	
	return false;
}

function cercarProductesProduccio(){
	obj = document.getElementById('text').value;
	
	if(obj != "") 
	{
		document.getElementById("resultat").innerHTML = "";
		$("#taulaDistProductes").hide();
		$("#contenidorProductes").load('/produccio/cercarProductes/'+obj);
	}
	else document.getElementById("resultat").innerHTML = "Has d'introduir un text al cercador";
	
	return false;
}

function showSubfamilies(id){
	$("#contenidorProductes").load('/distribucio/carregarSubfamilies/'+id);
}

function carregarProducteDistribucio(id){
	obj = document.getElementById('#subfamilia_'+id);
	$("#subfamilia_"+id).load('/distribucio/carregarProductes/'+id);
}

function carregarProducteProduccio(id){
	obj = document.getElementById('#producte_'+id);
	$("#producte_"+id).load('/produccio/carregarProducte/'+id);
}

function carregarProducteProduccioCerca(id){
	obj = document.getElementById('#producte_'+id);
	$("#producte_"+id).load('/produccio/carregarProductesCerca/'+id);
}

function carregarProducteDistribucioCerca(id){
	obj = document.getElementById('#subfamilia_'+id);
	$("#subfamilia_"+id).load('/distribucio/carregarProductesCerca/'+id);
}

function carregarRecepta(id){
	obj = document.getElementById('#recepta_'+id);
	$("#recepta_"+id).load('/carregarRecepta/'+id);
}

