//ver docu.js.php
window.fwk.common.classDestacados=function(){
	var mthis=this;		
	this.debug=true;
	this.showDebug=function(){$("#debugDestacadoFrame").show();};	
	this.setVerbose=function(v){			
				if(mthis.debug==true){
				var i=0;
				var hr="";
				//var hr="";for(i;i<60;i++){hr=hr+"-";} hr=hr+"\n";
						if(this.debugDiv==false){
							$("body").append("<div id='debugDestacadoFrame' style='width: 100%; height: 100px;position:fixed;right:0px;bottom: 0px;background-color:blue; text-align:right;'><input type='button' value='Clear' onclick='$(\"#debugDestacadoClass\").val(\"\");'/><input type='button' value='X' onclick='$(\"#debugDestacadoFrame\").hide();'/><p><textarea id='debugDestacadoClass' style='width: 100%;height: 100px;'  rows=10  wrap='off'>"+v+"\n"+hr+"</textarea></p></div>");
							this.debugDiv=true;
						}else{
							$("#debugDestacadoClass").val( $("#debugDestacadoClass").val()+v+"\n"+hr);
						}
					}
	};
	this.load=function(){
	
		$("[id^=destacadosCintaPaginador]").each(function(i){					
			mthis.goTo(this.id,1,true);
		});
		
	};
	this.nextItem=function(id){
		var item=($("#"+id).attr("item_actual")*1);
		var cantidad= ($("#"+id).attr("cantidad_pagina")*1);
		//$("#debug").html($("#debug").html()+item+">"+cantidad);
		var next=(item>=cantidad?1:(item+1));
		return next;
	};
	this.prevItem=function(id){
			var item=($("#"+id).attr("item_actual")*1);
			var cantidad= ($("#"+id).attr("cantidad_pagina")*1);
			var next=(item==1?cantidad:(item-1));
			return next;
	};
	this.showItem=function(id){
	//alert("comando "+$("#comandos"+id+" .comandos-num .selectedcommand").html());
	$("#comandos"+id+" .comandos-num .selectedcommand").html($("#comandos"+id+" .comandos-num .selectedcommand").html())
				$("#comandos"+id+" .comandos-num .selectedcommand").removeClass("selectedcommand");
				$("#comandos"+id+" .comandos-num .comando-pos"+$("#"+id).attr("item_actual")).addClass("selectedcommand");
				//-------------------------------------------
				//vertical
				// en caso que se quiere implementar verticalmente
				// faltan darle funcionalidad a los botones
				//-------------------------------------------
				if($("#"+id).attr("slice")=="vertical"){
					var mTop=$("#"+id+" .item-pos-"+$("#"+id).attr("item_actual")).css("marginTop");
					var h=$("#"+id).css("height");
					mTop=mTop.replace("px","");
					h=h.replace("px","");			
					//$("#debug").html($("#debug").html()+$("#"+id).attr("item_actual")+"!="+$("#"+id).attr("cantidad_pagina"));
					if($("#"+id).attr("item_actual")==$("#"+id).attr("cantidad_pagina")){				
						var a
						for(a=1;a<=$("#"+id).attr("cantidad_pagina");a++){
							$("#"+id+" .item-pos-"+a).css("marginTop",mTop+"px");
						}
					}else{
						$("#"+id+" .item-pos-"+$("#"+id).attr("item_actual")).animate({  marginTop: "-="+(h-mTop)+"px"}, 1000 );
	
					}			
				}else{
				//-------------------------------------------
				//facein
				//-------------------------------------------			
					
					var a;				
						for(a=1;a<=$("#"+id).attr("cantidad_pagina");a++){
							if($("#"+id+" .item-pos-"+a).css("display","none")){
							  /*$("#"+id+" .item-pos-"+a).fadeOut(500,function(){						  
							  });*/
							 
							 // break;
							}
							
							/* $("#"+id+" .item-pos-"+a).css("display","none");*/
						}				
					var c;
					for(c=1;c<=$("#"+id).attr("cantidad_pagina");c++){
							if(c==$("#"+id).attr("item_actual")){				 
								 $("#"+id+" .item-pos-"+c).fadeIn(500);
								 $("#"+id+" .item-pos-"+c).css("display","block")						 
								 // break;
								}
					}								
			}
	};
	this.setDestacado=function(id,jump){				
		mthis.setVerbose($("#"+id).attr("estado"));
		if($("#"+id).attr("estado")!="stop"){											
			mthis.showItem(id);
			if(jump==true){
				var next=mthis.nextItem(id);
				$("#"+id).attr("item_actual",next);
				setTimeout("fwk.common.destacados.setDestacado('"+id+"',"+jump+")",$("#"+id).attr("speed"));
			}
		//end stpo
		}
		
	};
	this.stopRun=function(id){
		$("#"+id).attr("estado","stop");
		$("#comandos"+id+" .selectedcommand").removeClass("selectedcommand");
		$("#comandos"+id+" .stop").addClass("selectedcommand");		
	};
	this.stop=function(id){
		this.stopRun(id)
		mthis.goTo(id,($("#"+id).attr("item_actual")-1),false);
	};	
	this.play=function(id){
	$("#comandos"+id+" .selectedcommand").removeClass("selectedcommand");
	$("#comandos"+id+" .play").addClass("selectedcommand");
		$("#"+id).attr("estado","play");		
		if($("#"+id).attr("item_actual")>=$("#"+id).attr("cantidad_pagina")){
			$("#"+id).attr("item_actual",1);//va al proximo
		}else{
		  var newItemActual=(($("#"+id).attr("item_actual") * 1)+1);
			$("#"+id).attr("item_actual",newItemActual);//va al proximo
		}
		//$("#"+id).attr("item_actual",(($("#"+id).attr("item_actual")==$("#"+id).attr("cantidad_pagina"))?1:($("#"+id).attr("item_actual")+1)));//va al proximo
		mthis.setDestacado(id,true);
	};
	this.moveFirst=function(id){
		$("#comandos"+id+" .selectedcommand").removeClass("selectedcommand");
		$("#comandos"+id+" .first").addClass("selectedcommand");		
		mthis.moveTo(id,1);
	};
	this.moveLast=function(id){
		$("#comandos"+id+" .selectedcommand").removeClass("selectedcommand");
		$("#comandos"+id+" .last").addClass("selectedcommand");
		$("#"+id).attr("cantidad_pagina",$("#"+id).attr("cantidad_pagina"));
		mthis.stopRun(id);
		mthis.moveTo(id,$("#"+id).attr("cantidad_pagina"));		
	};
	this.moveNext=function(id){
		$("#comandos"+id+" .selectedcommand").removeClass("selectedcommand");
		$("#comandos"+id+" .next").addClass("selectedcommand");
		if($("#"+id).attr("estado")=="stop"){
			mthis.stopRun(id);
		}else{
			this.stop(id);
		}		
		mthis.moveTo(id,mthis.nextItem(id));		
		
	};
	this.movePrev=function(id){
		$("#comandos"+id+" .selectedcommand").removeClass("selectedcommand");
		$("#comandos"+id+" .prev").addClass("selectedcommand");
		if($("#"+id).attr("estado")=="stop"){
			mthis.stopRun(id);
		}else{
			this.stop(id);
		}
		mthis.moveTo(id,mthis.prevItem(id));
		
	};
	this.goTo=function(id,itemNum,jump){			
		$("#comandos"+id+" .comandos-num .selectedcommand").removeClass("selectedcommand");
		$("#comandos"+id+" .comandos-num .comando-pos"+itemNum).addClass("selectedcommand");
		$("#"+id).attr("item_actual",itemNum);
		mthis.setDestacado(id,jump);		
		mthis.setVerbose("#comandos"+id+" .comandos-num .comando-pos"+itemNum);
	};
	this.moveTo=function(id,itemNum){
		$("#"+id).attr("estado","play");
		//$("#comandos"+id+" .selectedcommand").removeClass("selectedcommand");		
		mthis.stopRun(id);
		//mthis.goTo(id,itemNum,false);		
		$("#"+id).attr("item_actual",itemNum);
		mthis.showItem(id);
	};
}//end class

$(document).ready(function(){
	window.fwk.common.destacados=new window.fwk.common.classDestacados();
	window.fwk.common.destacados.load();		
});
