/* Field help */
jQuery(function () {
    var helpWindow = jQuery('#help-window');
    if (typeof helpWindow[0] == 'undefined') {
        var helpWindow = $('<div id="help-window">' +
			'<div id="help-window-top"></div>' +
			'<div id="help-window-center"></div>' +
			'<div id="help-window-bottom"></div>' +
		'</div>').appendTo('body');
    }
    var helpWindowContent = jQuery('#help-window-center');
    if (jQuery.browser.msie && jQuery.browser.version == '6.0') {
        helpWindow.append('<iframe frameborder="0" scrolling="no" src="#" width="243"></iframe>');
    };
    var helpWindowFrame = helpWindow.children('iframe');
    /* Close help window */
    function closeHelpWindow() {
        helpWindow.timeOut = setTimeout(function () {
            helpWindow.stop();
            if (!jQuery.browser.msie)
                helpWindow.animate({ opacity: 0 }, 200, function () {
                    jQuery(this).css({ display: 'none' }).removeClass('rightHelpWindow');
                    helpWindowContent.text('');
                });
            else {
                helpWindow.css({ display: 'none' }).removeClass('rightHelpWindow');
                helpWindowContent.text('');
            };
        }, 50);
    };

    jQuery('div.td-02 del, div.papers-block a, div.submenu-items a, div.newPrice span').each(function () {
        jQuery(this).hover(function () {
            /* Clear new settigns */
            clearTimeout(helpWindow.timeOut);
            helpWindow.stop();
            if (!jQuery.browser.msie)
                helpWindow.css({ opacity: 0, display: 'none' }).removeClass('rightHelpWindow');
            else
                helpWindow.css({ display: 'none' });
            helpWindowContent.text('');

            /* Open help winodw */
            var helpField = jQuery(this);
            var title = helpField.attr('title');
            if (title) {
                var documentWidth = jQuery(document).width();
                helpField.attr('title', '');
                helpWindow.css({ display: 'block', top: helpField.offset().top + 'px', left: (helpField.offset().left - 6) + 'px' });
                if (helpField.offset().left >= documentWidth - helpWindow.width()) {
                    helpWindow.addClass('rightHelpWindow');
                };
                helpWindowFrame.css({ display: 'block', height: helpWindow.height() });
                helpWindowContent.html(title);
                helpWindow.css({ top: (parseInt(helpWindow.css('top')) - helpWindow.height()) + 'px' });
                if (!jQuery.browser.msie)
                    helpWindow.animate({ opacity: 1 }, 200);
                else
                    helpWindow.css({ display: 'block' });
            };
        },
		function () {
		    if (helpWindowContent.text()) {
		        jQuery(this).attr('title', helpWindowContent.html());
		    };
		    closeHelpWindow();
		});
    });
});
