jQuery.fn.get_pos = function() {
	var x = 0, y = 0;
    var el = this.get(0);
	while(el) {
		x += el.offsetLeft || 0;
		y += el.offsetTop || 0;
		el = el.offsetParent;
	}
	return {x:x, y:y};
}

$(document).ready(function() {
    data = new Array();
    $('.manager_info').each(function(i, n) {
        data[i] = $(n).html();
    });
    tooltip = new tooltip(data);
    
    $('input.stxt').focus(function() {
        var val = $(this).val();
        var i = $(this);
        if (val == 'Поиск' || val == 'поиск') {
            i.val('');
        }
    });
    
    $('input.stxt').blur(function() {
        var val = $(this).val();
        var i = $(this);
        if (val == '' || val == 'поиск') {
            i.val('Поиск');
        }
    });
});

/* компонент всплывающей подсказки */
tooltip = function(info) {
    this.info = info;
    this.shown = false;
    this.obj = false;
    this.link = null;
    
    this.init();
}

tooltip.prototype.init = function() {
    var container = document.createElement("div");
    var div = document.createElement("div");
    $(div).addClass('tooltip');
    this.obj = div;
    $(container).attr('id', 'tooltip_helper').append(div);
    $('body').append(container);
    
    var tooltip = this;
    
    $(document).ready(function() {
        $(this).click(function(e){
            var link = e.originalTarget ? e.originalTarget : e.srcElement;
            if (tooltip.link && link != tooltip.link) {
                tooltip.hide();
            }
        });
    });
}

tooltip.prototype.show = function(e, n) {/*
    var tooltip = this;
    var link = e.originalTarget?e.originalTarget:e.srcElement;
    this.link = link;
    var pos = $(link).get_pos();
    
    if (this.shown !== false) {
        $(this.obj).hide(function() {
            var shown_n = tooltip.shown;
            tooltip.shown = false;
            
            if (shown_n !== n) {
                $(tooltip.obj).css({
                    top: (pos.y - 62),
                    left: (pos.x + $(link).width())
                }).html(tooltip.info[n]).show(function(){
                    tooltip.shown = n;
                });
            }
        });
        return false;
    }
    $(this.obj).css({
        top: (pos.y - 62),
        left: (pos.x + $(link).width())
    }).html(this.info[n]).show(function(){
        tooltip.shown = n;
    });*/
}

tooltip.prototype.hide = function(){
    var tooltip = this;
    $(this.obj).hide(function() {
        tooltip.shown = false;
    });
}