var _umlparentsc_img=[];
var _umlcoords_img=[];
var _umlhave_img='';
var _umloffX_img,_umloffY_img,_umlscrX_img,_umlscrY_img;
var _uml_ie_img=0;
var _umlunable_img=0;
var uim_img_src,uim_id_cell,uim_frM60,uim_img_class;

if (uim_frM60 == 1) {
    if (document.getElementById('frM60')) {
        var uim_inner = document.getElementById('frM60').innerHTML;
        var uim_button = '<input style="width:60px;" class="postPreview" type="button" value="Фото" onclick="addPhotoUploader();" /> ' + uim_inner;
        document.getElementById('frM60').innerHTML = uim_button;
    }
} else if (uim_img_src != undefined && uim_id_cell != undefined && uim_frM60 == undefined) {
    if (document.getElementById(uim_id_cell)) {
        var uim_inner = document.getElementById(uim_id_cell).innerHTML;
        var uim_button = '<img align="absmiddle" class="'+uim_img_class+'" src='+uim_img_src+' onclick="addPhotoUploader();" />' + uim_inner;
        document.getElementById(uim_id_cell).innerHTML = uim_button;
    }
} else {
    if(document.getElementById('bc1')) {
	    x='<span class="bbc1"><input onclick="addPhotoUploader();" type=\"button\" value=\"Фото\" class=\"codeButtons\" style=\"width:65px;\" name=\"addPhotoImg\" id=\"addPhotoImg\"></span>';
	    x+=document.getElementById('bc1').innerHTML;
	    document.getElementById('bc1').innerHTML=x;
    }
}

function addPhotoUploader(){	
	var scrw=document.body.clientWidth>0 ? document.body.clientWidth : window.innerWidth>0 ? window.innerWidth : document.body.offsetWidth;
	var scrh=document.body.clientHeight>0 ? document.body.clientHeight : window.innerHeight>0 ? window.innerHeight : document.body.offsetHeight;
	var x = (scrw-610)/2;
	var y = (scrh-375)/2-30;
	if (!document.getElementById('newLayerUimages')){
		var o = document.createElement('div');
		o.id = 'newLayerUimages';
		o.style.display = 'none';
		document.body.appendChild(o);
	}
	document.getElementById('newLayerUimages').innerHTML= '<div id="outLayerUimages" style="position: absolute; z-index:4; top:'+y+'px;left:'+x+'px;">'+
    '<div id="layerTopUimages" style="background: #6B82A4; width: 610px; height:30px; border-left:1px solid #D4D0C8; border-top:1px solid #D4D0C8; border-right:1px solid #D4D0C8;">'+
    '<div style="padding:3px 5px 3px 7px;" align="center"><table id="layerTitleUimages" border="0" cellpadding="0" cellspacing="0" width="580"><tr><td width="75%" align="left">'+
    '<!-- Заголовок -->'+
    '<div style="color:#FFFFFF;font-weight:bold;font-size:8pt;font-family:Century Gothic;">THE LOST.ORG.RU</div>'+
    '<!-- Конец Заголовок -->'+
    '</td><td width="25%" align="right">'+
    '<a href="javascript://" onclick=""><img onclick="closeUimages();" border="0" onmouseover="this.src=\'http://src.ucoz.net/img/ma/l_c1.gif\'" onmouseout="this.src=\'http://src.ucoz.net/img/ma/l_c.gif\'" src="http://src.ucoz.net/img/ma/l_c.gif" width="12" height="12" title="Закрыть"></a>'+
    '</td></tr></table></div>'+
    '<div id="heightUimages" style="background: #F0F3F5; border-left:1px solid #D4D0C8; border-top:1px solid #D4D0C8; border-right:1px solid #D4D0C8; border-bottom:1px solid #D4D0C8; width: 610px; height: 300px; overflow:auto;">'+
    '<table border="0" cellpadding="5" cellspacing="0" width="100%" height="100%"><tr><td align="center" style="color:#515151"><div align="center" style="font-size:8pt;font-family:Tahoma,Arial;" id="layerContentUimages">'+
    '<input onclick="uploadImagesUimages();" type="button" value="Загрузить изображение" style="border:1px solid #6B82A4; color:#6B82A4; background:#F0F3F5; font-family:verdana,arial,helvetica; font-size:8pt;" /> '+
    '<input onclick="alert(\'Функция будет доступна в 2.0 версии сервиса.\');" type="button" value="Создать слайдшоу" style="border:1px solid #6B82A4; color:#6B82A4; background:#F0F3F5; font-family:verdana,arial,helvetica; font-size:8pt;" /> '+
    '<input onclick="alert(\'Функция будет доступна в 2.0 версии сервиса.\');" type="button" value="Прикрепить группу" style="border:1px solid #6B82A4; color:#6B82A4; background:#F0F3F5; font-family:verdana,arial,helvetica; font-size:8pt;" />'+
    '</div></td></tr></table></div></div></div>';
	document.getElementById('newLayerUimages').style.display='';
	_umlRegMover('layerTitleUimages','outLayerUimages');
}

function closeUimages() {
    document.getElementById("newLayerUimages").style.display = "none";
}

