//fpv=3
fp_ajax_postloaderjs_man.scriptsondemandloaded_register("fpmod_plantillas_seccionbkrotativos");

function fpmod_plantillas_seccionbkrotativos(parent){
	this.parent=parent;
	this.nbktitcont=3;
	this.rottime=5000;
	this.onpuase=false;
	this.pauseOnMouseOver=false;
	
	this.init_cont=function(){
		if(!this.numcont){
			return false;
		}
		
		this.do_rotate();
		this.parent.show_dom_elem("allcont");
		this.parent.hide_dom_elem("loader");

		var _this=this;
		this.intervalrotate=setInterval(function(){_this.on_rotate_interval()},this.rottime);
	
	
	}
	
	this.on_rotate_interval=function(){
		if(this.onpuase){
			return false;	
		}
		this.do_rotate();
	}
	this.do_rotate=function(){
		if(!this.numcont){
			return false;
		}
		var contindex=this.rotation_index;
		for (var i=1;i<=this.nbktitcont;i++){
			if(contindex>=	this.numcont){
				contindex=0;	
			}
			this.set_bk_cont(i,contindex);
			contindex++;
		}
		this.rotation_index++;
		if(this.rotation_index>=	this.numcont){
			this.rotation_index=0;	
		}
		
	}
	this.set_bk_cont=function(bkindex,contindex){
		var code="titcont_"+bkindex;
		var c="";
		var nodes=this.bkcontnodes[code];
		if(nodes){
			var _item=nodes.item(contindex);
			if(_item){
				c=_item.firstChild.data;	
			}
		}
		var bk=	this.parent.set_dom_elem_cont(code,c);
	}
	this.setPause=function(val){
		this.onpuase=val;
	}
	this.setPauseOnMouseOver=function(){
		this.pauseOnMouseOver=true;
		var _divmain=this.parent.get_dom_elem_elem("disbks");	
		if(_divmain){
			var _this=this;
			_divmain.onmouseover=function(){
				_this.setPause(true);	
			}
			_divmain.onmouseout=function(){
				_this.setPause(false);	
			}
		}
	}
	this.init=function(){
		if(this.pauseOnMouseOver){
			this.setPauseOnMouseOver();
		}
		this.parent.do_request();
		
	}
	this.reset_cont=function(){
		
		if(this.intervalrotate){
			clearInterval(this.intervalrotate);	
		}
		this.rotation_index=0;
		this.bkcontnodes=new Object();
		this.parent.hide_dom_elem("allcont");
		this.parent.show_dom_elem("loader");
		this.numcont=0;	
	}
	this.onsendreq=function(){
		this.reset_cont();
	}
	this.load_bkcontnodes=function(node){
		this.bkcontnodes=new Object();
		if(!node){
			return false;	
		}
		var id;
		var itemcontnode;
		for (var _i=0;_i<node.childNodes.length;_i++){	
			if (node.childNodes[_i].nodeType == 1){
				if (node.childNodes[_i].nodeName == "titcontbkitem"){
					id=node.childNodes[_i].getAttribute('id');
					if(id){
						id=	"titcont_"+id;
						itemcontnode=mw_dom_get_ElementsByTagName_node_firstItem(node.childNodes[_i],"contlist");
						if(itemcontnode){
							this.bkcontnodes[id]=itemcontnode.getElementsByTagName("item");	
						}
					}
				}
			}
		}
		return true;
		
	}
	
	this.onresponse=function(response){
		this.reset_cont();
		
		this.numcont=parseInt(mw_dom_get_ElementsByTagName_node_firstChild_data(response,"contnum"));
		if(!this.numcont){
			this.numcont=0;	
		}
		if(!this.numcont){
			return false;
		}
		
		this.load_bkcontnodes(mw_dom_get_ElementsByTagName_node_firstItem(response,"contentbybk"));
		this.init_cont();
		return true;
		
		
		
	}
}
