/*
EGFadeBox
Enrico Galli 2010 http://www.egw.it
NON MODIFICARE - DO NOT CHANGE
*/

var $box = jQuery.noConflict();
var rImg = -1;
var rImgTemp = new Array(); 

/*
funzione che disegna le varie caselle (Box) - This draw the box(es)
nBox = nome della casella - Box name
sBox = classe stile della casella - Box class style
anitime = tempo di animazione fadein/out - fadein/out animation time 
pTime = tempo di visualizzazione dell'immagine nella casella - image displaying time
arrBox = array da usare per la casella in questione - set the array to use for current box
dOrd = ordine di Visualizzazione (ORD = ordinato RND = casuale) - dsplay order (ORD = ordered RND = random)
grBox = gruppo lightbox - lightbox group
*/

function creaBox(nBox,sBox,aniTime,pTime,arrBox,dOrd,grBox)
{
	
	
	if (dOrd == undefined) {dOrd = defDOrd};
	if (aniTime == undefined) {aniTime = defAniTime};
	if (pTime == undefined) {pTime = defPTime};
	if (grBox == undefined) {grBox = defGrBox};
	if (arrBox == undefined) {arrBox = defArrBox};
	document.write("<div class=\"" + sBox + "\" id=\"" + nBox + "\"><div class=\"i_" + sBox + "\" id=\"i_" + nBox + "\"></div></div>");
	
	$box("#i_" + nBox).fadeOut("fast");
	
	$box(document).ready( function() {
		avviaBox(nBox,aniTime,pTime,arrBox,dOrd,grBox)
	});
}

//funzione che avvia la casella - This start the box(es)
function avviaBox(nBox,aniTime,pTime,arrBox,dOrd,grBox)
{
	if (dOrd == "ORD")
	{
		if (rImgTemp[nBox] == undefined || rImgTemp[nBox] == arrBox.length) 
		{
			rImgTemp[nBox] = 0; 
		} 
		else 
		{ 
			rImgTemp[nBox] = rImgTemp[nBox] + 1; 
		}		
	}
	else
	{
		rImgTemp[nBox] = Math.floor(Math.random()*arrBox.length);
	}
	
	
	
	nHtml = "<a href=\"" + imgP + arrBox[rImgTemp[nBox]][1] + "\" rel=\"lightbox[" + grBox + "]\"";
	if (arrBox[rImgTemp[nBox]][2] != undefined) { nHtml = nHtml + " title=\"" + arrBox[rImgTemp[nBox]][2] + "\" "};
	nHtml = nHtml + ">";
	nHtml = nHtml + "<img class=\"boxMiniImg\"  id=\"img_" + nBox + "\" src=\"" + imgP + arrBox[rImgTemp[nBox]][0] + "\"></a>";
		
	$box("#i_" + nBox).html(nHtml);
	$box("#img_" + nBox).load(function() {
		$box("#i_" + nBox).fadeIn(aniTime).delay(pTime).fadeOut(aniTime,function(){
			avviaBox(nBox,aniTime,pTime,arrBox,dOrd,grBox);
		});
	});

}

