$(function(){
  $("#uploadify").uploadify({
    'uploader'    : '/pic/plugin/uploadify/uploadify.swf',
    'script'     : '/ajax/module/redact/uploadify.php',
    'checkscript'  : 'check.php',
    'cancelImg'   : '/pic/module/redact/cancel.png',
    'queueID'    : 'upload_files_img',
    'auto'      : true,
    'multi'     : true,
    'fileDesc'   : 'jpg;png;gif',
    'fileExt'   : '*.jpg;*.png;*.gif',
    'onComplete'   : function(event,queueID,fileObj,response,data) {
	$('#response').append(response);
	$('#response').find("span").after(function(){return '<div style="background-color:#ffffff;padding:5px 5px 10px 5px;float:left;"><img title="Кликните для удаления картинки" style="width:50px;height:50px;border:1px solid #777777;" src="/pic/fs/auto/'+this.innerHTML+'"></img><button style="margin-top:5px;margin-left:0px;height:20px;width:52px;font:10px Arial;">Добавить</button></div>';}).remove();
	$('#response').find("div").css({float:"left"});
	$('#response').find("div").find('img').css({width:"50px", height:"50px"}).click(function(){$(this).parent().css({display:"none"});});
	$('#response').find("div").find('button').unbind().click(function(){
	document.execCommand('inserthtml', false,'<img src="'+$(this).parent().find('img')[0].src+'">');
	Redactor.onChange();
	});
	}
  });
});




function getSelText()
{
var a=window.getSelection();
alert(a.anchorNode.parentNode.tagName);
}


function getCursorPos() {
var cursorPos;
if (window.getSelection) {
var selObj = window.getSelection();
var selRange = selObj.getRangeAt(0);
cursorPos =  findNode(selObj.anchorNode.parentNode.childNodes, selObj.anchorNode) + selObj.anchorOffset;
/* FIXME the following works wrong in Opera when the document is longer than 32767 chars */
alert(cursorPos);
}
else if (document.selection) {
var range = document.selection.createRange();
var bookmark = range.getBookmark();
/* FIXME the following works wrong when the document is longer than 65535 chars */
cursorPos = bookmark.charCodeAt(2) - 11; /* Undocumented function [3] */
alert(cursorPos);
}
}

function findNode(list, node) {
for (var i = 0; i < list.length; i++) {
if (list[i] == node) {
return i;
}
}
return -1;
}







