/*
AutoQuotator - скрипт на языке JavaScript для форумов системы uCoz
Copyright © VACion, 2009

Автор скрипта - VACion, ICQ#: 6-343-207, e-mail: vacion(at)li.ru.

Подробная информация: http://vacionlib.org.ru/forum/18-162-1
*/

var autoQuotator=function()
{
	this.aQMC="";this.aQI="";this.aQT=0;this.aQST=0;
	var aQMC,aQI,aQT,aQST,n=[],aQTimeout=false,aQShowTmt=false,aQElement=document.createElement("div"),gEBC=function(n){
		for(var e=document.getElementsByTagName("*"),c,a=[],i=0;i<e.length;i++){
			c=e[i];if(!c.className) continue;
			for(var b=0,t,p=c.className.split(' ');b<=p.length;b++){
				t=p[b];if(t==n){a[a.length]=c;break;}}}
		return a;
	},iCh=function(n,p){
		var a=p.getElementsByTagName('*'),i;if(p==n){return true;}
		for(i=0;i<a.length;i++){if(a[i]==n){return true;}}
		return false;
	},aQHide=function(){
			aQElement.style.display="none";
			aQTimeout=false;
	},aQShow=function(i){return(function(){
			get_selection();if(!selection){return;}
			aQElement.innerHTML=rep2D(aQI,n[i]);
			aQElement.style.display="";
			aQTimeout=setTimeout(aQHide,aQT);});
	},fE=function(e){
		e=e||event;
		if(e.pageX==null&&e.clientX!=null){
			html=document.documentElement,body=document.body;e.pageX=e.clientX+(html&&html.scrollLeft||body&&body.scrollLeft||0)-(html.clientLeft||0);
			e.pageY=e.clientY+(html&&html.scrollTop||body&&body.scrollTop||0)-(html.clientTop||0);}
		return(e);
	},rep2D=function(s,y){
		y=y.toString().replace("javascript:","").replace("selection","window.selection").replace(";","");
		y=decodeURIComponent(y);
		return(s=s.replace(/\$N\$/g,y));
	},ocCheck=function(e){
		e=e||event;
		t=e.target||e.srcElement;
		if(!iCh(aQElement,t)){aQHide();}
	},agent=navigator.userAgent.toLowerCase(),isie=((agent.indexOf("msie")!=-1)&&(agent.indexOf("opera")==-1)),oldselection="";
	this.Hide=aQHide;
	this.startAQ=function(){
		if(!(this.aQMC&&this.aQI&&this.aQT&&this.aQST)){throw("Ошибка: скрипт должен быть настроен перед запуском");}
		aQMC=this.aQMC;
		aQI=this.aQI;
		aQT=this.aQT;
		aQST=this.aQST;
		n=gEBC("postQuote");
		if(!n) return;
		a=gEBC(this.aQMC);
		c=aQElement;
		c.style.backgroundColor="#ffffff";
		c.style.border="0px";
		c.style.padding="0px";
		c.style.display="none";
		c.style.position="absolute";
		c.style.zindex="100";
		if(isie){document.body.onload=function(o){o=o?o:function(){};return(function(e){o(e);document.body.appendChild(aQElement);});}(document.body.onload);}else{document.body.appendChild(aQElement);}
		for(i=0;i<a.length;i++){
			cai=a[i];
			cai.selection="";
			cai.quotIndex=i;
			cai.onmousemove=function(om){
				om=om?om:function(){};
				return(function(e){
					om(e);e=fE(e);
					get_selection();
					if(oldselection!=selection){
						if(!selection){aQHide();}else{
							if(aQTimeout){
								clearTimeout(aQTimeout);
								aQElement.style.left=e.pageX+"px";
								aQElement.style.top=(e.pageY+8)+"px";
								aQTimeout=setTimeout(aQHide,aQT);
							}else{
								if(aQShowTmt){clearTimeout(aQShowTmt);}
								aQElement.style.left=e.pageX+"px";
								aQElement.style.top=(e.pageY+8)+"px";
								aQShowTmt=setTimeout(aQShow(this.quotIndex),aQST);}}}
					oldselection=selection;});}(cai.onmousemove);}
		document.onclick=function(o){o=o?o:function(){};return(function(e){o(e);ocCheck(e);});}(document.onclick);
	};
}
//Инициализация
var AQ=new autoQuotator;

//Настройки
 //Класс объекта, при выделении текста в котором должен появляться AutoQuotator
AQ.aQMC="posttdMessage";
 //HTML-код всплывающей кнопки ($N$ - вызов цитирования, используется в служебных целях)
AQ.aQI='<div class="autoQuotator"><table cellpadding="0" cellspacing="0" border="0"><tr><td valign="middle" align="left"><img src="http://keyzet.kz/bbicons/misc/smquoter.gif" border="0" align="middle"/></td><td valign="middle" align="left"><a href="javascript://" class="noun" onclick="get_selection();$N$;AQ.Hide();">Цитировать</a></td></tr></table></div>';
 //Время задержки в миллисекундах(1/1000 секунды) перед показом кнопки 
AQ.aQST=400;
 //Время задержки в миллисекундах(1/1000 секунды) после показа кнопки перед её исчезновением
AQ.aQT=4000;

//Запуск скрипта
AQ.startAQ();
