// Copyright 2000, 2001, 2002, 2003, 2004, 2005 Macromedia, Inc. All rights reserved.

//---------------     API FUNCTIONS    ---------------

function isDOMRequired() {
	// Return false, indicating that this object is available in code view.
	return true;
}

function isAsset() {
	return true;
}

function objectTag(assetArgs) {
  var rtnStr = "";
  var bDialogState = dw.getShowDialogsOnInsert(); // Was dialog shown?
  var prefsAccessibilityOption = null;

  var newURL;

if (dw.appName == "Contribute")
{
	if (MM.insertImgType == "file")
		newURL = dw.doURLEncoding(dw.browseForFileURL("select", "", true, "","","", "", "desktop"));
	else if (MM.insertImgType == "website")
		newURL = dw.doURLEncoding (dw.browseForImage ());
}

else
{
  var newURL = dw.doURLEncoding(dw.browseForFileURL("select", "", true));
}

  if (assetArgs)
  {
  	newURL = assetArgs;
  }

  var imgDim = dw.getNaturalSize(newURL);

  if ((newURL == '')  && bDialogState) {  return ''; }

  var thisDOM = dw.getDocumentDOM();

  // By default, we add the alt text and set it to NULL

  if (imgDim && !thisDOM.getUseFluidMediaForTag("img")){
    rtnStr= '<img src="' + newURL + '" width="' + imgDim[0] +'" height="' + imgDim[1] + '" ';
  }else{
    rtnStr= '<img src="' + newURL + '" ';
  }
  rtnStr = rtnStr + 'alt="' + '"/>';

  if (dw.appName == "Contribute")
  {
    prefsAccessibilityOption = dw.getAdminEnforceAccessibilityPref();
  }
  else
  {
    prefsAccessibilityOption = dw.getPreferenceString("Accessibility", "Accessibility Image Options", "");
  }

  if (thisDOM != null)
  {
	  //xhtml strict requires alt attribute
	  if(thisDOM.getIsXHTMLStrictDocument() && 0 > rtnStr.indexOf(" alt=") )
	  {
		  var insertIndex = rtnStr.indexOf(" width=");
		  if( insertIndex < 0 )
		  	insertIndex = rtnStr.length -1;

		  rtnStr = (rtnStr.substr(0, insertIndex) + ' alt=""' + rtnStr.substr(insertIndex));
	  }

	var siteName = site.getSiteForURL(dw.getDocumentDOM().URL);
	if( siteName != '' && site.getIsServerSite(siteName) )
	{
		var fullURL;
		if (newURL.indexOf("file://") != 0)
		{
		  if( newURL[0] == "/" )
		  fullURL = dw.relativeToAbsoluteURL(dw.getDocumentDOM().URL, dw.getSiteRoot(), newURL);
		  else
		  fullURL = dw.relativeToAbsoluteURL(dw.getDocumentDOM().URL, "", newURL);

		  if (dw.getSmartObjectState(fullURL,0,0) == 0)
		  {
			  site.get(fullURL);
		  }
		}
	}
  }

  return rtnStr
}

