var tout = new Array();
var hht = new Array();
var prev;
var psel = '';
var ElementsNone=2;
var wExec = 1;
var no = 0;
var imgparser = 0;

// -------------------------------------------- Предварительная инициализация ------------


// Проверяем знает ли браузер про HTMLElement. Хак для Firefox
if (typeof(HTMLElement) != "undefined") {
    var _emptyTags = { "IMG": true };
    
    HTMLElement.prototype.__defineGetter__("outerHTML", function () {
       var attrs = this.attributes;
       var str = "<" + this.tagName;
       for (var i = 0; i < attrs.length; i++)
          str += " " + attrs[ i ].name + "=\"" + attrs[ i ].value + "\"";
    
       if (_emptyTags[this.tagName])
          return str + ">";
    
       return str + ">" + this.innerHTML + "</" + this.tagName + ">";
    });
    
    HTMLElement.prototype.__defineSetter__("outerHTML", function (sHTML) {
       var r = this.ownerDocument.createRange();
       r.setStartBefore(this);
       var df = r.createContextualFragment(sHTML);
       this.parentNode.replaceChild(df, this);
    });
}

// ---------------------------------------------- ПРОЦЕДУРА СКРУГЛЕНИЯ КРАЕВ ------------

function process_round()
{

	// ОСНОВНОЙ КОД МОЕЙ ПРОГРАММЫ

	wExec = 0;

	var cn, cs, cw, ch, i, omg, dl, dw, dr, q, cr, alg;
	var px, py, pcx, pcy, ex;
	var tl, tr, br, bl;
	var msie6 = navigator.userAgent.match('MSIE 6.0') ? 1 : 0;

	omg = document.getElementsByTagName('img');
	for (cn = 0; cn<omg.length; cn++)
	if (omg[cn].className.substr(0,5) == 'round')
	{

		i = omg[cn];
		cr = i.alt;
		if (cr)
		{

			alg = i.align;
			if (i.parentNode.style.textAlign == 'center') { msie6 = 0; alg = 'center'; i.parentNode.style.textAlign = ''; }
			if (i.parentNode.style.width) { pcx = i.parentNode.style.width; pcx = parseInt ( pcx.substr(0,pcx.length-2) ); } else pcx = 0;
			if (i.parentNode.style.height) { pcy = i.parentNode.style.height; pcy = parseInt ( pcy.substr(0,pcy.length-2) ); } else pcy = 0;

			cs = i.src;
			cw = parseInt(i.width);
			ch = parseInt(i.height) - 1;
			if (i.border) ex = parseInt(i.border); else ex = 0;
			if (alg == 'center') {
				if (pcx == 0) pcx = cw; else if (pcy == 0) pcy = ch;
				if (msie6) px = (pcx + ex - cw) / 4; else px = (pcx + ex - cw) / 2;
				py = Math.floor((pcy + ex - ch) / 2);
			}
			else { px = 0; py = 0; }

			dl = i.className.substr(5,omg[cn].className.length-5);
			tl = ''; tr = ''; br = ''; bl = '';

			for (q = 0; q <= dl; q++) {
				dw = Math.floor(Math.sqrt(dl*dl - q*q));
				tl += '<i class="'+cr+'" style="width:'+(dl-dw)+'px;margin-top:'+(dl-q)+'px;"></i>';
				tr += '<i class="'+cr+'" style="margin-left:'+(cw-(dl-dw))+'px;width:'+(dl-dw)+'px;margin-top:'+(dl-q)+'px;"></i>';
				br += '<i class="'+cr+'" style="margin-left:'+(cw-(dl-dw))+'px;width:'+(dl-dw)+'px;margin-top:'+(ch-(dl-q))+'px;"></i>';
				bl += '<i class="'+cr+'" style="width:'+(dl-dw)+'px;margin-top:'+(ch-(dl-q))+'px;"></i>';
			}

			i.outerHTML = '<cite style="width:'+(cw+ex)+'px;height:'+(ch+ex)+'px;float:left;margin-left:'+px+'px;margin-top:'+py+'px;"><img  style="position:absolute;" src="' + cs + '">' + tl + tr + br + bl + '</cite>';
		}

	}

	wExec = 1;
}

// ---------------------------------------------- ПРОЦЕДУРА ВЫДВИЖНЫХ ПАНЕЛЕЙ ------------
// <var name="Как называется" class=""> все, кроме div </var>

