/**
 * Created by JetBrains PhpStorm.
 * User: taoqili
 * Date: 12-1-30
 * Time: 下午12:50
 * To change this template use File | Settings | File Templates.
 */
var wordImage = {};
//(function(){
var g = baidu.g,
	flashObj;
wordImage.init = function() {	
	showLocalPath("url");
	addOkListener();
};

function addOkListener() {
	dialog.onok = function() {
		if ($("url").length) return;
		var images = domUtils.getElementsByTagName(editor.document,"img");
		for (var i = 0,img; img = images[i++];) {
			var src = img.getAttribute("word_img");
			if(src!=null && src.indexOf(OldWordImageUrl) != -1){
			img.src = $("url").value;
			img.setAttribute("data_ue_src", $("url").value);  //同时修改"data_ue_src"属性
			parent.baidu.editor.dom.domUtils.removeAttributes(img, ["word_img","style","width","height"]);
			editor.fireEvent("selectionchange");
			}
		}
	};
}

var OldWordImageUrl;
function showLocalPath(id) {
    //单张编辑
    //if(editor.word_img.length==1){
        g(id).value = editor.word_img[0];
		OldWordImageUrl = editor.word_img[0];
        return;
    //}
	/*var path = editor.word_img[0];
    var leftSlashIndex  = path.lastIndexOf("/")||0,  //不同版本的doc和浏览器都可能影响到这个符号，故直接判断两种
            rightSlashIndex = path.lastIndexOf("\\")||0,
            separater = leftSlashIndex > rightSlashIndex ? "/":"\\" ;

	path = path.substring(0, path.lastIndexOf(separater)+1);
	g(id).value = path;
	OldWordImageUrl = path;*/
}

function extendProperty(fromObj, toObj) {
	for (var i in fromObj) {
		if (!toObj[i]) {
			toObj[i] = fromObj[i];
		}
	}
	return toObj;
}
//})();