YAHOO.namespace('forex');
YAHOO.forex.Hint = function(glossaryTerms, options) {
    this._glossaryTerms = glossaryTerms;
    if (YAHOO.lang.isUndefined(options)) {
        var options = {};
    }
    this._tooltipId = options.tooltipId || 'tooltip' + Math.floor(Math.random() * 1000);
    this._hintClass = options.hintClass || 'hint';
    this._class = options.searchClass || 'glossaryHighlight';
    this._showCount = options.showCount || false;
    this._termLength = options.termLength || 3;
    while (YAHOO.util.Dom.get(this._tooltipId)) {
        this._tooltipId = 'tooltip' + Math.floor(Math.random() * 1000);
    }
    this._init();
};
YAHOO.forex.Hint.prototype = {
    _tooltip: null,

    _init: function() {
        var glossaryText = YAHOO.util.Dom.getElementsByClassName(this._class);
        for (var i = 0; i < glossaryText.length; i++) {
            this._replaceContent(glossaryText[i]);
        }

        var keywords = YAHOO.util.Dom.getElementsByClassName(this._hintClass, 'a');
        this._tooltip = new YAHOO.widget.Tooltip(this._tooltipId, {context:keywords, width:"300px"});
        this._tooltip.contextTriggerEvent.subscribe(this._setContext, this, true);
    },

    _initTerms: function(terms) {
        var result = [];
        for (var i = 0; i < this._termLength; i++) {
            result.push({string: [], indexes: [], endFlag: false});
            for (var j = 0; j < this._termLength - i; j++) {
                result[i].string.push('');
                result[i].indexes.push(0);
            }
        }
        return result;
    },

    _shiftTerms : function(terms) {
        terms[0].string.shift();
        terms[0].indexes.shift();
        terms[0].endFlag = (terms[0].endFlag) ? --terms[0].endFlag : false;
        for (var i = 1; i < terms.length; i++) {
            for (var j = 0; j < terms[i].string.length; j++) {
                terms[i].string[j] = terms[0].string[j];
                terms[i].indexes[j] = terms[0].indexes[j];
            }

            if (YAHOO.lang.isNumber(terms[0].endFlag) && (terms[0].endFlag + 1 < terms[i].string.length)) {
                terms[i].endFlag = terms[0].endFlag;
            }
        }

        terms[terms.length - 1].endFlag = false;

        return terms;
    },

    _makeTerms: function(terms, word, index) {
        if (!word) {
            return this._shiftTerms(terms);
        }
        var length1 = word.length;
        word = word.replace(/^\s*/g, '');
        var length2 = word.length, endPos = word.length;
        var lang = YAHOO.lang;
        while (lang.isNull(word.substr(endPos - 1, 1).match(/[a-zA-Z\u0430-\u044f\u0410-\u042f\)]/)) && endPos) {
            endPos--;
        }

        if (endPos < word.length) {
            word = word.substring(0, endPos);
            terms[0].endFlag = terms[0].string.length - 1;
            if (word == '') {
                return terms;
            }
            terms[0].endFlag++;
        }

        terms[0].string.push(word);
        terms[0].indexes.push(index + length1 - length2);

        return this._shiftTerms(terms);
    },

    _makeHint: function(terms, end) {
        var result = {element: null}
        for (var i in terms) {
            if (terms[i].endFlag && (terms[i].endFlag < terms[i].string.length - 1)) {
                continue;
            }
            var term = terms[i].string.join(' ')
            var termObject = this._glossaryTerms[term.toLowerCase()];
            if (termObject && !YAHOO.lang.isFunction(termObject)) {
                if (this._showCount) {
                    if (termObject.count >= this._showCount) {
                        break;
                    }
                    termObject.count = (termObject.count == null) ? 1 : ++termObject.count;
                }
                result.index = terms[i].indexes[0];
                result.length = terms[i].indexes.pop() + terms[i].string.pop().length - result.index;
                result.element = document.createElement('a');
                result.element.className = this._hintClass;
                result.element.setAttribute('href', termObject.link);
                result.element.innerHTML = term;
                break;
            }
        }

        return result;
    },

    _parseText: function(child) {
        var words = child.nodeValue.split(' ');
        var index = 0;
        var terms = this._initTerms();
        var i = -1;

        do {
            i++;
            var word = false;
            if (YAHOO.lang.isString(words[i])) {
                if ((words[i] == '') || words[i].match(/^\s$/)) {
                    index += words[i].length + 1;

                    continue;
                }

                word = words[i];
            }

            terms = this._makeTerms(terms, word, index);

            if (YAHOO.lang.isUndefined(terms[this._termLength - 1].string[0])) {
                break;
            }

            var object = this._makeHint(terms);
            if (YAHOO.lang.isNull(object.element)) {
                if (word) {
                    index += word.length + 1;
                }
                continue;
            }

            var newChild = child.splitText(object.index);
            newChild.nodeValue = newChild.nodeValue.substr(object.length);
            child.parentNode.insertBefore(object.element, newChild);
            break;
        } while (1);
    },

    _replaceContent: function(element) {
        var child = element.firstChild;
        while (!YAHOO.lang.isNull(child)) {
            if ((child.tagName == 'A') || (child.tagName == 'IMG')) {
            } else if (child.nodeName == '#text') {
                this._parseText(child);
            } else {
                this._replaceContent(child);
            }

            child = child.nextSibling;
        }
    },

    _setContext: function(type, args) {
        var glossaryTerm = args[0];
        var hintContent = this._glossaryTerms[glossaryTerm.innerHTML.toLowerCase()].hintContent;
        this._tooltip.cfg.setProperty('text', hintContent);
    }
};var glossaryObj = [];glossaryObj[1] = {link: "/glossary/letter1/#word1", hintContent:"Information about account activity and account status of a trading account managed by a broker"};glossaryObj[2] = {link: "/glossary/letter1/#word2", hintContent:"American Stock Exchange"};glossaryObj[3] = {link: "/glossary/letter1/#word3", hintContent:"analysis of FOREX-related market news, forecasts and experts opinions"};glossaryObj[50] = {link: "/glossary/letter1/#word50", hintContent:"the with analysis of bank transakts"};glossaryObj[4] = {link: "/glossary/letter1/#word4", hintContent:"The quoted price at which a customer can buy a currency pair. Also referred to as the &amp;#039;offer,&amp;#039; &amp;#039;ask price,&amp;#039; or &amp;#039;ask rate.&amp;#039;"};glossaryObj[49] = {link: "/glossary/letter1/#word49", hintContent:"AutochartistAutochartist"};glossaryObj[5] = {link: "/glossary/letter2/#word5", hintContent:"The quoted price where a customer can sell a currency pair. Also known as the &amp;#039;bid price&amp;#039; or &amp;#039;bid rate."};glossaryObj[6] = {link: "/glossary/letter2/#word6", hintContent:"A firm in the business of acting as a counterparty to foreign currency transactions."};glossaryObj[7] = {link: "/glossary/letter3/#word7", hintContent:"Classic FOREX CLUB quote plan, as well as a trading terminal (also known as Rumus) working with it."};glossaryObj[9] = {link: "/glossary/letter3/#word9", hintContent:"The two currencies (for example, euro and US dollar) that make up a foreign exchange rate."};glossaryObj[10] = {link: "/glossary/letter4/#word10", hintContent:"The act of buying and selling a stock within a trading session or a single trading day, without carrying open positions over to the following trading day or session."};glossaryObj[11] = {link: "/glossary/letter4/#word11", hintContent:"A dedicated FOREX CLUB staff member managing customers’ transactions."};glossaryObj[12] = {link: "/glossary/letter4/#word12", hintContent:"A practice account that allows you to trade on the FOREX market without risking REAL money. That is it&amp;#039;s only difference from a real trading account."};glossaryObj[13] = {link: "/glossary/letter4/#word13", hintContent:"An index; an average computed from the stock prices of a group of the largest companies in the United States."};glossaryObj[15] = {link: "/glossary/letter5/#word15", hintContent:"Central banking system of the USA"};glossaryObj[16] = {link: "/glossary/letter5/#word16", hintContent:"International currency exchange market that allows making profits by buying and selling currencies. An abbreviation of FOReign EXchange, meaning foreign currency exchange."};glossaryObj[17] = {link: "/glossary/letter5/#word17", hintContent:"Forex Club is your partner on the FOREX market. With us, you will make profits by trading Forex."};glossaryObj[18] = {link: "/glossary/letter5/#word18", hintContent:"Our own Internet TV channel broadcasting latest news and reporting events from the world’s largest stock exchanges"};glossaryObj[19] = {link: "/glossary/letter6/#word19", hintContent:"A break between prices on a chart that usually occurs on weekends when no trading takes place; can be created by important external factors"};glossaryObj[20] = {link: "/glossary/letter6/#word20", hintContent:"Greenwich mean time; time zones compute their local time as an offset from GMT."};glossaryObj[21] = {link: "/glossary/letter7/#word21", hintContent:"FOREX trading via the Internet, from anywhere in the world, without bosses or staff."};glossaryObj[22] = {link: "/glossary/letter7/#word22", hintContent:"Investment is a process of multiplying your capital. Money generates more money."};glossaryObj[46] = {link: "/glossary/letter18/#word46", hintContent:"Commission on Regulation of Relations of Financial Market Participants"};glossaryObj[23] = {link: "/glossary/letter8/#word23", hintContent:"A tool offered my FOREX CLUB that allows you to control large amount of a commodity with a comparatively small amount of capital."};glossaryObj[24] = {link: "/glossary/letter8/#word24", hintContent:"Your personal user name or nickname required to enter a system."};glossaryObj[25] = {link: "/glossary/letter8/#word25", hintContent:"loss from transaction"};glossaryObj[26] = {link: "/glossary/letter8/#word26", hintContent:"the minimum amount of currency bought/sold in a trade"};glossaryObj[27] = {link: "/glossary/letter9/#word27", hintContent:"The amount of money needed to open or maintain a position on the FOREX market."};glossaryObj[28] = {link: "/glossary/letter9/#word28", hintContent:"A progressive FOREX CLUB quote plan, as well as a trading terminal working with it."};glossaryObj[29] = {link: "/glossary/letter10/#word29", hintContent:"The National Association of Securities Dealers Automated Quotations"};glossaryObj[30] = {link: "/glossary/letter10/#word30", hintContent:"New York Mercantile Exchange"};glossaryObj[31] = {link: "/glossary/letter10/#word31", hintContent:"The oldest and largest stock exchange in the USA. Established in 1792. Located in New York on the Wall Street."};glossaryObj[32] = {link: "/glossary/letter11/#word32", hintContent:"The instruction, by a customer to a brokerage, for the purchase or sale of a security with specific conditions."};glossaryObj[33] = {link: "/glossary/letter11/#word33", hintContent:"Open positions that a dealer can carry over into the next dealing day."};glossaryObj[34] = {link: "/glossary/letter12/#word34", hintContent:"The smallest increment of change in a quote (foreign currency price)."};glossaryObj[35] = {link: "/glossary/letter12/#word35", hintContent:"profit from transactions"};glossaryObj[36] = {link: "/glossary/letter13/#word36", hintContent:"A current price of a currency pair at which the currencies can be bought or sold; a simultaneous Bid and Ask in a currency pair."};glossaryObj[52] = {link: "www.ya.ru", hintContent:"1!!!!"};glossaryObj[37] = {link: "/glossary/letter14/#word37", hintContent:"The difference between the ask and bid price of a currency pair."};glossaryObj[38] = {link: "/glossary/letter14/#word38", hintContent:"A command to the dealing desk to close your position when your losses reach a certain level."};glossaryObj[39] = {link: "/glossary/letter14/#word39", hintContent:"Fee charged or paid to a trader for the rollover of a FOREX position due to the difference in currencies interest rates."};glossaryObj[40] = {link: "/glossary/letter15/#word40", hintContent:"A single-time quote sent by the information system, created by movements in the price of a currency."};glossaryObj[41] = {link: "/glossary/letter15/#word41", hintContent:"A FOREXCLUB customer, who trades FOREX with us trading with the purpose of making profit"};glossaryObj[47] = {link: "/glossary/letter15/#word47", hintContent:"MY FXBANK - Trading Account Management System; it is used for operations like account funding, funds withdrawal or login change."};glossaryObj[42] = {link: "/glossary/letter15/#word42", hintContent:"Software installed on customer’s computer required for FOREX trading"};glossaryObj[43] = {link: "/glossary/letter15/#word43", hintContent:"Overall market tendency – positive trend (upward movement) and negative trend (downward movement)."};glossaryObj[44] = {link: "/glossary/letter16/#word44", hintContent:"A macroeconomic indicator that shows the ratio of the total number of unemployed workforce to the total workforce."};glossaryObj[45] = {link: "/glossary/letter17/#word45", hintContent:"A street in New York hosting the largest US stock exchanges, such as  NYSE, NASDAQ, AMEX, NYMEX, and NYBOT."};var glossaryTerms = [];glossaryTerms['account statement'] = glossaryObj[1];glossaryTerms['amex'] = glossaryObj[2];glossaryTerms['analytics'] = glossaryObj[3];glossaryTerms['anti-crisis'] = glossaryObj[50];glossaryTerms['profit'] = glossaryObj[50];glossaryTerms['ask'] = glossaryObj[4];glossaryTerms['autochartist'] = glossaryObj[49];glossaryTerms['bid'] = glossaryObj[5];glossaryTerms['broker'] = glossaryObj[6];glossaryTerms['classicforex'] = glossaryObj[7];glossaryTerms['currency pair'] = glossaryObj[9];glossaryTerms['day trading'] = glossaryObj[10];glossaryTerms['dealer'] = glossaryObj[11];glossaryTerms['demo account'] = glossaryObj[12];glossaryTerms['dow jones averages'] = glossaryObj[13];glossaryTerms['federal reserve system'] = glossaryObj[15];glossaryTerms['forex'] = glossaryObj[16];glossaryTerms['forex club'] = glossaryObj[17];glossaryTerms['forexclub'] = glossaryObj[17];glossaryTerms['forex club tv'] = glossaryObj[18];glossaryTerms['gap'] = glossaryObj[19];glossaryTerms['gmt'] = glossaryObj[20];glossaryTerms['internet trading'] = glossaryObj[21];glossaryTerms['investment'] = glossaryObj[22];glossaryTerms['kroufr'] = glossaryObj[46];glossaryTerms['leverage'] = glossaryObj[23];glossaryTerms['login'] = glossaryObj[24];glossaryTerms['loss'] = glossaryObj[25];glossaryTerms['lot'] = glossaryObj[26];glossaryTerms['margin'] = glossaryObj[27];glossaryTerms['modernforex'] = glossaryObj[28];glossaryTerms['nasdaq'] = glossaryObj[29];glossaryTerms['nymex'] = glossaryObj[30];glossaryTerms['nyse'] = glossaryObj[31];glossaryTerms['order'] = glossaryObj[32];glossaryTerms['overnight'] = glossaryObj[33];glossaryTerms['pips'] = glossaryObj[34];glossaryTerms['profit'] = glossaryObj[35];glossaryTerms['quote'] = glossaryObj[36];glossaryTerms['short'] = glossaryObj[52];glossaryTerms['spread'] = glossaryObj[37];glossaryTerms['stop loss'] = glossaryObj[38];glossaryTerms['swap'] = glossaryObj[39];glossaryTerms['tick'] = glossaryObj[40];glossaryTerms['trader'] = glossaryObj[41];glossaryTerms['trading account management system'] = glossaryObj[47];glossaryTerms['trading terminal'] = glossaryObj[42];glossaryTerms['trend'] = glossaryObj[43];glossaryTerms['unemployment rate'] = glossaryObj[44];glossaryTerms['wall street'] = glossaryObj[45];YAHOO.util.Event.onDOMReady(function () {
    new YAHOO.forex.Hint(
            glossaryTerms,  
            { 
              showCount: 2
            }
    );
});