

// Fiches

var WallProdDefs=new Array();

function getImagesFromServer(xmlinfo) {
	
	var lProdDefs=new Array();
	lProdDefs=ProdXmltoArray(xmlinfo);
    return lProdDefs;
    
/*	for (var i=0; i<lProdDefs.length; i++) {
		var nprod=getIndFollowingWSType(lProdDefs[i].Type);
		
	    // class fiches by categorie	
		var imgsAct=imagesmin[nprod];
		var nimgs=imgsAct.length;
		imgsAct[nimgs]=lProdDefs[i].Pict5;
		imagesmin[nprod]=imgsAct;
		
		imgsAct=wall_images[nprod];
		nimgs=imgsAct.length;
		imgsAct[nimgs]=lProdDefs[i].Pict1;
		wall_images[nprod]=imgsAct;
		
	}
	*/
}


function getLocalImages() {
	
	// Merchandising
	var imgsMerch = new Array();
	for (var i=0; i<10; i++) { imgsMerch[i]="Merch"+i+".png";	}
	wall_images[wall_images.length]=imgsMerch;
	var imgsMerchMin = new Array();
	imgsMerchMin[0]="merchandising.jpg";
	for (var i=1; i<=10; i++) {	imgsMerchMin[i] = "Merc"+i+".png";	}
	imagesmin[imagesmin.length]=imgsMerchMin;
	
	// Marketing
	wall_images[wall_images.length] = new Array("Marketing1.png");
	imagesmin[imagesmin.length] = new Array("marketing.jpg","Market1.png");
	
	// Prise de vue
	wall_images[wall_images.length]=new Array("Prisedevue1.png", "Prisedevue2.png");
	imagesmin[imagesmin.length]=new Array("prise-de-vue.jpg", "Prisedvue1.png", "Prisedvue2.png");
	
	// Prepresse
	wall_images[wall_images.length]=new Array("Prepresse1.png", "Prepresse2.png");
	imagesmin[imagesmin.length]=new Array("pre-presse.jpg", "Prepres2.png");
	
	// Edition
	wall_images[wall_images.length]=new Array();
	imagesmin[imagesmin.length]=new Array("edition.jpg");
	
	// PLV
	var imgsPLV=new Array();
	for (var i=0; i<20; i++) {		imgsPLV[i]="PLV"+i+".png";	}
	wall_images[wall_images.length]=imgsPLV;
	var imgsPLVmin=new Array();
	imagesmin[0]="PLV.jpg";
	for (var i=1; i<=20; i++) {		imgsPLVmin[i]="PLVm"+i+".png";	}
	imagesmin[imagesmin.length]=imgsPLVmin;
	
	// Packaging
	wall_images[wall_images.length]=new Array("Packaging1.png", "Packaging2.png");// Pack1.html
	imagesmin[imagesmin.length]=new Array("packaging.jpg","Packag1.png", "Packag2.png");
	
	// Logistique
	var imgsLogist = new Array();
	for (var i=0; i<5; i++) {		imgsLogist[i]="Logistique"+i+".png";	}
	wall_images[wall_images.length]=imgsLogist;
	var imgsLogistmin=new Array();
	imgsLogistmin[0]="logistique.jpg";
	for (var i=1; i<=5; i++) {		imgsLogistmin[i]="Logistiq"+i+".png";	}
	imagesmin[imagesmin.length]=imgsLogistmin;

}

var maxActivities=30;
var wall_images=new Array(); 	wall_images.length=maxActivities;
var wall_textes=new Array(); 	wall_textes.length=maxActivities;
var imagesmin  =new Array();   	imagesmin.length=maxActivities;

var WallProds=new Array();
var PopupProds=new Array();


