function SjPicture(inParent, inElementId,inWidth,inHeight) {
	if (arguments[0] == 'empty') {
		return;
	}
	this.SjElement = SjElement;
	this.SjElement(inParent, inElementId);
	if (this._parent && this._parent._elementId){
		sjCreateDiv(this._parent._elementId , this._elementId);
	}else{
		sjCreateDiv(null , this._elementId);
	}

	if (inElementId) {
		var w = jQuery("#"+inElementId).css("width").match(/\d+/);
		if (w != null) {
			this._imageWidth = w[0];
		}
		else {
			this._imageWidth = 0;
		}
	}
	else {
		this._imageWidth = 0;
	}
	if (inElementId) {
		var h = jQuery("#"+inElementId).css("height").match(/\d+/);
		if (h != null) {
			this._imageHeight = h[0];
		}
		else {
			this._imageHeight = 0;
		}
	}
	else {
		this._imageHeight = 0;
	}	
	this._stretch = false;
	this.scale = 1;
	this.loaded = false;
	this.img = new Object();
	this.img._uId = this._elementId + '_img';
	this.img.src = "";
    this.img.str = ' <img';
	this.img.str += ' id=' + this.img._uId;
	this.img.str += ' name=' + this.img._uId;
	this.img.str += ' border=' + 0;
	this.img.str += ' style="position:absolute;left:0;top:0;"';
	this.img.str += '> ';
	//if (document.all) {
		//sjGetElement(this._elementId).insertAdjacentHTML('afterBegin',this.img.str);
	//}else{
	    sjSetLayerHTML(this._elementId,this.img.str);
	//}
	this._content = sjGetElement(this._elementId);
	this.imageElm = sjGetElement(this.img._uId);
	this.imageElm._parent = this;
	this.useMap='';
	this.imageElm.useMap='';
	this.img._parent = this;	
}

SjPicture.prototype = new SjElement('empty');

SjPicture.prototype.load = function(inURL) {
	this.loaded = false;
	if (inURL == this.img.src) {
		this.loaded = true;
	eval('document.' + this.img._uId + '.onload=this.onLoad;');//?????????/
		if (jQuery("#"+this.img._uId).css("width") && jQuery("#"+this.img._uId).css("width").match(/\d+/)) {
			document[this.img._uId].style.width=jQuery("#"+this.img._uId).css("width").match(/\d+/)[0];
			document[this.img._uId].style.height=jQuery("#"+this.img._uId).css("height").match(/\d+/)[0];
		}
		else {
			eval('document.' + this.img._uId + '.style.width=this._imageWidth;');
			eval('document.' + this.img._uId + '.style.height=this._imageHeight;');
		}
		eval('document.' + this.img._uId + '.onload();');
		return;
	}
	if (document.all) {
		sjGetElement(this.img._uId).outerHTML=this.img.str;
		this.imageElm = sjGetElement(this.img._uId);
		this.imageElm._parent = this;
		this.img._parent = this;
	}else{
		eval('document.' + this.img._uId + '.style.width=null;');
		eval('document.' + this.img._uId + '.style.height=null;');
	}	
	this.img.src = inURL;
	eval('document.' + this.img._uId + '.onload=this.onLoad;');
	eval('document.' + this.img._uId + '.onerror=this.onError;');
	eval('document.' + this.img._uId + '.onabort=this.onAbort;');
    eval('document.' + this.img._uId + '.src = inURL;');
	this.imageElm.useMap = this.useMap;
};


SjPicture.prototype.onLoad = function() {
	this._parent.loaded = true;
	var w = jQuery(this).width();	// .css("width").match(/\d+/); doesn't work for auto in IE -> null 
	var h = jQuery(this).height(); // .css("height").match(/\d+/); doesn't work for auto in IE -> null
	
	this._parent._imageWidth = w;
	this._parent._imageHeight = h;
	
	this._parent.stretch(this._parent.stretch());
	//this._parent.setSize(this.width,this.height);//set size of container div !!!
	this._parent.fireEvent('load');
};

SjPicture.prototype.onError = function() {
	this._parent.loaded = false;
	this._parent.fireEvent('error');
};

SjPicture.prototype.onAbort = function() {
	this._parent.loaded = false;
	this._parent.fireEvent('abort');
};

SjPicture.prototype.stretch = function(inStretch) {
	if (inStretch != null) {
		this._stretch = inStretch;
		var w = this.width();
		var h = this.height();
		if (this._stretch) {
			sjSetWidth(this.img._uId, this._width);
			sjSetHeight(this.img._uId, this._height);
		} else {
			sjSetWidth(this.img._uId, this._imageWidth);
			sjSetHeight(this.img._uId, this._imageHeight);
		}
			sjZoomMap (this.imageElm.useMap.substring(1), this.width()/w, this.height()/h);
	}
	return this._stretch;
};

SjPicture.prototype.super_width = SjPicture.prototype.width;
SjPicture.prototype.width = function(inWidth) {
	var w = this.super_width();
	var h = this.super_height();
	var ret = this.super_width(inWidth);
	if (inWidth != null) {
			if (this._stretch) {
				sjSetWidth(this.img._uId, this._width);
				sjSetHeight(this.img._uId, this._height);
			}
			sjZoomMap (this.imageElm.useMap.substring(1), this.width()/w, this.height()/h);
	}
	return ret;
};

SjPicture.prototype.super_height = SjPicture.prototype.height;
SjPicture.prototype.height = function(inHeight) {
	var w = this.super_width();
	var h = this.super_height();
	var ret = this.super_height(inHeight);
	if (inHeight != null) {
			if (this._stretch) {
				sjSetWidth(this.img._uId, this._width);
				sjSetHeight(this.img._uId, this._height);
			}
			sjZoomMap (this.imageElm.useMap.substring(1), this.width()/w, this.height()/h);
	}
	return ret;
};

SjPicture.prototype.map = function(inMap) {
	if (inMap!= null){
	  this.imageElm.useMap=this.useMap='#'+inMap;
	}else
	return this.imageElm.useMap;
};

SjPicture.prototype.clearMap = function() {
	  this.imageElm.useMap=this.useMap='';
};

