var xmouse = 0;
var ymouse = 0;

function CaptPositonMouse(e){
   xmouse=(document.all)?event.clientX:e.pageX;
   ymouse=(document.all)?event.clientY:e.pageY;
}
function ODOM_getMyObj(OBJName) {
  if (document.all) if (document.all[OBJName]) return document.all[OBJName];
  if (document.layers) if (document.layers[OBJName]) return document.layers[OBJName];
  if (document.getElementById ) if (document.getElementById(OBJName) != "") return document.getElementById(OBJName);
  if (document.getElementsByTagName) if (document.getElementsByTagName(OBJName)) return document.getElementsByTagName(OBJName);
  return null;
}


function ODOM_setClipMyObj(obj, valor) {
   if (!obj) return 0;
   if (obj.style) {
      comando = "obj.style.clip = 'rect(" + valor + ")'";
   } else {
      comando = "obj.clip = 'rect(" + valor + ")'";
   }
   eval(comando);

}

function ODOM_setMyObj(obj, prop, valor, debug) {
   if (!obj) return 0;
   if (obj.style) {
      comando = "obj.style."+prop+" = '" + valor + "'";
   } else {
      comando = "obj."+prop+" = '" + valor + "'";
   }
   if (debug) alert (comando);
   return eval(comando);
}

function ODOM_setMyObjProp(obj, prop, valor, debug) {
   if (!obj) return 0;
   comando = "obj."+prop+" = '" + valor + "'";
   if (debug) alert (comando);
   return eval(comando);
}


function ODOM_getMyObjProp(obj, prop) {
   if (!obj) return 0;
   if (obj.style) {
      comando = "obj.style."+prop;
   } else {
      comando = "obj."+prop;
   }
   return eval(comando);
}

function ODOM_getMyObjDisplay(obj) {
   if (!obj) return 0;
   return ((obj.style)?obj.style.display:obj.display);
}


function ODOM_getMyObjOffsetW(obj) {
   if (!obj) return 0;
   return ((obj.offsetWidth)?obj.offsetWidth:obj.outerWidth);
}

function ODOM_getMyObjOffsetH(obj) {
   if (!obj) return 0;
   return ((obj.offsetHeight)?obj.offsetHeight:obj.outerHeight);
}



function ODOM_getMyObjW(obj) {
   if (!obj) return 0;
   return parseInt(((obj.style.width)?obj.style.width:obj.clientWidth));
}

function ODOM_getMyObjH(obj) {
   if (!obj) return 0;
   return ((obj.clientHeight)?obj.clientHeight:obj.clientHeight);
}

function ODOM_getMyObjLeft(obj) {
   if (!obj) return 0;
   return ((obj.style)?obj.style.left:obj.left);
}

function ODOM_getMyObjTop(obj) {
   if (!obj) return 0;
   return ((obj.style)?obj.style.top:obj.top);
}

function ODOM_WriteLayer(layer,texto) {
    if (document.getElementById(layer) ) {
        document.getElementById(layer).innerHTML = texto;
    } else if (document.all) {
        document.all[layer].innerHTML = texto;
    } else if (document.layers ) {
        document.layers[layer].document.open();
        document.layers[layer].document.write(texto);
        document.layers[layer].document.close();
    }
}

function createObj(nome,nomedestino,css,prop){
	
	destino=ODOM_getMyObj(nomedestino)		
		
	if (!destino)destino=document.body;
	if (css==undefined)css = Array	
	if (prop==undefined)prop = Array	
	obj = document.createElement('DIV');

	obj.id = nome;
	obj.name = nome;
	
	//obj.innerHTML = nome;

	/*********************************************************************************
	Aplicando todas propriedades de objetos passadas por parametro em um ARRAY,
	(não são propriedades de CSS) e sim do próprio objeto ex: name, id, bgcolor etc... 
	*********************************************************************************/ 
	for(i in prop){
		obj[i] = prop[i];
		ODOM_setMyObj(obj, i, prop[i]);
		//document.write(i + '=' + prop[i] + '<br>');
	}
	
	/*********************************************************************************
	Aplicando todas propriedades de CSS passadas por parametro em um ARRAY,
	os nomes das propriedades tem que ter a sintaxe do JavaScrip e não do CSS.
	*********************************************************************************/
	
	for(i in css){
		ODOM_setMyObj(obj, i, css[i]);
	}
	
	destino.appendChild(obj);	
	return obj;
}

function format(str,len,pos){
	if (!pos)pos='l';
	if (!len)len=2;
	str=String(str);
	z="";
	if(str.length<len){
		for(a=1;a<=(len-str.length);a++){z+="0"}
		str=((pos=='r')?str+z:z+str);
	}
	return str;				
}

function findpos(obj){
	if (!obj)return false;
	x=0;
	y=0;
	objtemp=obj;
	
	x+=objtemp.offsetWidth;
	y+=objtemp.offsetHeight;
	
	while (objtemp.offsetParent){
		x+=objtemp.offsetLeft;
		y+=objtemp.offsetTop;
		objtemp=objtemp.offsetParent;	
	}
	return [x,y];
}

function divscroll(nomeobj,tipo){
   if (!tipo)tipo="v";
   if(!nomeobj)nomeobj='imgs';
   obj = ODOM_getMyObj(nomeobj);

   pos=findpos(obj);
   obj.posx = pos[0];
   obj.posy = pos[1];

   if (tipo=="v" || tipo=="auto"){
      //obj.midy = parseFloat(ODOM_getMyObjProp(obj,'height'))/2;
      //obj.scrollTop =  ((ymouse  - (obj.posy+15))/(obj.offsetHeight+30)) * (obj.scrollHeight/2);
      //obj.midy = obj.offsetHeight/2;
      //obj.incry = (ymouse - obj.midy)/(obj.offsetHeight/2);
      //this.parent.document.title = y + ' ' + obj.midy + ' ' + obj.posy + ' ' + obj.offsetHeight;
      //obj.scrollTop += (obj.incry * 5);
      obj.scrollTop = (((ymouse)/obj.offsetHeight)/(obj.scrollHeight/obj.offsetHeight))*obj.scrollHeight;
   }

   if (tipo=="h" || tipo=="auto"){
      //obj.midx = parseFloat(ODOM_getMyObjProp(obj,'width'))/2;
      //obj.scrollLeft =  ((xmouse  - (obj.posx+15))/(obj.offsetWidth+75)) * (obj.scrollWidth/2);
      //obj.midx = obj.offsetWidth/2;
      //obj.incrx = (xmouse - obj.midx)/(obj.offsetWidth/2);
      //obj.scrollLeft += (obj.incrx * 5);
      obj.scrollLeft = ((obj.offsetWidth-(obj.posx - xmouse))/(obj.scrollWidth/obj.offsetWidth))*obj.scrollWidth;
   }

   //if (    (  (y > obj.midy + 20 || y < obj.midy - 20) && (tipo=="v" || tipo=="auto")   )     ||     (  (x > obj.midx + 20 || x < obj.midx - 20) && (tipo=="h" || tipo=="auto")   )   ) setTimeout('divscroll("'+nomeobj+'","'+tipo+'");',100);
   return false;
}

document.onmousemove=CaptPositonMouse;