function createWall(xmlinfo, automatic) {
	
	// All main activities -> fill list with first image of every activity
	
	// Calculate what to show
	// If precise activity
	// - All of activity ; if more than 7 subactivities of activity do random between subactivities
	// - All of activity then random betweem main imgs except actual activity, finally sub other
	// Else random by activity
	
	// getLocalImages();
	var lProdDefs = new Array();
	lProdDefs = ProdXmltoArray(xmlinfo);
	
	if (automatic==undefined || automatic==null || automatic!=1) {
		WallProds=lProdDefs;
	}
	else {
		
		//var debuginfo="WallProds :"; for (var j=0; j<WallProds.length; j++) debuginfo+=WallProds[j].Title+", "  ;

		// filtre newprods for new ones
		var newProds = new Array();
		for (var i=0; i<lProdDefs.length; i++) {
			var newprod=true;
			for (var j=0; j<WallProds.length; j++) {
				if (lProdDefs[i].Title==WallProds[j].Title) {
					newprod=false;
				}
			}
			if (newprod==true) {
				newProds[newProds.length]=lProdDefs[i];
			}
		}
		lProdDefs=newProds;
	}
	
	//newitems=""; for (var j=0; j<lProdDefs.length; j++) newitems+=lProdDefs[j].Title+", "  ;
	//debuginfo=debuginfo+"\nNew : "+newitems+"\n";
	//console.debug(debuginfo);
	
	// Miniatures, types=n° activité
	show_activities(lProdDefs, automatic);
	
	
	/*	var myIndx=getIndFollowingWSType(type);
	if (myIndx==-1) {
	}
	else {
	    // Images de l'activité
	     var subimgs=new Array();subimgs = getRandomArray(imagesmin[myIndx]);
		
		// if not 8 imgs add random between imgs des activités restants
		if ( mainimgs.length<8 ) {
			// Enlever l'activité de l'utilisateur
			var mainimgsleft=new Array(0, 1, 2, 3, 4, 5, 6, 7);
			mainimgsleft.splice(myIndx,1);
			mainimgsleft=takeRandom(mainimgsleft, 8 - mainimgs.length);
			for (var i=0; i<mainimgsleft.length; i++) {
				var idx=mainimgsleft[i];
				// add his images to list for wall
			}
		}
	}	
*/
}