function dropfind()
{

	var d, e, r, s, m, p;

	// Убирает все заменители

	e = document.getElementsByTagName('samp')
	for (r = 0; r < e.length; r++) e[r].style.display = 'none';

	// Выстраивает вместо них дропфинды

	r = 0; m = ''; s = '';
	while (e = document.getElementsByTagName('var')[0])
	{

		r++;
		if (e.getAttribute('popup')!='no') p = 'onclick="no=1;dac('+r+');"'; else p = '';
		if (e.className) s = 'class="'+e.className+'"'; else m = 'background:white;border:1px dotted black;width:' + e.getAttribute('width') + 'px;'; 
		d = '<span style="z-index:700;display:none;position:absolute;'+m+'" id="dac'+r+'" '+s+' '+p+'>';
		d += e.innerHTML;
		d += '</span>';
		d += '<span class="dac" href="javascript://" onclick="no=1;dac('+r+');">' + e.getAttribute('name') + '</span>';
		e.outerHTML = d;

	}

}

function openDAC(id,o,h,c)
{

	var e = document.getElementById('dac'+id);
	if (tout[id]) clearTimeout(tout[id]);
	if (o == 0) if (c > 0) e.style.overflow = 'hidden';
	else {
		e.style.display = 'none';
		e.style.overflow = 'visible';
		}

	o += c;
	if (o > 100) { o = 100; no = 0; }
	if (o < 0) { o = 0; no = 1; }

	e.style.marginTop = Math.floor(o*0.23) + 'px';
	e.style.height = Math.floor(o/100*h) + 'px';
	e.style.opacity = (o / 100);
	e.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity:" + o + ");";
	if (o < 100) tout[id] = setTimeout('openDAC('+id+','+o+','+h+','+c+');', 35);
}

function dac(id)
{
	var e = document.getElementById('dac'+id);
	if (e) {

		if (prev) openDAC(prev,100, document.getElementById('dac'+prev).clientHeight,-17);
		if (e.style.display == 'none') { 
			prev = id;
			e.style.display = 'inline';
			if (!hht[id]) hht[id] = e.clientHeight;
			openDAC(id,0,hht[id],17); 
		}
		else { openDAC(id,100,e.clientHeight,-17);  }

	}
}


// ----------------------------------

function sboit(id,v,k) {

	var h = document.getElementById('_sf'+id);
	var e = document.getElementById('_sf'+id+'i');
	var s = document.getElementById('_sf'+id+'d');
	e.value = v;
	h.value = k;
	s.style.display = 'none';
	
}

function sbsdd(id) {

	var s = document.getElementById('_sf'+id+'d');
	if (s.style.display == '') s.style.display = 'none';
	if (s.style.display == 'none') {
		s.style.display = 'block'; 
		if (psel != id && psel) 
		{
			var d = document.getElementById('_sf'+psel+'d');
			d.style.display = 'none';
		}
		psel = id;

	} else s.style.display = 'none';

}

function selectParser()
{

	var d, e, r, w, i, n, s, a, u1, u2;

	r = 0; u1 = ''; ps = 0;
	while (e = document.getElementsByTagName('select')[ps])
	if (e.getAttribute('multiple') === null || e.getAttribute('multiple') === false)
	{
		r++;
		a = e.getAttribute('width');
		if (a == null) a = 150; else a = parseInt(a);

		n = e.getElementsByTagName('option');
		w = ' style="width:' + (a+21) + 'px; ';
		if (n.length > 7) w += ' height: 100px; overflow-y:scroll;overflow-x:none;" '; else w += '"';
		d = '<span class="select">';
		d += '<div class="options" id="_sf'+r+'d"'+w+' style="height:40px;overflow:scroll;">';
		w = ' style="width:' + a + 'px;"';

		for (i = 0; i < n.length; i++)
		{
			d += '<div onclick="sboit('+r+', \''+n[i].innerHTML+'\', \''+n[i].value+'\');">'+n[i].innerHTML+'</div>';
			if (n[i].getAttribute('selected') != null) { u1 = n[i].value; u2 = n[i].innerHTML; }
		}
		if (u1=='') { u1 = n[0].value; u2 = n[0].innerHTML; }

		d += '</div><table cellpadding="0" cellspacing="0"><tr><td class="lcorn"></td><td>';
		d += '<input onclick="sbsdd('+r+');" class="xinput" type="text"'+w+' id="_sf'+r+'i" value="'+u2+'">';
		d += '<input type="hidden" name="'+e.getAttribute('name')+'" value="'+u1+'" id="_sf'+r+'"></td>';
		d += '<td class="rcorn" onclick="sbsdd('+r+');"></td></tr></table></span>';

		e.outerHTML = d;

	} else ps += 1; 


}

/* ------------------------------------------------------------ */
function timeoutstart()
{
	if (imgparser) process_round();
	dropfind();
	// selectParser();
	if (wExec) if (ElementsNone--) setTimeout("timeoutstart();",1500);
} 


/* --- Обеспечивает скрытие областей при нажатии на сам документ --- */

setTimeout("timeoutstart();", 250);
window.onload = function () { imgparser = 1; ElementsNone = 2; timeoutstart(); }
document.onclick = function () { if (no==0) dac(prev); }