///////////////////////////////////////////////////////////
//
//  Оригиналът е на
//  http://www.bosrup.com/web/overlib/
//
//  Обаче там е без ускоренията и тия неща, така че
//  ползвайте това.
//
///////////////////////////////////////////////////////////

var ol_ready= false;
var ol_vis= false;

var obj= null;
var theObj= null;
var pTXT= null;

MENU_BODY_WIDTH= 250;
MENU_OPACITY= 90;
MENU_FADE_STEP= 0.8;

OVERLIBBIE_OPACITY= 85;
OVERLIBBIE_MOVE_ACCEL= 0.02;
OVERLIBBIE_MAX_SPEED= 2;
OVERLIBBIE_FADESTEP_INCREASE= 0.9;

OVERLIBBIE_MOZ_TO_IE_OPACITY_RATIO= 0.96;

OVERLIBBIE_STILL_OPAQUE= 0.2;

OVERLIBBIE_R_DISTANCE_X= - 8;
OVERLIBBIE_R_DISTANCE_Y= 8;

OVERLIBBIE_L_DISTANCE_X= - 220;
OVERLIBBIE_L_DISTANCE_Y= OVERLIBBIE_R_DISTANCE_Y;

///////////////////////////////////////////////////////////

OVERLIBBIE_DISTANCE_X= - 8;
OVERLIBBIE_DISTANCE_Y= 8;

OVERLIBBIE_CURRENT_ORIENTATION= 'R';


preloadImages ("img/v2/overlibbie_hinv_top.gif");

var movestep;
killMovement ();


function overlibbie () {
	
	if (document.all) {
		obj= document.all['overDiv'];
	} else if (document.getElementById) {
		obj= document.getElementById('overDiv');
	} else if (document.layers) {
		obj= document.layers['overDiv'];
	} else
		return false;

	theObj= (document.layers ? obj : obj.style);

	if (document.all) {
		obj= document.all['overSpan'];
	} else if (document.getElementById) {
		obj= document.getElementById('overSpan');
	} else if (document.layers) {
		obj= document.layers['overSpan'];
	}

	_theobj= document.getElementById ("overDiv");

	/////////////

	browserdetect= _theobj.filters? "ie" : typeof (_theobj.style.MozOpacity) == "string" ? "mz" : "";

	/////////////

	if (browserdetect == "ie")
		_theobj.filters.alpha.opacity= 0;

	else if (browserdetect == "mz")
		_theobj.style.MozOpacity= 0;

	/////////////

	olMouseCapture ();

	ol_ready= true;

	return ol_ready;
}

function overlib (txt) {

	document.onmousemove= olMouseMove;

	txt= txt;

	if (!ol_ready)
		return false;

	if (txt != pTXT) {

		pTXT= txt;

		txt += "\n";
		if (document.layers) {
			var lyr= obj.document;
			lyr.write (txt);
			lyr.close ();

		} else if (typeof obj.innerHTML != 'undefined') {
			obj.innerHTML= '';
			obj.innerHTML= txt;

		} else {
			range= document.createRange ();
			range.setStartAfter (obj);
			domfrag= range.createContextualFragment (txt);
			
			while (obj.hasChildNodes ()) {
				obj.removeChild (obj.lastChild);
			}
			
			obj.appendChild (domfrag);
		}

	}

	/////////////

	if (typeof (olfadestep) != typeof (undefined))
		clearInterval (olfadestep);

	/////////////

	if (
		(browserdetect == "mz" && _theobj.style.MozOpacity >= OVERLIBBIE_OPACITY * OVERLIBBIE_STILL_OPAQUE / 100) ||
		(browserdetect == "ie" && _theobj.filters.alpha.opacity >= OVERLIBBIE_OPACITY * OVERLIBBIE_STILL_OPAQUE)
		)
		do_not_reposition= true;
	else
		do_not_reposition= false;

	/////////////

	if (browserdetect == "ie")
		_theobj.filters.alpha.opacity= OVERLIBBIE_OPACITY;

	else if (browserdetect == "mz")
		_theobj.style.MozOpacity= MENU_OPACITY / 100 * OVERLIBBIE_MOZ_TO_IE_OPACITY_RATIO;

	/////////////

	if (do_not_reposition)
		return true;

//	reposition ();
	jumpNow= true;

	/////////////

	// theObj.visibility = 'visible';
	ol_vis= true;

}

function nd () {

	if (!ol_ready)
		return false;

//	theObj.visibility = 'hidden';
//	ol_vis= false;

	olFade ();

}

function olMouseCapture () {

//	document.onmousemove= olMouseMove;
	document.onmousemove= nothin;

	if (document.layers) {
		capExtent.captureEvents (Event.MOUSEMOVE);
	}
}

x= 0;
y= 0;

function nothin () {
}

_TARGET_X= 0;
_TARGET_Y= 0;

