function getStyle(obj,style){
	if(obj.currentStyle){
		return obj.currentStyle[style];
	}else if(document.defaultView){
		return document.defaultView.getComputedStyle(obj,"").getPropertyValue(style);	
	}
}
function setStyle(obj,style,val){
	if(obj.currentStyle){
		obj.currentStyle[style]=val;
	}else if(document.defaultView){
		document.defaultView.getComputedStyle(obj,"").getPropertyValue(style)=val;
	}

}

var Defil=function(id,fonction,delai,pas,haut,bas,droite,gauche){
//alert("defil:"+this);
	this.obj=$(id);
	console.log("jquery:"+$(id)+"\nthis.obj:"+this.obj);
	console.log("div top:"+getStyle($(id),"top"));
	//console.log("jquery:"+$(id).css("top"));//+"\nthis.obj:"+this.obj);
	var refObj=this;
	this.id=id;
	//this.obj;
	this.fonction=fonction;
	this.delai=3000;
	this.haut=haut;
	this.bas=bas;
	this.droite=droite;
	this.gauche=gauche;
	this.rotate=true;
	this.width=0;

	this.init=function(){
		//var obj=findDOM(this.id,0);
		//if(obj){
			//this.obj=obj;
			/*
			if($(this.id).clientWidth && $(this.id).clientHeight){
				this.bas=$(this.id).clientHeight;
				this.droite=$(this.id).clientWidth;
			}*/
			this.animate();
		//}
	}

	this.animate=function(){
		setInterval(function(){refObj.toHaut(refObj.id);},this.delai);
		/*
		if(o.fonction="haut")timeout=window.setInterval(o.toHaut(),1000);
		else if(o.fonction="bas")timeout=setTimeout(o.toBas(),o.delai);
		else if(o.fonction="droite")timeout=setTimeout(o.toDroite(),o.delai);
		else if(o.fonction="gauche")timeout=setTimeout(o.toGauche(),o.delai);*/
	}


	//	Défilement vers le haut
	this.toHaut=function(id){
		if(this.rotate){
			//var div=$(id);
			//if($(id).clientHeight){
			var pos=parseInt($(id).style.top);
			if(isNaN(pos))pos=parseInt(getStyle($(id),"top"));
//console.log("demande de repositionnement de "+$(this.id)+" - "+pos+" - "+getStyle($(this.id),"top"));
	console.log("div top:"+pos);
			if(pos>=(this.haut-$(id).clientHeight))pos-=this.pas;
			else pos=this.bas;
			$(id).style.top=String.valueOf(pos)+"px";
				//$(id).css(function(){top:pos});

//console.log("top:"+$(this.id).style.top);
				//setStyle(this.obj,"top",pos+"px");
				//this.obj.style.border=pos+"px dotted red";
			//}*/
		}
	}
}

/*
	//	Défilement vers le bas
	this.bas=function(){
		if(this.rotate){
			if(this.obj.clientHeight){
				var pos=parseInt(this.obj.style.top);
				if(isNaN(pos))pos=parseInt(getStyle(this.obj,"top"));
				if(pos<=this.bas)pos+=this.pas;
				else pos=this.haut-this.obj.clientHeight;
				this.obj.style.top=pos+"px";
			}
		}
		this.animate();
	}

	//	Défilement vers la droite
	this.droite=function(){
		if(this.rotate){
			if(this.obj.clientHeight){
				if(this.width==0)this.width=this.obj.clientWidth;
				var pos=parseInt(this.obj.style.left);
				if(isNaN(pos))pos=parseInt(getStyle(this.obj,"left"));
				if(pos<=this.droite)pos+=this.pas;
				else pos=this.gauche-this.obj.clientHeight;
				this.obj.style.width=width+"px";
				this.obj.style.left=pos+"px";
			}
		}
		this.animate();
	}

	//	Défilement vers la droite
	this.gauche=function(){
		if(this.rotate){
			if(this.obj.clientHeight){
				if(this.width==0)this.width=this.obj.clientWidth;
				var pos=parseInt(this.obj.style.left);
				if(isNaN(pos))pos=parseInt(getStyle(this.obj,"left"));
				if(pos>=(this.gauche-this.obj.clientWidth))pos-=this.pas;
				else pos=this.droite;
				this.obj.style.left=pos+"px";
			}
		}
		this.animate();
	}
}*/