function highlightthumb(i,tf) {
	//1 queue by img

	if (tf==true) {
		
		// Title -> absolute position at bottom
		var bordercolor="#bbb";
		var nidT=getNodeRef("wallthumbtitle"+i);
		nidT.style.backgroundImage="";
		nidT.style.position = 'absolute'; 
		nidT.style.left = '-1px'; 
		nidT.style.bottom = '-17px'; 
		nidT.style.border = '2px solid '+bordercolor; 
		nidT.style.width='100%';
		nidT.style.borderRadius="3px";
		nidT.style.backgroundColor = bordercolor;
		
		// Hide thumb decoration
		var nidI=getNodeRef("wallthumbimgspace"+i);
		nidI.style.visibility="hidden";
		
/*		var nid1=getNodeRef("mur_imglnk"+(i+1));
		Effect.Queues.get(nid1.id).invoke('cancel');
		nid1.style.position="relative"; //nid1.style.top="0px"; nid1.style.left="0px"; 
		nid1.style.float="none";
		new Effect.Morph(nid1.id, {
			  style: 'top:-3px; left:-3px; padding:3px; border-radius:5px; background:#7cc; width:140px; height:90px;', //  CSS Properties
			  duration: 0.2,
			  queue: { position: 'end', scope:nid1.id, limit:1}
			}
		);
*/				
		// Image
		var nid1=getNodeRef("wallthumbimg"+(i));
		Effect.Queues.get(nid1.id).invoke('cancel');
		nid1.style.position="absolute";  
		nid1.style.position="relative";  
		nid1.style.float="none";
		nid1.style.border="0px solid "+bordercolor;
		nid1.style.borderRadius="6px";
		new Effect.Morph( nid1.id, {
			  style: 'left:-10px; top:-5px; border:2px; border-radius:10px; background:white; width:160px; height:85px;', //  CSS Properties
			  duration: 0.25,
			  delay:0,
			  queue: { position: 'end', scope:nid1.id, limit:1}
			}
		);
		
	}
	else {
		
/*		var nid0=getNodeRef("mur_imglnk"+(i+1));
		nid0.style.position="relative"; 
		nid0.style.float="none";
		new Effect.Morph(nid0.id, {
			style: 'top:0px; left:0px; padding:0px; background:white; width:140px; height:90px; border-radius:0px; ', //  CSS Properties
			duration: 0.1, // Must take some more time then appearence
			queue: { position: 'end', scope:nid0.id},
			delay: 0.15,
			afterFinish : function( ) {	$(nid0).setStyle({ position:"static", float:"left" });	  }
			}
		);	
*/		
		/*nid.style.height="90px";	 nid.style.width="140px"; nid.style.padding="0px";
		nid.style.position="static"; nid.style.float="left";  nid.style.display="block"; 		 
		nid.style.backgroundColor="";*/

		var nid0=getNodeRef("wallthumbimg"+(i));
		nid0.style.position="relative"; 
		nid0.style.float="none";
		new Effect.Morph(nid0.id, {
			style: 'top:0px; left:0px; width:140px; height:75px; border:0px;', //  CSS Properties
			duration: 0.2, 
			queue: { position: 'end', scope:nid0.id},
			delay: 0,
			afterFinish : // Replace elements
				function( ) {
				
					// - Image
					$(nid0).setStyle({ position:"static", float:"left" });  
					nid0.style.borderRadius="0px";
					// - ,, decoration
					var nidI=getNodeRef("wallthumbimgspace"+i);
					nidI.style.visibility="visible";
					
					// - Title
					var nidT = getNodeRef("wallthumbtitle"+i);
					nidT.style.position = 'static'; 
					nidT.style.border = '0px'; 
					nidT.style.borderRadius="0px";
					nidT.style.width="142px";
					nidT.style.backgroundColor = '#8E8E8E'; //

					
					var bgimgtitle="";
					if (i==7) { bgimgtitle="r";} else { if (i==5) bgimgtitle="l";}
					bgimgtitle="images/img-mur/bg_murtitle"+bgimgtitle+".gif";
					nidT.style.backgroundImage = "url('"+bgimgtitle+"')";				
				}
			}
		);	
		
		
	}
	//nid.style.border = (tf) ? '1px solid #5d5' : "";
	//nid.style.height = (tf) ? '98px' : "100px";


}

// Create wall pimages=miniatures, types=n° activité 
function show_activities(pProducts, automatic) {
	
	// Type, Title ShortDescr Validated	ForComm Pict1.. 5
	var nitems = (pProducts.length<8) ? pProducts.length : 8;
	for (var i=0; i<nitems; i++) {
		
		// Fill wall with Thumbnail structure if not already done so
		var nid= "mur_img"+(i+1);
		if (getNodeContent(nid)=="") {
			var script="onmouseup=\"javascript:showPopup2("+ i +");\" "+
			" onmouseover=\"javascript:highlightthumb("+i+","+true+")\" onmouseout=\"javascript:highlightthumb("+i+","+false+")\"";
			
			var imgpath="http://"+urlimgs+"/Images/"+pProducts[i].Pict5;
			// background:url(\""+imgpath+"\") #9bc no-repeat' " +
			var nidlnk = "mur_imglnk"+(i+1);
			var pages_selected="<div id=\""+nidlnk+"\" "+script+ " style=\"float:left; display:none; cursor:pointer;\" >"+		
			createWallThumb(i, imgpath )+"</div>";
			setNodeContent(nid, pages_selected);
		}

	}
	
	popupwallthumbs(nitems, pProducts, automatic);

}

var firstload=true;

