
try {
	
	Type.registerNamespace("Flex");

	Flex.ImageFieldContext = function(imageID, sourceUrlID, alternateTextID, widthID, heightID) {
		this.Image = $get(imageID);
		this.SourceUrlInput = $get(sourceUrlID);
		this.AlternateTextInput = $get(alternateTextID);
		this.WidthInput = $get(widthID);
		this.HeightInput = $get(heightID);
	}

	Flex.ImageFieldContext.prototype = {
		
		SetupImage: function() {

			var isrc = this.SourceUrlInput.value
			
			if (isrc != null && isrc.length == 0) {
				this.Image.style.display = 'none';
				return;
			}
			
			this.Image.style.display = 'inline';
			this.Image.src = isrc;
			this.Image.alt = this.AlternateTextInput.value;
			
			if (this.WidthInput.value.length == 0)
				this.Image.style.width = "auto";
			else
				this.Image.style.width = this.WidthInput.value + 'px';
				
			if (this.HeightInput.value.length == 0)
				this.Image.style.height = "auto";
			else
				this.Image.style.height = this.HeightInput.value + 'px';
			
		},
		
		Choose: function(siteurl) {
			
			if (siteurl == '/') siteurl = '';
			
			var url = window.showModalDialog(siteurl + "/_layouts/Flex/ChooseImage.aspx", "ichoose", "resizable: yes; scroll: yes; center: yes; dialogWidth: 750px; dialogHeight: 550px");
			
			if (url != null && url.length > 0) {
				this.SourceUrlInput.value = url
				this.AlternateTextInput.value = '';
				this.WidthInput.value = '';
				this.HeightInput.value = '';
			}
			
			this.SetupImage();
			
		}

	}

	Flex.ImageFieldContext.registerClass('Flex.ImageFieldContext');
	
} catch (ex) {
	//alert('register error: ' + ex.message);
}


function SelectImage(url) {
	
	window.returnValue = url;
	window.close();

}


if (typeof(Sys) != 'undefined') Sys.Application.notifyScriptLoaded();