/**
 * Author: Marco Dalicco  --- 02.09.2009
 * 
 * Elenco parametri :
 * parent       object			--> il nodo parent al quale l'oggetto mainCont sarà agganciato.
 * mainCont  	object[HTML element] 	--> div contenitore di tutto.
 * imgCont	object			--> div contenitore dove sarà creata la lista <ul>
 * a_img	object[array of imgItem]--> array contenente tutti gli oggetti imgItem da caricare
 * [arrowDx]	object[imgItem]		--> Freccia  DX alla quale associare l'azione di spostamento del box mainCont
 * [arrowSx] 	object[imgItem]		--> Freccia  SX alla quale associare l'azione di spostamento del box mainCont
 * 
 * 
 * 
 */

function Rullino(options){
    
    this.rullinoItem=null;
    
    
    //*********************** Options *****************************************
    this.options 	= options;
    this.parent		= (this.options['p_Parent'] 	!= null ? this.options['p_Parent']	: null);
    this.mainCont	= (this.options['p_MainCont']	!= null ? this.options['p_MainCont']   	: null);
    //this.arrowDx	= (this.options['p_ArrowDx']	!= null ? this.options['p_ArrowDx']    	: null);
    //this.arrowSx	= (this.options['p_ArrowSx']	!= null ? this.options['p_ArrowSx']    	: null);
    this.a_img		= (this.options['p_A_Img']	!= null ? this.options['p_A_Img']     	: null);
    this.ulCssId	= (this.options['p_UlCssId']	!= null ? this.options['p_UlCssId']     : null);
    //*************************************************************************
    
    
    //********************   public methods  **********************************
    //********************  SET *****************************************
    this.setParent  	=  function(p_Parent) 	{this.parent 	= (p_Parent   != null	? p_Parent 	: null);};
    this.setMainCont 	=  function(p_MainCont)	{this.mainCont	= (p_MainCont != null	? p_MainCont 	: null);};
    //this.setArrowDx 	=  function(p_ArrowDx)	{this.arrowDx 	= (p_ArrowDx  != null	? p_ArrowDx   	: null);};
    //this.setArrowSx 	=  function(p_ArrowSx)	{this.arrowSx 	= (p_ArrowSx  != null	? p_ArrowSx   	: null);};
    this.setA_img 	=  function(p_A_Img)	{this.a_img 	= (p_A_Img    != null	? p_A_Img 	: null);};
    //********************  FINE SET ************************************
    
    //******************** GET ******************************************
    this.getParent  	=  function() {return this.parent;	};	
    this.getMainCont 	=  function() {return this.mainCont;	};
    //this.getArrowDx 	=  function() {return this.arrowDx;	};
    //this.getArrowSx 	=  function() {return this.arrowSx;	};
    this.getA_img 	=  function() {return this.a_img;	};
    this.getUlCssId 	=  function() {return this.ulCssId;	};
    //********************  FINE GET ************************************  
    //************************ END public methods  ****************************
    
    
    //***** Aggiungo le immagini al contenitore ed imposto le azioni per le freccie ************************************
    this.render = function(){

			
		//this.setLogger(false, 'debug');
		//##################
		
		this.ul  = document.createElement('ul');
		this.ul.setAttribute('id', this.ulCssId);
		
		//aggancio gli li alle immagini e gli LI all'UL
		for(i=0; i < this.a_img.length; i++){
		    if(window.console) console.log("DEBUG [rullino] [render()] img:["+i+"]");
		   
		    var li = document.createElement('li');
		    this.a_img[i].setParent(li);
		    this.a_img[i].renderImg();
		    li.appendChild(this.a_img[i].imgElement);
		    //alert(li.parentNode.tagName);
		    this.ul.appendChild(li);
		}
		//this.mainCont=document.getElementById(this.mainCont);
		this.mainCont.appendChild(this.ul);
		
	
    };
    //****************END Render()*********************************************
    
    this.getLiWidth = function(){
	 if(window.console) console.log("DEBUG [rullino] [getLiWidth()] LI width:["+this.ul.firstChild.offsetWidth+"]");
	 return(this.ul.firstChild.offsetWidth);
    };
    
    this.spostaSx = function(){
	/*var firstChild =$(this.ulCssId).getElement(':first-child');
	var myClone = firstChild.clone().cloneEvents(firstChild);
	if(window.console) console.log("DEBUG [rullino] [spostaSx] ul > primoNodoFiglio:["+myClone+  "]");
	$(this.ulCssId).appendChild(myClone);
	firstChild.destroy();*/
	
	var lastChild = this.ul.lastChild;
	var firstChild = this.ul.firstChild;
	this.ul.insertBefore(lastChild,firstChild);
	
	
	//if(window.console) console.log("DEBUG [rullino] [spostaSx] ul > firstChild:["+firstChild+  "]");
    };
    
    this.spostaDx = function(){
	/*var firstChild =$(this.ulCssId).getElement(':first-child');
	var myClone = firstChild.clone().cloneEvents(firstChild);
	if(window.console) console.log("DEBUG [rullino] [spostaSx] ul > primoNodoFiglio:["+myClone+  "]");
	$(this.ulCssId).appendChild(myClone);
	firstChild.destroy();*/
	
	var firstChild = this.ul.firstChild;
	this.ul.appendChild(firstChild);
	//if(window.console) console.log("DEBUG [rullino] [spostaSx] ul > firstChild:["+firstChild+  "]");
    };
    
}

//Rullino.prototype = new JSLogger;

//EOF