function popupwallthumbs(pnitems, pProducts, automatic) {
	
	// Show the thumbs
	var nitems=pnitems;
	var cdelay=0;
	var arr=[0,1,2,3,4,5,6,7];
	if (automatic==undefined || automatic==null) automatic=0;
	if (automatic==1 && nitems>0)
		nitems=1;
	
	var nImg=0;
	for (var i=0; i<nitems; i++) {
		
		// Choose item
		var rdm = Math.floor(Math.random()*arr.length);
		nImg=arr[rdm];
		arr.splice(rdm, 1);

		// Product info
		var product=pProducts[i];
		//showThumb(nImg, product);
		

		// Show item

		// cdelay=(i==0) ? 0 : (0.5-(i*(1/16))); // Speedup
		//var nid="mur_imglnk"+(i+1);
		//new Effect.Fade  (nid, {duration:0.4 });
		//new Effect.Grow(nid, {duration:0.4, direction:'center', queue: { position: 'end', scope:nid }}); 
	}
	//new Effect.multiple(["mur_imglnk1", "mur_imglnk2","mur_imglnk3","mur_imglnk4","mur_imglnk5","mur_imglnk6","mur_imglnk7","mur_imglnk8"],Effect.Fade, {duration:0.15, speed:0, queue:{position:'end', scope:"wall"} } );

	var delayappear=0;
	
	var start=0; var end=nitems;
	
	// Ne changer qu'une 
	if (automatic==1 && nitems>0) {
		
		start=nImg; end=nImg+1;
		
		// memorise this one is displayed
		WallProds[nImg]=pProducts[0];
	}
	
	// Show thumb (with effects)
	
 	// Hide items (ne pas cacher à la première affichage) 
	if (firstload==false) {
		for (var i=start; i<end; i++) {
			var nid="mur_imglnk"+(i+1);
			new Effect.Fade(nid, {duration:0.3, from:1, to: 0, delay:0 });
		}
		delayappear=0.4;
    }
	else {
		firstload=false;
		/*for (var i=start; i<end; i++) {
			var nid="mur_imglnk"+(i+1);
			var imgnode = getNodeRef(nid);
			if (imgnode!=undefined && imgnode!=null)
				imgnode.style.display="";
		}*/
	}
	// Show items	
	for (var i=start; i<end; i++) {
		var nid = "mur_imglnk"+(i+1);
		var product=pProducts[i];
		new Effect.Appear(nid, {duration:1.5, from:0, to: 1, delay:delayappear,
			  beforeSetup : function(effect) { 
				var nImg=effect.element.id.substr(10);
				showThumb(nImg );  
			  },
			  afterFinish : function(effect) {
				  emptyqueue();
					/*var nImg=effect.element.id.substr(10);
					preloadImage(nImg);*/
			  }
		});
		
	}
	// C'est comme une queue en fait :
	//new Effect.multiple(["mur_imglnk1", "mur_imglnk2","mur_imglnk3","mur_imglnk4","mur_imglnk5","mur_imglnk6","mur_imglnk7","mur_imglnk8"],Effect.Appear, {duration:0.2, speed:0, from:0, to:1, delay:delayappear, queue:{position:'end', scope:"wall"} } );

	
}

var itemsinqueue=0;

function emptyqueue() {
	
	itemsinqueue=0;
	var queue = Effect.Queues.get('global');
	queue.each(function(effect) { itemsinqueue++; });
	if (itemsinqueue==0 ) 
		preloadImages();

}


var picts=new Array();

