/* hint function */

var _d = document, _n = navigator.userAgent, _w = window;

/* style definition */

_d.write(
    '<style type="text/css">',
    '#hint { ',
    '	border: 1px solid #333;',
    '	background: #ffffe1; ',
    '	padding: 2px 4px; ',
    '	position: absolute; ',
    '	visibility: hidden; ',
    '	white-space: nowrap; ',
    '	text-align: left; ',
    '	font-size: 11px; ',
    '	color: #000; ',
    '}',
    '#shadow { ',
    '	position: absolute;',
    '	background: #000;',
    '	opacity: 0.15; ',
    (new BWC().ie?
        /* ie styles only */
        '	filter: alpha(opacity=15);'
        /* ie styles end */
        : ''),
    '}',
    '</style>'
    );

/* style definition end */

function hint(o, html)
{
    /* show and hide delay in ms */
    var showDelay = 10,
    hideDelay = 100;

    if(typeof ho == 'undefined')
        hintInit = function()
        {
            ho = _d.createElement('div');
            sho = _d.createElement('div');
        }();

    if(typeof hintTid == 'undefined')
        hintTid = null;
    else if(hintTid)
        clearTimeout(hintTid);

    if($o('hint') == null && o)
    {
        ho.id = 'hint';
        ho.className = 'l';
        ho.innerHTML = html;

        sho.id = 'shadow';
        sho.style.visibility = 'hidden';

        _d.body.appendChild(sho);
        _d.body.appendChild(ho);

        var	oW = ho.offsetWidth,
        oH = ho.offsetHeight,
        scrW = _d.body.clientWidth,
        scrH = (new BWC).op? _d.body.clientHeight : _d.documentElement.clientHeight,
        scllH = _d.documentElement.scrollTop;

        o.onmousemove = function(e)
        {
            e = DRG.fixE(e);

            var x = e? e.clientX : 0,
            y = e? e.clientY : 0;

            x = x + oW < scrW? x + 10 : x - oW - 10;
            y = y + scllH + 20 + oH < scrH + scllH? y + scllH + 20 : y + scllH - oH - 10;

            ho.style.left = x + 'px';
            ho.style.top = y + 'px';

            with(sho.style)
            {
                width = oW + 'px';
                height = oH + 'px';
                left = x + 2 + 'px';
                top = y + 2 + 'px';
                }

        }

        o.onmouseout = function(){
		
            removeHint();
		
        }

        hintTid = setTimeout(
            function()
            {
                ho.style.visibility = 'visible';
                sho.style.visibility = 'visible';
            }
            , showDelay);

    }
    else if($o('hint') && $o('shadow') && !o)
    {
        hintTid = setTimeout(
            function()
            {
                removeHint();
            }
            , hideDelay);
    }
    else if($o('hint') && $o('shadow') && o)
    {
        removeHint();
        hint(o, html);
    }
	
    function removeHint()
    {
        try {
            _d.body.removeChild(sho);
            _d.body.removeChild(ho);
        } catch (exception) {}
    }
	
}

function linksInit(o) 
{
   o = typeof o == 'undefined'? _d : o;
	 
	  var arr = $o(o, 'a');

    for(var x in arr) {
        if(arr[x].rev) {
            arr[x].onmouseover = function()
            {
                this.title = '';
                this.alt = '';
                hint(this, this.rev.replace(/(\d+)/g,'<b>$&</b>','g'));
            }
        }
    }
    
    var arr = $o(o, 'li');

    for(var x in arr) {
        if(arr[x].title) {
            arr[x].onmouseover = function()
            {
            	var t = this.title;
            	hint(this, this.title.replace(/(\d+)/g,'<b>$&</b>','g'));
            	this.title = '';
            	this.onmouseout = function()
							{ 
								this.title = t; 
								_d.body.removeChild($o('hint'));
								_d.body.removeChild($o('shadow'));
							}
            }
        }
    }
    
}

/* hint function end */

/* Find element function */

function $o()
{
	var a = $o.arguments;

	if(typeof a[0] == 'string' && a[0].indexOf('#') != 0)
		return eval('_d.getElementById(a[0])' + (a[1] == 1? '.style' : ''));
	else if(typeof a[0] == 'string' && a[0].indexOf('#') == 0)
		return $o($o(a[0].substring(1)), a[1], a[2], a[3]);
	else if(typeof a[0] == 'object' && typeof a[1] == 'string' && typeof a[2] == 'undefined')
		return a[0].getElementsByTagName(a[1]);
	else if(typeof a[0] == 'object' && a[2] >= 0 && typeof a[3] == 'undefined')
		return a[0].getElementsByTagName(a[1])[a[2]];
	else if(typeof a[0] == 'object' && a[2] >= 0 && a[3] == 1)
		return a[0].getElementsByTagName(a[1])[a[2]].style;
	else
		return;
}

