// JavaScript Document
//objeto barra
function oBarra(color, x, y)
{
this.color = color
this.objHTML = null
this.parar = true
this.ident = ""
this.px = x
this.py = y
this.cant = 0
this.mas = function (arg)
  {
 var largo = parseInt(this.objHTML.style.width)
 if (largo< 255)
  	{
	k=50
   	if (arg>0) 
	   {
	   this.parar = false	
	   k = 200
	   }
    if (!this.parar)
		{
	    this.objHTML.style.width = largo + 1
		componer()  
	    setTimeout(this.ident+".mas()",k)
		}
	}
  else	   
    this.parar = true
  }
  
this.menos = function (arg)
  {
  var tempor
  var largo = parseInt(this.objHTML.style.width)
  if (largo > 0 )
  	{
	k=50
   	if (arg>0) 
	   {
	   this.parar = false	
	   k = 200
	   }
	 if (!this.parar)
	 	{
		this.objHTML.style.width = largo - 1
     	tempor = this.ident+".menos()"
	 	componer()
        setTimeout(tempor,k)
	   }
	}
  else
    this.parar = true	   
  }
this.stop=function()
 {
  this.parar = true
 }
this.crear = function (ident)
  {
  this.objHTML = document.getElementById(ident)
  this.ident=ident
  this.objHTML.style.width = 255
  this.objHTML.style.background = this.color
  }
}

function componer()
{
var r,g,b, cadHex
r = parseInt(rojo.objHTML.style.width)
g = parseInt(verde.objHTML.style.width)
b = parseInt(azul.objHTML.style.width)
cadHex = "#"+toHex(r)+toHex(g)+toHex(b)
document.getElementById("color").style.background = cadHex
document.getElementById("Hexa").value = cadHex
document.getElementById("Dec").value = r+" "+g+" "+b
}

function toHex(valor)
{
var coc, resto, digitos, res
digitos = "0123456789ABCDEF"
resto = valor % 16
valor = Math.floor(valor/16)
res = digitos.substr(resto,1)
res = digitos.substr(valor,1) + res
return res
}

function iniObj()
{
window.rojo = new oBarra("#FF0000",0,0)
rojo.crear('rojo')
window.verde = new oBarra("#00FF00",0,0)
verde.crear('verde')
window.azul= new oBarra("#0000FF",0,0)
azul.crear('azul')
componer()
}