function preloadImages() {
	
	var nImg=0;
	var baseurl="http://"+urlimgs+"/Images/";
	//i-1; if (nImg<0) nImg=0;
	for (var nImg=0; nImg<WallProds.length; nImg++) {
		
		var prodimgs=new Array();
		if (document.images) {
			
			for (var i=0; i<5; i++) {
				
				var pict="";
				var prod=WallProds[nImg];
				switch (i) {
					case 0 : pict=prod.Pict1; break;
					case 1 : pict=prod.Pict2; break;
					case 2 : pict=prod.Pict3; break;
					case 3 : pict=prod.Pict4; break;
					case 4 : pict=prod.Pict5; break;
				}
				pict=pict.replace(/ /gi, "");
				if (pict.length>0) {
					var imglink = baseurl + pict;
					prodimgs[i]= new Image(); 
					prodimgs[i].src=imglink; 
				}
			}

		}
		
		picts[nImg]=prodimgs;
	}
	
}


function showThumb(pnImg) {
	
	var nImg=pnImg-1;
	var product=WallProds[nImg];

	// - Title categorie
	var nAct=getIndFollowingWSType(product.Type);
	var title=activityNames[nAct];
	setNodeContent("wallthumbtitle"+nImg, title);
	
	// - Title product
	var imgnodeid="mur_imglnk"+(nImg+1);
	var imgnode = getNodeRef(imgnodeid);
	if (imgnode!=undefined && imgnode!=null) {
		imgnode.title=product.Title;
		imgnode.style.display="";
	}
	
	// - Img product
	var imgpath="http://"+urlimgs+"/Images/"+product.Pict5;
	var imgnodeid="wallthumbimg"+nImg;
	var imgnode = getNodeRef(imgnodeid);
	if (imgnode!=undefined && imgnode!=null)
		imgnode.style.backgroundImage="url('"+imgpath+"')";
	
	var imgnodeid="wallthumbimgspace"+nImg;
	var imgnode = getNodeRef(imgnodeid);
	if (imgnode!=undefined && imgnode!=null)
		imgnode.src=imgpath;
	
}

function createWallThumb(nImg,pImg) {
	
	var imgsfold="images/img-mur/";
	var imgpath=pImg;
	var imgcadre=imgsfold+"bg_murimg.gif";
	
	var script=" onmouseover=\"javascript:highlightthumb("+nImg+","+true+")\" onmouseout=\"javascript:highlightthumb("+nImg+","+false+")\"";
	var style = "background:white no-repeat; background-size:100%; padding:0px; url('"+imgpath+"')";
	var returnstr="<div id=\"wallthumbimg"+nImg+"\" style=\"float:left; clear:both; width:140px; height:75px; padding:0px; overflow:visible; "+style+ "\"" + script +">";
		// Img
		var style="display:block; float:left; clear:left; border:1px solid #8E8E8E;";
		returnstr+="<img id=\"wallthumbimgspace"+nImg+"\" "+"src=\""+imgpath+"\""+
		" style=\"width:138px; height:73px; "+style+"\"></img>"; //	
		
		// Title
		var bgimgtitle="bg_murtitle";
		if (nImg==7) { bgimgtitle+="r";	} else if (nImg==5) {bgimgtitle+="l";}
		
		// radius
		//	if (nImg==7) {stylearrounded+="border-bottom-right-radius:8px;";} else { if (nImg==5) stylearrounded+="border-bottom-left-radius:8px;";}
		//returnstr+="<div style=\"float:left; clear:left; width:140px; height:15px; padding:0px; background:url('"+imgsfold+bgimgtitle+".gif') no-repeat; text-align:center\">";
		var style="float:left; clear:left; ";
		returnstr+="<div id=\"wallthumbtitle"+nImg+"\" style=\"font-size:11px; line-height: 13px; color:white; width:143px; font-weight:bold; padding:1px 0px 1px 0px; border-right:0px; "+
		style+"height:15px; background:url('"+imgsfold+bgimgtitle+".gif') no-repeat #8E8E8E; text-align:center \" "+"></div>";
		//returnstr+="</div>";
	
	returnstr+="</div>";

	return returnstr;
	
}


