
var FCKToolbarCustomLinksCombo = function() {
	this.Command	= FCKCommands.GetCommand('CustomLinks') ;
	this.Label		= this.GetLabel();
	this.Tooltip	= window.parent.SbGetLocaleByKey('WYSIWYG-CUSTOM-LINKS-TOOLTIP');
	this.Style		= FCK_TOOLBARITEM_ICONTEXT;
}

FCKToolbarCustomLinksCombo.prototype = new FCKToolbarSpecialCombo;

FCKToolbarCustomLinksCombo.prototype.GetLabel = function() {
	return window.parent.SbGetLocaleByKey('WYSIWYG-CUSTOM-LINKS');
}

FCKToolbarCustomLinksCombo.prototype.CreateItems = function(targetSpecialCombo) {	
	var tree = top.document.getElementById('edit');
//	node.identifier
	var childList = tree.getChildList();	
	for (i in childList) {
		var node = childList[i];
		
		if ('undefined' != typeof(node.textObject)) {
			this._Combo.AddItem(node.fName, node.textObject.innerHTML);		
		
			if (node.hasChilds()) {
				var nodeChildList = node.getChildList();
				for (j in nodeChildList) {
					var node = nodeChildList[j];
					
					if ('undefined' != typeof(node.textObject)) {
						this._Combo.AddItem(node.fName, '&nbsp;&nbsp;&nbsp;' + node.textObject.innerHTML);
					}
				}			
			}
		}
	}
	targetSpecialCombo.FieldWidth = 70;
}

var CustomLinksPlugin = function() {
	/*...*/
};

CustomLinksPlugin.GetState = function() {
	return FCK_TRISTATE_OFF;
}

CustomLinksPlugin.Execute = function(CustomLinks, item) {
	FCK.Focus();	
	var oLink = FCK.Selection.MoveToAncestorNode( 'A' ) ;
	if ( oLink ) {
		FCK.Selection.SelectNode( oLink );
	}

	var sUri = CustomLinks;	
	
	if ( oLink )	// Modifying an existent link.
	{
		FCKUndo.SaveUndoStep() ;
		oLink.href = sUri ;
	}	
	else			// Creating a new link.
	{
		oLink = FCK.CreateLink(sUri) ;
		if ( ! oLink ) { // link with no text
			FCK.InsertHtml('<a href="' + CustomLinks + '>' + item.innerHTML + '</a>');
		}
	}
	FCKToolbarSpecialCombo_RefreshActiveItems(CustomLinksPluginButton._Combo, '');
}

FCKCommands.RegisterCommand('CustomLinks', CustomLinksPlugin);
var CustomLinksPluginButton = new FCKToolbarCustomLinksCombo();
FCKToolbarItems.RegisterItem('CustomLinks', CustomLinksPluginButton);
