var id_sequence = 0;
var imagesCache = new Object;

extend = function(subClass, baseClass) 
{
   function inheritance() {}
   inheritance.prototype = baseClass.prototype;

   subClass.prototype = new inheritance();
   subClass.prototype.constructor = subClass;
   subClass.baseConstructor = baseClass;
   subClass.superClass = baseClass.prototype;
}

function Control()
{
	this.setStyle = function($name, $value)
    {
        style[$name] = $value;
    }

    this.getStyle = function($name)
    {
        return style[$name];
    }
}
 

function Img()
{

    var src = null;

    id_sequence += 1;
    var id = "id" + id_sequence;

    var attrib = new Array();
    var style = new Array();

    this.setImage = function($src)
    {
        src = $src;
    }

    this.setAttribute = function($name, $value)
    {
        attrib[$name] = $value;
    }
    


    this.setStyle = function($name, $value)
    {
        style[$name] = $value;
    }

    this.getStyle = function($name)
    {
        return style[$name];
    }


    this.toString = function()
    {
        var res = "";
        res += "<img id='" + id + "' src='" + src + "' ";

        res += "style='";
        for(var k in style)
        {
            res += k + ":" + style[k] + ";";
        }
        res += "' ";


        for(var k in attrib)
        {
            res += k + "='" + attrib[k] + "' ";
        }

        res += ">";

        return res;
    }

    this.moveLeft = function($value)
    {
        //debugger;
        var img = document.getElementById(id);
        img.style.left = $value + "px";
        style["left"] = $value;
    }

}


function CheckBox()
{
    var checked = false;
    var value = 0;

    id_sequence += 1;
    var id = "id" + id_sequence;

    var attrib = new Array();
    var style = new Array();

    this.setChecked = function($checked)
    {
        (document.getElementById(id)).checked = $checked;
        checked = $checked;
    }
    
    this.getChecked = function()
    {
        return (document.getElementById(id)).checked;
    }

    this.setAttribute = function($name, $value)
    {
        attrib[$name] = $value;
    }
    
    this.setValue = function($value)
    {
        (document.getElementById(id)).value = $value;
        value = $value;
    }
    
    this.getValue = function()
    {
        return (document.getElementById(id)).value;
    }


    this.toString = function()
    {
        var res = "";
        res += "<input type='checkbox' id='" + id + "' " + (checked ? "checked " : "");

        res += "style='";
        for(var k in style)
        {
            res += k + ":" + style[k] + ";";
        }
        res += "' ";


        for(var k in attrib)
        {
            res += k + "='" + attrib[k] + "' ";
        }

        res += ">";

        return res;
    }

}

function Label()
{

    var text = "";

    id_sequence += 1;
    var id = "id" + id_sequence;

    var attrib = new Array();
    var style = new Array();

    this.setText = function($text)
    {
        (document.getElementById(id)).innerHTML = $text;
    }

    this.setAttribute = function($name, $value)
    {
        attrib[$name] = $value;
    }
    
    this.setColor = function($value)
    {
         (document.getElementById(id)).style.color = $value;
    }

    this.getColor = function()
    {
        return (document.getElementById(id)).style.color;
    }


    this.toString = function()
    {
        var res = "";
        res += "<span id='" + id + "' ";

        res += "style='";
        for(var k in style)
        {
            res += k + ":" + style[k] + ";";
        }
        res += "' ";


        for(var k in attrib)
        {
            res += k + "='" + attrib[k] + "' ";
        }

        res += ">" + text + "</span>";

        return res;
    }
}