function getRandomArray(pArray, pN) {
	
	// Take at most 7 thumbs for this activity
	// More than 7 of same activity -> do random else show all images of activity
	var resultarray = new Array();
	var subimgsrandom = new Array();
	subimgsrandom=pArray[0];
	if (subimgsrandom.length>7) subimgsrandom = takeRandom(subimgsrandom,pN);
	for (var i=0; i<subimgsrandom.length; i++) {
		resultarray[resultarray.length]=subimgsrandom[i];
	}
	return resultarray;
}


// POPUP


selected_activityimg_idx=0;
var selected_activity=0;

function showpopup() {
	
	var page="mur/getFiches.php";
	//parameters: {company: 'example', limit: 12}
	new Ajax.Request(page, {
	    method:	"post",
	    onSuccess: function(transport){
	      var xmlinfo = transport.responseText || "no response text";
	      if ( (ifError(xmlinfo))==false) {
		      var products=ProdXmltoArray(xmlinfo);

		  	  showPopup2(null, products);
	      }
	    },
	    onFailure: function(){ alert('Sorry something went wrong on loading of the page '+page ); }
	});
	
}

//var selectedWallImg=0;

// shows item in list following idx
function showPopup2(pIdx, list) {
	
	var action="";
	var idxdisplay=pIdx;
	var lProdDefs=new Array();
	if (pIdx!=null) {

		// Popup from wall
		if (list==null) {
			
			action		= "Call popup from wall";
			
			// Initialize popuplist
			PopupProds	= new Array();
			PopupProds[0]=WallProds[pIdx];
			selected_activityimg_idx=0;
			lProdDefs 	= PopupProds;
			idxdisplay=0;
			
			// popupimg
			$( 'popup_img' ).setStyle({display:"none"});
	
			// Effects
			/*var nid="mur_imglnk"+(pIdx+1);
			selectedWallImg=pIdx+1;
			Effect.Puff(nid, { 	duration : 0.5,	direction:'center',	queue: { position: 'end', scope:'popupimgwall', limit:2 },
				afterFinish : function( ) {	$(nid).setStyle({width:'150px', height:'100px', display:'block', opacity:1});}
			});	*/
			/*Effect.Opacity(nid, { duration : 1.5,	from:0,	to:1,	queue: { position: 'end', scope:'popupimgwall', limit:2 }});*/
		}
		
		// From items already shown 
		else lProdDefs=list;
	}
	
	// From new downloaded items(list)
	else {
		
		action="Refresh popup";
		
		lProdDefs=list;
		if (lProdDefs.length>0) {
			
			// Take a product from downloaded serie not already in representation list
			var found=false; var selectedidx=0;
			if (PopupProds.length>0) {
				var i=0;
				while ( (found==false) && (i<lProdDefs.length) ) {
					
					var ok=true;
					// Test si fiche téléchargée n'est pas déjà présente
					for (var j=0; j<PopupProds.length; j++) {
						var newitem = lProdDefs[i];
						if (PopupProds[j].Title==newitem.Title ) 						
							ok=false;
					}
					if (ok==true) {
						found=true;
						selectedidx=i;
					}
					else i++;
				}
			}
			else found=true;

			// Add item to list
			if (found==true) {
				var selecteditem=lProdDefs[selectedidx];	//console.debug("selected item:"+selecteditem.Title);
				PopupProds[PopupProds.length] = selecteditem;
				idxdisplay=selectedidx; // for display
			}	
		}
		selected_activityimg_idx=PopupProds.length-1; // show last one
		//console.debug("selidx: "+selected_activityimg_idx);
	}
	
	// Show it
	if (lProdDefs.length>0) {
		
		//selected_activityimg_idx = (selected_activityimg_idx!=null) ? selected_activityimg_idx : 0; 
		
		// Title
		//var nact=getIndFollowingWSType(lProdDefs[idx].Type);
		//var title=capitalize(activityNames[nact]);
		
		// Show Popupwindow with title
		if (!fenetre1visible) {
			//fenetre1.setTitle(title);
			fenetre1.show();
			fenetre1.center();

			fenetre1visible=true;
		}
		
		showFicheinPopup(lProdDefs[idxdisplay]);

	}
	else 
		alert("Strange, items list is empty ("+action+").");
	
}