function uploadImagesUimages() {
	document.getElementById("layerContentUimages").innerHTML = '<iframe id="UimagesFrameUpload" marginwidth="0" marginheight="0" border="0" frameborder="0" style="width: 100%; height: 100%;" height="100%" src="http://uimages.ru/index/0-8"></iframe>';
    brouserUimages = navigator.userAgent.toLowerCase();
    if (brouserUimages.indexOf("gecko") != -1) {
	    document.getElementById("UimagesFrameUpload").style.height = "290px";
	}
}
/*
function UimFrameLoadDone() {
	document.getElementById("previewLoadFrameUim").style.display = 'none';
	document.getElementById("UimagesFrameUpload").style.display = '';
	brouserUimages = navigator.userAgent.toLowerCase();
	if (brouserUimages.indexOf("gecko") != -1) {
	    document.getElementById("UimagesFrameUpload").style.height = "290px";
	}
}
*/
if (document.addEventListener){
	document.addEventListener('mouseup',_umlUp,false);
	document.addEventListener('mousemove',_umlMove,false);
}

else if (window.attachEvent){
	document.attachEvent('onmouseup', _umlUp);
	document.attachEvent('onmousemove', _umlMove);
	window.attachEvent('onscroll', _umlScroll);
	_uml_ie_img=1;
} else {
	_umlunable_img=1;
}

function _umlGetCoord(obj){
	if(!obj) return { 'left' : 0, 'top' : 0 };
	var left_offset = obj.offsetLeft;
	var top_offset = obj.offsetTop;
	if(!left_offset && !top_offset && obj.offsetParent==null) {
	left_offset=parseInt(obj.style.left);
	top_offset=parseInt(obj.style.top);
	} else
	while ((obj = obj.offsetParent) != null)
	{
		left_offset += obj.offsetLeft;
		top_offset += obj.offsetTop;
	}

	return { 'left' : left_offset, 'top' : top_offset };
}

function _umlRegMover(mover,movparent) {
	if(_umlunable_img) return;
	var it=document.getElementById(mover);
	var itpar=document.getElementById(movparent);
	if(!it || !itpar) return;
	if(!_uml_ie_img && itpar.style.position!='fixed') {itpar.style.position='fixed';}
	_umlparents[mover]=itpar;
	if(_uml_ie_img) {
		_umlscrX_img=document.body.scrollLeft;
		_umlscrY_img=document.body.scrollTop;
		var pos=_umlGetCoord(itpar);
		_umlcoords_img[mover]=[pos['left']+_umlscrX_img,pos['top']+_umlscrY_img];

		itpar.style.left=_umlcoords_img[mover][0]+'px';
		itpar.style.top=_umlcoords_img[mover][1]+'px';

		it.attachEvent('onmousedown',_umlDown);
	}
		else it.addEventListener('mousedown',_umlDown,false);
	it.style.cursor="move";
}

function _umlMove(e) {
	if(_uml_ie_img) e=event;
	if(!_umlhave_img) return;
	if(_uml_ie_img && (e.button&1)==0) {_umlUp(e);return;}

	_umlparents[_umlhave_img.id].style.left=(_umloffX_img+e.clientX)+'px';
	_umlparents[_umlhave_img.id].style.top=(_umloffY_img+e.clientY)+'px';
	if(window.getSelection) {
		window.getSelection().removeAllRanges();
		} else if(document.selection) {
			if(document.selection.type!='none') document.selection.empty();
		
		}
}

function _umlScroll(e) {
	if(_uml_ie_img) e=event;
	for(var i in _umlcoords_img) {
		var newx=_umlcoords_img[i][0]+document.body.scrollLeft-_umlscrX_img;
		if(newx+_umlparents[i].offsetWidth<document.body.scrollWidth) _umlparents[i].style.left=newx+'px';
		var newy=_umlcoords_img[i][1]+document.body.scrollTop-_umlscrY_img;
		if(newy+_umlparents[i].offsetHeight<document.body.scrollHeight) _umlparents[i].style.top=newy+'px';
		}
}


function _umlDown(e) {
	if(_uml_ie_img) {
		if(!_umlparents[event.srcElement.id]) return;
		e=event;
		if(e.button && (e.button&1)!=1) return;
		_umlhave_img=e.srcElement;
		} else {
		_umlhave_img=this;
		e.stopPropagation();
		}
	var pos=_umlGetCoord(_umlparents[_umlhave_img.id]);
	_umloffX_img=pos['left']-e.clientX;
	_umloffY_img=pos['top']-e.clientY;
	if(_uml_ie_img) {
		_umlscrX_img=document.body.scrollLeft;
		_umlscrY_img=document.body.scrollTop;
		var pos=_umlGetCoord(_umlparents[_umlhave_img.id]);
		_umlcoords_img[_umlhave_img.id]=[pos['left'],pos['top']];
	}
}

function _umlUp(e) {
	if(!_umlhave_img) return;
	if(_uml_ie_img) {
		var pos=_umlGetCoord(_umlparents[_umlhave_img.id]);
		_umlcoords_img[_umlhave_img.id]=[pos['left'],pos['top']];
	}
	_umlhave_img=0;
}