// Interactivity Flash and Javascript
//Initialisation global variables


var myFamily = "nescafe_collection";
var myName = "alta_rica";

function initDisplayContent(family, name) {
    myFamily = family;
    myName = name;
	displayContent();
}

/*Function mask content*/
function displayContent(){
	var arrProduct = document.getElementById("descriptionProduct").getElementsByTagName("div");
	var nChildren = arrProduct.length;	
	for(var i = 0; i<nChildren; i++){
		var nameProduct = arrProduct[i].id;
		arrProduct[i].style.display = (nameProduct == myName) ? 'block' : 'none';
	}
}
/*When Flash is ready*/
function carouselInitOnLoad(){
	var swfProduct=(typeof(swfProduct)!="undefined")?swfProduct:swfobject.getObjectById("swf_product");	
	
	if (swfProduct.loaded==true){
		clearTimeout(swfProduct.timer);
		swfProduct.sendNameProduct(myName);
		return true;	
	}
	
	/*looping till flash function is available*/
	if (typeof(swfProduct.sendNameProduct)=="undefined"){	
		swfProduct.loaded=false;
		swfProduct.timer=setTimeout("carouselInitOnLoad()",100);
		return true;
	} else {
		swfProduct.loaded=true;		
		swfProduct.timer=setTimeout("carouselInitOnLoad()",100);
		return true;	
	}	
	
}

function sendId(str){
	myName = str;	
	displayContent();
}

function animationPicture(){
	var myListOfPicture = $("#descriptionReceipt img"); 
	
	myListOfPicture.each(function(){	
		$(this).appendTo("#listPicture");
		$(this).css('float','left');
		$(this).css('position','relative');
	});
	
	var firstItemIntoTheList = $("#listPicture img:first"); 
	firstItemIntoTheList.css('visibility','visible');
}

function animationTextContent(){
	var myListOfItem = $("#descriptionReceipt ul").children();
	var myFirstItem = $("#descriptionReceipt ul li:first");
		myFirstItem.addClass("active");	
		
	myListOfItem.each(		
		function(){
			$(this).hover(
				function(){
					//Remove class for the first Item
					myFirstItem.removeClass("active");
					//Add The class to the selected item
					$(this).addClass("active");
					//Display the currentImage
					displayImage($(this).attr("id"));
					
				}, function(){
					$(this).removeClass("active");
				}
			);
		}
	);
}

function displayImage(myIDContent, myFlag){
	var myListOfPicture = $("#listPicture img"); 
	var $listPicture = $("#listPicture");
	
	myListOfPicture.each(function(){	
		var myIDPicture = $(this).attr("id").split("-")[0];
		
		if(myIDContent == myIDPicture){
			var myLeftPosition = $(this).position().left;
			$listPicture.stop();
			$listPicture.animate({ left: "-" + myLeftPosition + "px" }, 800);
		}
	});
}

$(function(){
    plo_counter=0;
	animationPicture();
	animationTextContent();
});


/*
function recalc_timer(){
	var myListOfItem = $("#descriptionReceipt ul").children();
	//remove class active on each li into #descriptionReceipt
	myListOfItem.each(function(){
		if($(this).hasClass("active")){
			$(this).removeClass("active");
		};	  
	});
	//addClass on the current Item
	$(myListOfItem[plo_counter]).addClass("active");
	setTimeout(function(){nextItem(plo_counter);}, 10000);
};

function nextItem(cpt){
	plo_counter = plo_counter + 1;
	var myListOfItem = $("#descriptionReceipt ul").children();
	
	if(plo_counter == 3){ plo_counter = 0;}
	
	var obj = swfobject.getObjectById("swf_receiptMini");
	if(obj&&typeof(obj.sendNameReceipt)!="undefined"){
		obj.sendNameReceipt(myListOfItem[plo_counter].id);
	};
	return false;
};

function sendToJava(myString){
	//console.log(myString);	
}

*/