// Popup
var screencontent=""+
"<table style='width:690px; padding:0px'>"+
"<tr style='padding:0px'><td style='padding:0px 0px 0px 10px; text-align:left'><h2 id='popup_title' style='color:gray; padding:2px; '></h2></td>"+
"<td id='popup_nxtbtn' style='vertical-align:top; text-align:left; padding:5px 10px 0px 15px'>" +
	"<img id='popup_prevbtn' src='mur/previous.gif' title='Produit pr&eacute;c&eacute;dent' style='vertical-align:top; cursor:pointer' onmouseup='prevImage()' ></img>"+
	"<span id='popup_loadedimgs' style='text-align:left; color:gray; cursor:pointer'></span>"+
		"<div id='popup_nimg' style='display:none; padding:3px 3px 0px 3px'></div>" +
		"<img src='./mur/next.gif' title='Produit suivant' style='vertical-align:top; cursor:pointer' onmouseup='nextImage()' ></img>" +
	"</td></tr>" +
"<tr>"+
"<td style='padding-left:10px; vertical-align:top; width:320px; height:320px;'>"+
"<div style='width:320px; height:320px; padding:0px; border:0px; overflow:hidden'>"+

  "<img id='popup_img' style='background-size:320px 320px; background-repeat:no-repeat;"+
  "height:320px; width:320px; display:none; position:relative; border:solid thin #cff'></img>"+
  //"<img id='popup_img' src='mur/loading.gif' height=320px width=320px style='display:none; position:relative; background:white; border:solid thin #cff'></img>"+
  "<img id='popup_img2' height=320px width=320px style='display:none; border:solid thin #eef'></img>"+
  
"</div><div id='popupimglnk'></div></td>" +
"<td id='popup_text' style='width:350px; vertical-align:top; text-align:left; padding:0px 15px; color:gray'></td>"+
"</tr><tr>" +
"<td id='popup_thumbs' style='padding:2px 0px 8px 10px'></td><td></td>" +
"</tr></table>";


// Navigation : hide / show btns & index parcours

function ShowActivityinPopup() {
	
	//getNodeRef("popup_nxtbtn").style.visibility = (selected_activityimg_idx < PopupProds.length-1) ? "visible" : "hidden";
	getNodeRef("popup_prevbtn").style.visibility = (selected_activityimg_idx >0) ? "visible" : "hidden";
	var nimg=selected_activityimg_idx+1;
	setNodeContent("popup_nimg", nimg+"" );
	
}


function nextImage() {
	
	if (selected_activityimg_idx < (PopupProds.length-1) ) {
		
		selected_activityimg_idx++;
		showFicheinPopup(PopupProds[selected_activityimg_idx]);
		
		/*var limitedarray=new Array();
		limitedarray[0]=PopupProds[selected_activityimg_idx];
		showPopup2(0, limitedarray);*/
		
	}
	else 	// load new ones*/
		showpopup();

}



function prevImage() {
	
	if (selected_activityimg_idx >0) {
		selected_activityimg_idx--;
		showFicheinPopup(PopupProds[selected_activityimg_idx]);
	}
}


function showPopupImg(nImg) {
	
	selected_activityimg_idx=nImg;
	showFicheinPopup(PopupProds[selected_activityimg_idx]);

}


// Common String and number functions

function removeExtension(pStr) { return (pStr.substr(0, pStr.lastIndexOf("."))); }

function takeRandom(pArray, number) {
	
	var newArray=pArray;
	while (newArray.length > number) {
		var randomnum=Math.floor(Math.random()*newArray.length);
		newArray.splice(randomnum,1);
	}
	return newArray;
}




