///
///
///
function ImageControlUpdateSource(e)
{
	var imgContainer = embeddedControl_PresentationControls[this.controlObject.id];
	var newData = this.GetContent().split("|");

	try
	{
		imgContainer.removeAttribute("href");
		var img = imgContainer.getElementsByTagName("img")[0];
		img.src = unescape(newData[0]);
		img.title = unescape(newData[1]);
		
		var url = newData[2];
		if (url != null && url != "")
			imgContainer.setAttribute("href", unescape(url));
	}
	catch (err) { }
}

///
///
///
function ImageControlContextMenu(contentType)
{
	if (contentType == "EditDesign")
		return CONTROLCONTEXTMENU_ENABLEDISABLE | CONTROLCONTEXTMENU_CLEAR | CONTROLCONTEXTMENU_EDIT | CONTROLCONTEXTMENU_PROPERTIES | CONTROLCONTEXTMENU_CUSTOMPROPERTIES | CONTROLCONTEXTMENU_DEPTHORDERING | CONTROLCONTEXTMENU_DELETERESTORE;
	else if (contentType == "EditContent")
		return CONTROLCONTEXTMENU_EDIT | CONTROLCONTEXTMENU_CLEAR | CONTROLCONTEXTMENU_DELETERESTORE;

	return 0;
}


function InitializeImageControl(controlID, imageContainerID)
{
	var control = eval("_" + controlID);
	embeddedControl_PresentationControls[controlID] = $get(imageContainerID);
	control.OnInitialized = ImageControlUpdateSource;

//	DEPRECATED? Hyperlinkproperty is moved into the imagecontrol's content instead
//	try{
//		eval("_" + controlID + "_HyperLinkable") = new TemplateBaseControlExtension_HyperLinkableClass(imageID, Template.GetContentType() == "View");
//		SetLink(eval("_" + controlID + "_HyperLinkable"), $get(controlID).style["cueAfter"]);
	//	}catch(err){}
	try
	{
		var imgElement = $get(imageContainerID).getElementsByTagName("img")[0];
		imgElement.onerror = function() { HandleMissingImageFile(imgElement); }
	} catch (err) { }

	if (Template.ContentType != "View")
	{
		control.GetEditorControlID = function() { return "ImageSourceEditor"; }
		control.GetCustomContent = function() { return [control.GetCustomProperties(), control.GetContent()]; }
		control.PreProcessEditorContent = PreProcessContent_SaveFileReferences;
		control.ContentUpdated = ImageControlUpdateSource;
		control.OnContextMenu = ImageControlContextMenu;
		control.GetCustomPropertyControlID = function() { return "ImageSettings"; }
	}
}

function HandleMissingImageFile(element)
{
	try
	{
		element.src = "/images/blank.gif";
	} catch (err) { }
}