/* Find element function end */

/* get element by class name */

function $c(_e, classId, o)
{
var a = [], o = typeof o == 'string'? $(o) : typeof o == 'object'? o : d;
	
	for(var x = 0; x <= $o(o, _e).length - 1; x++)
		if($o(o, _e, x).className.indexOf(classId) != -1)
			a[a.length] = $o(o, _e, x);
			
	return a;
}

/* get element by class name end */

/* Browser check class */

function BWC(){

	this.dom = _d.getElementById;
	this.ie4 = _d.all && !this.dom?  true : false;
	this.ns4 = _d.layers? true : false;

	this.ns = _n.indexOf('Netscape') > -1 && !this.ns4;
	this.ff = _n.indexOf('Firefox') > -1;
	this.mz = _n.indexOf('Gecko') > -1 && !this.ns && !this.ff;
	this.op = _n.indexOf('Opera') > -1;
	this.ie = _n.indexOf('MSIE') > -1 && !this.op && !this.ie4;
	this.ie6 = _n.indexOf('MSIE 6') > -1 && !this.op && !this.ie4;

}

/* Browser check class end */

/* Drag object */

var DRG = {

	obj : null,

	init : function(o, oRoot, minX, maxX, minY, maxY, x, y, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
	{
		o = typeof o == 'object'? o : $o(o);
		oRoot = typeof oRoot == 'object'? oRoot : $o(oRoot);
	
		o.onmousedown	= DRG.start;

		o.hmode = bSwapHorzRef? false : true;
		o.vmode = bSwapVertRef? false : true;

		o.root = oRoot && oRoot != null? oRoot : o;

		o.root.style.left = (o.hmode && !isNaN(x))? x + 'px' : o.root.offsetLeft + 'px';
		o.root.style.top = (o.vmode && !isNaN(y))? y + 'px' : o.root.offsetTop + 'px';
		o.root.style.right = (!o.hmode && !isNaN(x))? x + 'px' : 0;
		o.root.style.bottom = (!o.hmode && !isNaN(x))? y + 'px' : 0;

		o.minX	= typeof minX != 'undefined'? minX : null;
		o.minY	= typeof minY != 'undefined'? minY : null;
		o.maxX	= typeof maxX != 'undefined'? maxX : null;
		o.maxY	= typeof maxY != 'undefined'? maxY : null;

		o.xMapper = fXMapper? fXMapper : null;
		o.yMapper = fYMapper? fYMapper : null;

		o.root.onDragStart = new Function;
		o.root.onDragEnd = new Function;
		o.root.onDrag = new Function;
	},

	start : function(e)
	{
		var o = DRG.obj = this;
		e = DRG.fixE(e);
		var y = parseInt(o.vmode? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode? o.root.style.left : o.root.style.right );

		o.root.onDragStart(x, y);

		o.lastMouseX	= e.clientX;
		o.lastMouseY	= e.clientY;

		if (o.hmode) {
			if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
			if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
		} else {
			if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
			if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
		}

		if (o.vmode) {
			if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
			if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
		} else {
			if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
			if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
		}

		d.onmousemove	= DRG.drag;
		d.onmouseup		= DRG.end;

		return false;
	},

	drag : function(e)
	{
		e = DRG.fixE(e);
		var o = DRG.obj;

		var ey = e.clientY;
		var ex = e.clientX;
		var y = parseInt(o.vmode? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode? o.root.style.left : o.root.style.right );
		var nx, ny;

		if (o.minX != null) ex = o.hmode? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
		if (o.maxX != null) ex = o.hmode? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
		if (o.minY != null) ey = o.vmode? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
		if (o.maxY != null) ey = o.vmode? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

		nx = x + ((ex - o.lastMouseX) * (o.hmode? 1 : -1));
		ny = y + ((ey - o.lastMouseY) * (o.vmode? 1 : -1));

		if (o.xMapper)	nx = o.xMapper(y)
		else if (o.yMapper)	ny = o.yMapper(x)

		o.root.style[o.hmode? "left" : "right"] = nx + "px";
		o.root.style[o.vmode? "top" : "bottom"] = ny + "px";
		o.lastMouseX	= ex;
		o.lastMouseY	= ey;

		/* this writes togeter with drag action */
		o.root.onDrag(nx, ny);

		return false;
	},

	end : function()
	{
		d.onmousemove = null;
		d.onmouseup   = null;

		/* this writes end result of the drag action */
		DRG.obj.root.onDragEnd(parseInt(DRG.obj.root.style[DRG.obj.hmode? "left" : "right"]),
		 parseInt(DRG.obj.root.style[DRG.obj.vmode ? "top" : "bottom"]));

		DRG.obj = null;
	},

	fixE : function(e)
	{
		if (typeof e == 'undefined') e = _w.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	}
};

/* Drag object end */

