BwClasses["BwImageLink"] = BwImageLink;

function BwImageLink ()
{
	this.isa = BwWidget;
	this.isa();
	
    this.url = null;
    this.targ = null;
   	this.picture = null;

	this.initFromDOM = BwImageLink.initFromDOM;
	
    /* Link */
    this.setUrl = BwImageLink.setUrl;
	this.getUrl = BwImageLink.getUrl;

    this.setTarget = BwImageLink.setTarget;
	this.getTarget = BwImageLink.getTarget;

    this.setValue = BwImageLink.setValue;
	this.getValue = BwImageLink.getValue;
    
    /* Image */
    this.draw = BwImageLink.draw;
	
	this.setImage= BwImageLink.setImage;
	this.getImage= BwImageLink.getImage;

}

BwImageLink.newInstance = function (src, linkName, linkUrl, linkTarget)
{
	var self = document.createElement ("A");
	
	self.BwClass = BwImageLink;
	self.BwClass();

	self.className = "BwImageLink";
	if (linkUrl==null) {
		self.setAttribute ("href", "#");
    } else {
		self.setAttribute ("href", linkUrl);
    }
	
	/*if (linkName) {
		self.setAttribute ("title", linkName);
	}*/
	
    if (linkTarget && linkUrl!='null') {
		self.setAttribute ("target", linkTarget);
	}
    
    if (src) {
		selfImg.setAttribute ("source", src);
	}
	self.initFromDOM();
	
	return self;
};

BwImageLink.initFromDOM = function ()
{
	BwWidget.initFromDOM.call (this);
	
	/*this.style.cursor="pointer";
	 var linkName = this.getAttribute ("title");

	if (linkName != null)
		this.setValue (linkName);*/
        
    this.draw();

    return false;
};

BwImageLink.draw = function ()
{
	this.style.display="inline";
	
	var img = this.getAttribute ("image");
	if (img != null) {
		this.setImage (img);
	}
	
	/*var txt = this.getAttribute ("label");
	if (txt != null) {
		this.setLabel (txt);
	}*/
	
	return false;
};


BwImageLink.setImage = function (img)
{
	var p = this.picture;
	if (p == null)
	{
		p = BwImage.newInstance ();
    	p.style.marginLeft="2px";
		p.style.marginRight="2px";
		p.style.border="0px";
		p.style.verticalAlign = "middle";
		p.style.width="70px";
		p.align="center";

        if (this.text != null && this.text) {
			p.attachBefore (this.text);
		} else {
			p.attach (this);
		}
	
		this.picture = p;
	}
	
	if (img != p.getSource()) {
		p.setSource (img);
	}
};

BwImageLink.getImage = function ()
{
	var p = this.picture;
	if (p == null) return null;
	return p.getSource();
};

BwImageLink.setUrl = function (u)
{
    this.url = u;
    this.href=u;
};

BwImageLink.getUrl = function ()
{
    var u = this.url;
    if (u==null) return null;
	return u;
};

BwImageLink.setTarget = function (targ)
{
    this.targ = targ;
    this.target = targ;
};

BwImageLink.getTarget = function ()
{
    var t = this.targ;
    if (t==null) return null;
	return t;
};

BwImageLink.getValue = function ()
{
	return this.url;
};

BwImageLink.setValue = function (link)
{
    return setUrl(link);
};