function olMouseMove (e) {

	if (!ol_vis)
		return true;

	var e = (e) ? e : event;

	if (e.pageX) {

		x = e.pageX;
		y = e.pageY;

	} else if (e.clientX) {

		x = e.clientX + document.body.scrollLeft;
		y = e.clientY + document.body.scrollTop;

	}

	x+= OVERLIBBIE_DISTANCE_X;
	y+= OVERLIBBIE_DISTANCE_Y;

	if (jumpNow)
		return reposition ();

	_TARGET_X= x;
	_TARGET_Y= y;

	if (!moving ()) {

//		killMovement ();
//		movestep= setInterval ("slideTo (" + x + ", " + y + ");", 25);
//		slideTo (x, y);

		movestep= setInterval ("slideTo ();", 25);
		slideTo ();

	}
	

}

_cX= 0;
_cY= 0;

//function slideTo (xL, yL) {
function slideTo () {
	
	xL= _TARGET_X;
	yL= _TARGET_Y;

	if ((xL == _cX) && (yL == _cY)) {
		killMovement ();
		return true;
	}

	if (screen) {
		if (xL > screen.width - 270) {
			xL= screen.width - 270;
		}
	}

	_nX=  ((xL - _cX) * OVERLIBBIE_MOVE_ACCEL);
	_nY=  ((yL - _cY) * OVERLIBBIE_MOVE_ACCEL);
	
	if (Math.abs (_nX) > OVERLIBBIE_MAX_SPEED)
		(_nX > 0) ? _nX= OVERLIBBIE_MAX_SPEED : _nX= -OVERLIBBIE_MAX_SPEED;

	if (Math.abs (_nY) > OVERLIBBIE_MAX_SPEED)
		(_nY > 0) ? _nY= OVERLIBBIE_MAX_SPEED : _nY= -OVERLIBBIE_MAX_SPEED;

	_cX+= _nX;
	_cY+= _nY;

	theObj.left = _cX + (!document.layers ? 'px' : 0);
	theObj.top = _cY + (!document.layers ? 'px' : 0);

}

function reposition () {

	jumpNow= false;

	/////////////

	xL= x;
	yL= y;

	if (screen) {
		if (xL > screen.width - 270) {
			xL= screen.width - 270;
		}
	}

	_cX= xL;
	_cY= yL;

	theObj.left = xL + (!document.layers ? 'px' : 0);
	theObj.top = yL + (!document.layers ? 'px' : 0);

	/////////////

	theObj.visibility = 'visible';

	return true;

}

function moving () {
	return (movestep != 'STATIC');
}

function killMovement () {
	clearInterval (movestep);
	movestep= 'STATIC';
}

///////////////////////////////////////////////////////////

var olfadestep;

function olFade () {

	olfadestep= setInterval ("olFadeLevel()",25);
}

function olFadeLevel () {

	if (browserdetect != 'ie' && browserdetect != 'mz') {

		clearInterval (olfadestep);
		olKill ();
		return true;
	}

	if (browserdetect == "ie")
		_theobj.filters.alpha.opacity= Math.floor (_theobj.filters.alpha.opacity * MENU_FADE_STEP * OVERLIBBIE_FADESTEP_INCREASE);

	else if (browserdetect == "mz")
		_theobj.style.MozOpacity= Math.floor (_theobj.style.MozOpacity * MENU_FADE_STEP * 100 * OVERLIBBIE_FADESTEP_INCREASE) / 100;
		
	if ((_theobj.style.MozOpacity <= 0.0) || (_theobj.filters.alpha.opacity <= 0)) {

		clearInterval (olfadestep);
		olKill ();

	}
}

function olKill () {

	theObj.visibility = 'hidden';

	if (moving ())
		killMovement ();

	theObj.left= (!document.layers ? '0px' : 0);
	theObj.top= (!document.layers ? '0px' : 0);

	ol_vis= false;
	document.onmousemove= nothin;
}

///////////////////////////////////////////////////////////


function showTW (txt) {
	if (!overlib)
		return true;

	if (txt.charAt (1) == ':') switch (txt.charAt (0)) {
		
		case 'L':
			showlTW (txt.substring (2, txt.length));
			break;

	} else {

//		if (OVERLIBBIE_CURRENT_ORIENTATION != 'R')
//			jumpNow= true;

		OVERLIBBIE_CURRENT_ORIENTATION= 'R';

		OVERLIBBIE_DISTANCE_X= OVERLIBBIE_R_DISTANCE_X;
		OVERLIBBIE_DISTANCE_Y= OVERLIBBIE_R_DISTANCE_Y;

		_top= document.getElementById ("overlibbie_top");

		if (_top)
			_top.src= "img/v2/overlibbie_top.gif";

		overlib (txt);

	}
}

function showlTW (txt) {

//	if (OVERLIBBIE_CURRENT_ORIENTATION != 'L')
//		jumpNow= true;

	OVERLIBBIE_CURRENT_ORIENTATION= 'L';

	OVERLIBBIE_DISTANCE_X= OVERLIBBIE_L_DISTANCE_X;
	OVERLIBBIE_DISTANCE_Y= OVERLIBBIE_L_DISTANCE_Y;

	_top= document.getElementById ("overlibbie_top");

	if (_top)
		_top.src= "img/v2/overlibbie_hinv_top.gif";

	if (overlib) {
		overlib (txt);
	}
}

function showuTW (txt) {
	if (overlib) {
		overlib (txt);
	}
}

function hideTW () {
	if (nd) {
		nd ();
	}
}

///////////////////////////////////////////////////////////