function bookmark(title, url) {
  try {

    // Gecko or compatible
    if (window.sidebar) {
       window.sidebar.addPanel(title, url, "");
       return;
    }

    // Opera or compatible
    if (window.opera && window.print) {
       var anchor = document.createElement('a');
       anchor.setAttribute('href', url);
       anchor.setAttribute('title', title);
       anchor.setAttribute('rel', 'sidebar');
       anchor.click();
       return;
    }

    // Internet Explorer 4 or compatible
    if (document.all && (parseInt(navigator.appVersion, 10) >= 4)) {
       window.external.AddFavorite(url, title);
       return;
    }

  } catch (e) {
    // fall through
  }

  alert("To bookmark the current page press Ctrl-D" +
      "\n(Internet Explorer, Firefox, Safari and Chrome)" +
      "\nor Ctrl-T (Opera)");
}

function startsWith(source, value) {
    return source.indexOf(value, 0) == 0;
}

function endsWith(source, value) {
    return source.indexOf(value, source.length - value.length) != -1;
}

/**
 * Returns a copy of string without leading and trailing whitespace.
 * Whitespace is defined as {char c | c <= ' '}.
 * @param string The string to trim.
 * @return The trimmed string.
 */
function trim(string) {

    /* We avoid regular expressions in implementation to support older user agents. */

    /* Lookup the LENGTH of string. */
    var LENGTH = string.length;

    /* Find the first character that is not whitespace. */
    var beginIndex = 0;
    while (beginIndex != LENGTH && string.charAt(beginIndex) <= ' ') {
        beginIndex++;
    }

    /* If all characters are whitespace then return the empty string. */
    if (beginIndex == LENGTH) {return "";}

    /* Find the last character that is not whitespace. */
    var endIndex = LENGTH;
    while (endIndex != beginIndex && string.charAt(endIndex - 1) <= ' ') {
        endIndex--;
    }

    /*
     * If no leading or trailing whitespace found then return the string,
     * otherwise return the substring without leading and trailing whitespace.
     */
    return ((beginIndex == 0) && (endIndex == LENGTH)) ?
        string : string.substring(beginIndex, endIndex);
}

var TableUtil = {

    LabeledRow : function (label, row) {
        this.label = label;
        this.row   = row;
    },

    debug : true,

    lastColumn : [],

    lastDirection : [],

    DIRECTION_ASC : 1,

    DIRECTION_DESC : -1,

    getFirstChild : function (element, predicate) {
        var i, n, childNode, childNodes;
        childNodes = element.childNodes;
        for (i = 0, n = childNodes.length; i < n; i++) {
            childNode = childNodes.item(i);
            if (predicate(childNode)) {
                return childNode;
            }
        }
        return null;
    },

    getChildNodes : function (element, predicate) {
        var result, i, n, childNode, childNodes;
        result = [];
        childNodes = element.childNodes;
        for (i = 0, n = childNodes.length; i < n; i++) {
            childNode = childNodes.item(i);
            if (predicate(childNode)) {
                result.push(childNode);
            }
        }
        return result;
    },

    removeChildNodes : function (element) {
        var newElement = element.cloneNode(false);
        while (newElement.hasChildNodes()) {
            newElement.removeChild(newElement.firstChild);
        }
        element.parentNode.replaceChild(newElement, element);
        return newElement;
    },

    findAncestor : function (node, predicate) {
        for (var i = node; i; i = i.parentNode) {
            if (predicate(i)) {
                return i;
            }
        }
        return null;
    },

    findAncestorElement : function (node, nodeName) {
        nodeName = nodeName.toLowerCase();
        return TableUtil.findAncestor(
            node,
            function (i) {
                return i.nodeType == 1 && i.nodeName.toLowerCase() == nodeName;
            }
        );
    },

    findIndex : function (element) {
        var count, childNodes, childNode;
        count = 0;
        childNodes = element.parentNode.childNodes;
        for (var i = 0, n = childNodes.length; i < n; i++) {
            childNode = childNodes.item(i);
            if (childNode.nodeType == 1) {
                if (childNode == element) {
                    return count;
                }
                /* Count child elements */
                count++;
            }
        }
        throw "Node not found among child nodes of parent node.";
    },

    sortBy : function (element, comparator, columnIndex) {
        var table, tbody, rows, row, cells, labeledRows, i, n;
        columnIndex = columnIndex || TableUtil.findIndex(TableUtil.findAncestorElement(element, "th") || TableUtil.findAncestorElement(element, "td"));
        table = TableUtil.findAncestorElement(element, "table");
        if (!table) {
            throw "Table not found";
        }
        tbody = TableUtil.getFirstChild(table, function (node) {
            return node.nodeType == 1 && node.nodeName.toLowerCase() == "tbody";
        });
        if (!tbody) {
            throw "tbody not found";
        }
        comparator = comparator || TableUtil.Comparator.BY_TEXT_CI;
        rows = TableUtil.getChildNodes(tbody, function (node) {
            return node.nodeType == 1 && node.nodeName.toLowerCase() == "tr";
        });
        labeledRows = [];
        for (i = 0, n = rows.length; i < n; i++) {
            row = rows[i];
            cells = TableUtil.getChildNodes(row, function (node) {
                return node.nodeType == 1 && (node.nodeName.toLowerCase() == "td" || node.nodeName.toLowerCase() == "th");
            });
            labeledRows.push(new TableUtil.LabeledRow(comparator.getLabel(TableUtil.getText(cells[columnIndex])), row));
        }
        /*
         * ECMAScript standard warns that Array.sort() is not necessarily stable.
         */
        if (navigator.userAgent.indexOf("MSIE") > -1 || labeledRows.length > 512) {
            /*
             * MSIE uses a stable sort.
             * For long lists (over 512 elements) we'll take whatever the browser implements.
             */
            labeledRows.sort(comparator.compare);
        } else {
            /* For non-MSIE, and with small lists (less than 512 elements) we'll
             * use a merge-sort.
             */
            labeledRows = TableUtil.mergesort(labeledRows, comparator.compare);
        }
        if (table in TableUtil.lastColumn && TableUtil.lastColumn[table] == columnIndex) {
            if (table in TableUtil.lastDirection && TableUtil.lastDirection[table] == TableUtil.DIRECTION_ASC) {
                labeledRows.reverse();
                TableUtil.lastDirection[table] = TableUtil.DIRECTION_DESC;
            } else if (table in TableUtil.lastDirection && TableUtil.lastDirection[table] == TableUtil.DIRECTION_DESC) {
                //labeledRows.reverse();
                TableUtil.lastDirection[table] = TableUtil.DIRECTION_ASC;
            } else {
                TableUtil.lastDirection[table] = TableUtil.DIRECTION_ASC;
            }
        } else {
            TableUtil.lastColumn[table] = columnIndex;
            TableUtil.lastDirection[table] = TableUtil.DIRECTION_ASC;
        }
        tbody = TableUtil.removeChildNodes(tbody);
        for (i = 0, n = labeledRows.length; i < n; i++) {
            tbody.appendChild(labeledRows[i].row);
        }
    },

    getText : function (element) {
        var childNodes, childNode, i, n, result;
        result = "";
        childNodes = element.childNodes;
        for (i = 0, n = childNodes.length; i < n; i++) {
            childNode = childNodes.item(i);
            if (childNode.nodeType == 1 && childNode.nodeName.toLowerCase() != "sup") {
                // noteType == 1 => ELEMENT_NODE
                result += TableUtil.getText(childNode);
            } else if (childNode.nodeType == 3) {
                result += childNode.nodeValue;
            }
        }
        return trim(result);
    },

    Comparator : {

        /* Compare by text, case insensitive. */
        BY_TEXT_CI : {
            compare : function (first, second) {
                var firstText = first.label;
                var secondText = second.label;
                return firstText < secondText ? -1 : firstText == secondText ? 0 : 1;
            },
            getLabel : function (text) {
               return text.toLowerCase();
            }
        },

        /* Compare by text: reverse order of words, case insensitive. */
        BY_TEXT_REVERSE_WORDS_CI : {
            compare : function (first, second) {
                var firstText = first.label;
                var secondText = second.label;
                return firstText < secondText ? -1 : firstText == secondText ? 0 : 1;
            },
            getLabel : function(text) {
                return TableUtil.reverseWords(text.toLowerCase());
            }
        },

        /* Compare by text, case insensitive, ignore leading "The". */
        BY_TEXT_CI_THE : {
            compare : function (first, second) {
                var firstText = first.label;
                var secondText = second.label;
                return firstText < secondText ? -1 : firstText == secondText ? 0 : 1;
            },
            getLabel : function(text) {
                var lower = text.toLowerCase();
                if (lower.substr(0, 4) === "the ") {
                    return lower.substr(4);
                }
                return lower;
            }
        },

        BY_DATE_DDMMYY : {
            compare : function (first, second) {
                var firstTime = first.label;
                var secondTime = second.label;
                if (isNaN(firstTime)) {
                    return isNaN(secondTime) ? 0 : 1;
                }
                return isNaN(secondTime) ? -1 : (firstTime - secondTime);
            },
            getLabel : function(text) {
                return TableUtil.parseDate_DDMMYY(text).getTime();
            }
        },

        /* Compare by text, case insensitive. */
        BY_INTEGER : {
            compare : function (first, second) {
                var firstText = first.label;
                var secondText = second.label;
                return firstText - secondText;
            },
            getLabel : function (text) {
                try {
                    if (text.charAt(0) == "(") {
                        return -1 * parseInt(text.replace(/[,\.\(\)]/g, ""), 10);
                    }
                    return parseInt(text.replace(/,/g, ""), 10);
                } catch (e) {
                    return 0;
                }
            }
        }
    },

    reverseWords : function(string) {
        /* A simple split on the space character. */
        var words = string.split(" ");
        var i, result;
        for (i = words.length - 1; i >= 0; i--) {
            result += words[i];
            if (i != 0) {
                result += " ";
            }
        }
        return result;
    },

    parseDate_DDMMYY : function (value) {
        var components = value.split("/");
        if (components.length < 3) {
            return new Date(NaN);
        }
        return new Date(components[2], components[1] - 1, components[0], 0, 0, 0);
    },

    /* Based on pseudocode: http://en.wikipedia.org/wiki/Merge_sort#Algorithm */
    mergesort : function (array, comparator) {
        if (array.length <= 1) {
            return array;
        }
        /* For small lists (less than 7 items) we'll use an insertion-sort. */
        if (array.length < 7) {
            return TableUtil.insertionsort(array, comparator);
        }
        var middle = Math.floor(array.length / 2);
        var left = TableUtil.mergesort(array.slice(0, middle), comparator);
        var right = TableUtil.mergesort(array.slice(middle), comparator);
        var result = TableUtil.merge(left, right, comparator);
        return result;
    },

    /* Based on pseudocode: http://en.wikipedia.org/wiki/Merge_sort#Algorithm */
    merge : function (left, right, comparator) {
        var result = [];
        while (left.length > 0 && right.length > 0) {
            if (comparator(left[0], right[0]) <= 0) {
                result.push(left[0]);
                left = left.slice(1);
            } else {
                result.push(right[0]);
                right = right.slice(1);
            }
        }
        if (left.length > 0) {
            return result.concat(left);
        }
        if (right.length > 0) {
            return result.concat(right);
        }
        return result;
    },

    insertionsort : function(array, comparator) {

        var length, i, j, value;

        length = array.length;

        for (i = 1; i < length; i++) {
            value = array[i];
            j = i - 1;
            while (j >= 0 && comparator(array[j], value) > 0) {
                array[j + 1] = array[j];
                j = j - 1;
            }
            array[j + 1] = value;
        }

        return array;
    }

};

function sortBy(element, comparator) {
    TableUtil.sortBy(element, comparator);
    if ($(element).hasClass("sort_asc")) {
        $("table.companies th").removeClass("sort_asc sort_desc");
        $(element).addClass("sort_desc");
    } else {
        $("table.companies th").removeClass("sort_asc sort_desc");
        $(element).addClass("sort_asc");
    }
}

$(document).ready(function () {

    $("a[rel='external']").each(function (i) {
        if (!this.target) {
            this.target = "_blank";
        }
        if (!this.title) {
            this.title = "the page will open in a new window";
        }
    });
    $("a[rel='pdf']").each(function (i) {
        if (!this.target) {
            this.target = "_blank";
        }
        if (!this.title) {
            this.title = "the PDF document will open in a new window";
        }
    });
    $("a[rel='chart']").each(function (i) {
        if (!this.target) {
            this.target = "_blank";
        }
        if (!this.title) {
            this.title = "the chart will open in a new window";
        }
    });

    $('table.financial tbody tr').hover(
            function () {
                $(this).find('td').css('background-color','#e8f5f8');
                $(this).find('th').css('background-color','#e8f5f8');
            },
            function () {
                $(this).find('td').css('background-color','');
                $(this).find('th').css('background-color','');
            }
    );

    $('table.companies tbody tr').hover(
            function () {
                $(this).find('td').css('background-color','#fff');
                $(this).find('th').css('background-color','#fff');
            },
            function () {
                $(this).find('td').css('background-color','');
                $(this).find('th').css('background-color','');
            }
    );

    $('input[name=q]').each(function () {

        if (this.value === "") {
            this.value = "Search the site";
        }

        this.onclick = function () {
            if (this.value === 'Search the site') {
                this.value = "";
            }
        };
    });

    $('img[alt="Print"]').parent().hover(
            function () {
                if (startsWith($('img[alt="Print"]').attr('src'), "../")) {
                    $('img[alt="Print"]').attr('src', '../images/icons/icon_print_blue.png');
                } else {
                    $('img[alt="Print"]').attr('src', 'images/icons/icon_print_blue.png');
                }
            },
            function () {
                if (startsWith($('img[alt="Print"]').attr('src'), "../")) {
                    $('img[alt="Print"]').attr('src', '../images/icons/icon_print.png');
                } else {
                    $('img[alt="Print"]').attr('src', 'images/icons/icon_print.png');
                }
            }
    );

    $('img[alt="Add to basket"]').parent()
    .click(
            function () {
                $('img[alt="Add to basket"]').attr('src', '../images/icons/icon_plus_click.png');
                $(this).unbind('mouseenter mouseleave');
                return false;
            }
    )
    .hover(
            function () {
                if (startsWith($('img[alt="Add to basket"]').attr('src'), "../")) {
                    $('img[alt="Add to basket"]').attr('src', '../images/icons/icon_plus_blue.png');
                } else {
                    $('img[alt="Add to basket"]').attr('src', 'images/icons/icon_plus_blue.png');
                }
            },
            function () {
                if (startsWith($('img[alt="Add to basket"]').attr('src'), "../")) {
                    $('img[alt="Add to basket"]').attr('src', '../images/icons/icon_plus.png');
                } else {
                    $('img[alt="Add to basket"]').attr('src', 'images/icons/icon_plus.png');
                }
            }
    );

    $('img[alt="View Basket"]').parent().hover(
            function () {
                var src = $('img[alt="View Basket"]').attr('src');
                if (startsWith(src, "../")) {
                    $('img[alt="View Basket"]').attr('src', '../images/icons/icon_basket_blue.png');
                } else {
                    $('img[alt="View Basket"]').attr('src', 'images/icons/icon_basket_blue.png');
                }
            },
            function () {
                if (startsWith($('img[alt="View Basket"]').attr('src'), "../")) {
                    $('img[alt="View Basket"]').attr('src', '../images/icons/icon_basket.png');
                } else {
                    $('img[alt="View Basket"]').attr('src', 'images/icons/icon_basket.png');
                }
            }
    );

    $('img[alt="Bookmark"]').parent().hover(
            function () {
                if (startsWith($('img[alt="Bookmark"]').attr('src'), "../")) {
                    $('img[alt="Bookmark"]').attr('src', '../images/icons/icon_bookmark_blue.png');
                } else {
                    $('img[alt="Bookmark"]').attr('src', 'images/icons/icon_bookmark_blue.png');
                }
            },
            function () {
                if (startsWith($('img[alt="Bookmark"]').attr('src'), "../")) {
                    $('img[alt="Bookmark"]').attr('src', '../images/icons/icon_bookmark.png');
                } else {
                    $('img[alt="Bookmark"]').attr('src', 'images/icons/icon_bookmark.png');
                }
            }
    );

    $('img[alt="Share page"]').parent().hover(
            function () {
                if (startsWith($('img[alt="Share page"]').attr('src'), "../")) {
                    $('img[alt="Share page"]').attr('src', '../images/icons/icon_share_blue.png');
                } else {
                    $('img[alt="Share page"]').attr('src', 'images/icons/icon_share_blue.png');
                }
            },
            function () {
                if (startsWith($('img[alt="Share page"]').attr('src'), "../")) {
                    $('img[alt="Share page"]').attr('src', '../images/icons/icon_share.png');
                } else {
                    $('img[alt="Share page"]').attr('src', 'images/icons/icon_share.png');
                }
            }
    );

    $('img[alt="Previous"]').parent().hover(
            function () {
                if (startsWith($('img[alt="Previous"]').attr('src'), "../")) {
                    $('img[alt="Previous"]').attr('src', '../images/icons/icon_left_arrow_blue.png');
                } else {
                    $('img[alt="Previous"]').attr('src', 'images/icons/icon_left_arrow_blue.png');
                }
            },
            function () {
                if (startsWith($('img[alt="Previous"]').attr('src'), "../")) {
                    $('img[alt="Previous"]').attr('src', '../images/icons/icon_left_arrow.png');
                } else {
                    $('img[alt="Previous"]').attr('src', 'images/icons/icon_left_arrow.png');
                }
            }
    );

    $('img[alt="Next"]').parent().hover(
            function () {
                if (startsWith($('img[alt="Next"]').attr('src'), "../")) {
                    $('img[alt="Next"]').attr('src', '../images/icons/icon_right_arrow_blue.png');
                } else {
                    $('img[alt="Next"]').attr('src', 'images/icons/icon_right_arrow_blue.png');
                }
            },
            function () {
                if (startsWith($('img[alt="Next"]').attr('src'), "../")) {
                    $('img[alt="Next"]').attr('src', '../images/icons/icon_right_arrow.png');
                } else {
                    $('img[alt="Next"]').attr('src', 'images/icons/icon_right_arrow.png');
                }
            }
    );

    $('#data_back_link').hover(
            function () {
                if (startsWith($('img[alt="Slide left"]').attr('src'), "../")) {
                    $('img[alt="Slide left"]').attr('src', '../images/icons/icon_left_arrow_blue.png');
                } else {
                    $('img[alt="Slide left"]').attr('src', 'images/icons/icon_left_arrow_blue.png');
                }
            },
            function () {
                if (startsWith($('img[alt="Slide left"]').attr('src'), "../")) {
                    $('img[alt="Slide left"]').attr('src', '../images/icons/icon_left_arrow.png');
                } else {
                    $('img[alt="Slide left"]').attr('src', 'images/icons/icon_left_arrow.png');
                }
            }
    );

    $('#data_next_link').hover(
            function () {
                if (startsWith($('img[alt="Slide right"]').attr('src'), "../")) {
                    $('img[alt="Slide right"]').attr('src', '../images/icons/icon_right_arrow_blue.png');
                } else {
                    $('img[alt="Slide right"]').attr('src', 'images/icons/icon_right_arrow_blue.png');
                }
            },
            function () {
                if (startsWith($('img[alt="Slide right"]').attr('src'), "../")) {
                    $('img[alt="Slide right"]').attr('src', '../images/icons/icon_right_arrow.png');
                } else {
                    $('img[alt="Slide right"]').attr('src', 'images/icons/icon_right_arrow.png');
                }
            }
    );

    $('img.left_col_link').hover(
            function () {
                $(this).css('border', '1px solid #006579');
            },
            function () {
                $(this).css('border', '1px solid #fff');
            }
    )

    $('li.current').prev().css('background','none');
    $('div.nav ul li:not(.current)').last().css('background','none');

    /* Slide animation for resource centre downloads page. */
    $('a.panel_link').toggle(
            function () {
                $('div.panel_container').slideDown('500');
                if (startsWith($('img.logo').attr('src'), "../")) {
                    $('a.panel_link').css('background-image','url(../images/icons/icon_download_panel_up.png)')
                } else {
                    $('a.panel_link').css('background-image','url(images/icons/icon_download_panel_up.png)')
                }
            },
            function () {
                $('div.panel_container').slideUp('slow');
                $('a.panel_link').css('background-image','')
            }
    );
    /* Touching Lives panel interaction */
//    $('div#slider2 div.cap').css('height', '24px');

    $('div#slider1 a').toggle(
            function(){
                $(this).removeClass().addClass('minus').html('<span>minus</span>');
                $('div#slider1 div.cap').animate({height:12 + 5*17 + 6});
                $('div#slider1').animate({marginTop:-(5*17 + 6)});
            },
            function(){
                $(this).removeClass().addClass('plus').html('<span>plus</span>');
                $('div#slider1 div.cap').animate({height:12});
                $('div#slider1').animate({marginTop:0});
            }
    );

    $('div#slider2 a').toggle(
            function(){
                $(this).removeClass().addClass('minus').html('<span>minus</span>');
                $('div#slider2 div.cap').animate({height:2*12 + 5*17 + 6});
                $('div#slider2').animate({marginTop:-(5*17 + 6)});
            },
            function(){
                $(this).removeClass().addClass('plus').html('<span>plus</span>');
                $('div#slider2 div.cap').animate({height:2*12});
                $('div#slider2').animate({marginTop:0});
            }
    );

    $('div#slider3 a').toggle(
            function(){
                $(this).removeClass().addClass('minus').html('<span>minus</span>');
                $('div#slider3 div.cap').animate({height:24 + 6*17 + 6});
//                $('div#slider3').animate({marginTop:-(5*17 + 6)});
            },
            function(){
                $(this).removeClass().addClass('plus').html('<span>plus</span>');
                $('div#slider3 div.cap').animate({height:24});
                $('div#slider3').animate({marginTop:0});
            }
    );

    $('div#slider4 a').toggle(
            function(){
                $(this).removeClass().addClass('minus').html('<span>minus</span>');
                $('div#slider4 div.cap').animate({height:16 + 5*17 + 6});
//                $('div#slider4').animate({marginTop:-(4*17 + 6)});
            },
            function(){
                $(this).removeClass().addClass('plus').html('<span>plus</span>');
                $('div#slider4 div.cap').animate({height:16});
                $('div#slider4').animate({marginTop:0});
            }
    );

    $('div#slider5 a').toggle(
            function(){
                $(this).removeClass().addClass('minus').html('<span>minus</span>');
                $('div#slider5 div.cap').animate({height:36 + 5*17 + 6});
//                $('div#slider5').animate({marginTop:-(5*17 + 6)});
            },
            function(){
                $(this).removeClass().addClass('plus').html('<span>plus</span>');
                $('div#slider5 div.cap').animate({height:36});
                $('div#slider5').animate({marginTop:0});
            }
    );


    $('div#asia_slider1 a').toggle(
        function(){
            $(this).removeClass().addClass('minus').html('<span>minus</span>');
            $('div#asia_slider1 div.cap').animate({height:40 + 6*17 + 6});
//            $('div#asia_slider1').animate({marginTop:-(6*17 + 6)});
        },
        function(){
            $(this).removeClass().addClass('plus').html('<span>plus</span>');
            $('div#asia_slider1 div.cap').animate({height:40});
//            $('div#asia_slider1').animate({marginTop:0});
        }
    );

    $('div#asia_slider2 a').toggle(
        function(){
            $(this).removeClass().addClass('minus').html('<span>minus</span>');
            $('div#asia_slider2 div.cap').animate({height:46 + 6*17 + 6});
//            $('div#asia_slider2').animate({marginTop:-(4*17 + 6)});
        },
        function(){
            $(this).removeClass().addClass('plus').html('<span>plus</span>');
            $('div#asia_slider2 div.cap').animate({height:46});
//            $('div#asia_slider2').animate({marginTop:0});
        }
    );

    $('div#asia_slider3 a').toggle(
        function(){
            $(this).removeClass().addClass('minus').html('<span>minus</span>');
            $('div#asia_slider3 div.cap').animate({height:46 + 7*17 + 6});
            $('div#asia_slider3').animate({marginTop:-(7*17 + 6)});
        },
        function(){
            $(this).removeClass().addClass('plus').html('<span>plus</span>');
            $('div#asia_slider3 div.cap').animate({height:46});
            $('div#asia_slider3').animate({marginTop:0});
        }
    );

    $('div#asia_slider4 a').toggle(
        function(){
            $(this).removeClass().addClass('minus').html('<span>minus</span>');
            $('div#asia_slider4 div.cap').animate({height:40 + 8*17 + 6});
            $('div#asia_slider4').animate({marginTop:-(8*17 + 6)});
        },
        function(){
            $(this).removeClass().addClass('plus').html('<span>plus</span>');
            $('div#asia_slider4 div.cap').animate({height:40});
            $('div#asia_slider4').animate({marginTop:0});
        }
    );

    $('div#asia_slider5 a').toggle(
        function(){
            $(this).removeClass().addClass('minus').html('<span>minus</span>');
            $('div#asia_slider5 div.cap').animate({height:28 + 4*17 + 6});
            //$('div#asia_slider5').animate({marginTop:-(8*17 + 6)});
        },
        function(){
            $(this).removeClass().addClass('plus').html('<span>plus</span>');
            $('div#asia_slider5 div.cap').animate({height:28});
            $('div#asia_slider5').animate({marginTop:0});
        }
    );

    $('div#asia_slider6 a').toggle(
        function(){
            $(this).removeClass().addClass('minus').html('<span>minus</span>');
            $('div#asia_slider6 div.cap').animate({height:40 + 7*17 + 6});
            $('div#asia_slider6').animate({marginTop:-(7*17 + 6)});
        },
        function(){
            $(this).removeClass().addClass('plus').html('<span>plus</span>');
            $('div#asia_slider6 div.cap').animate({height:40});
            $('div#asia_slider6').animate({marginTop:0});
        }
    );

    $('div#asia_slider7 a').toggle(
        function(){
            $(this).removeClass().addClass('minus').html('<span>minus</span>');
            $('div#asia_slider7 div.cap').animate({height:40 + 10*17 + 6});
            $('div#asia_slider7').animate({marginTop:-(10*17 + 6)});
        },
        function(){
            $(this).removeClass().addClass('plus').html('<span>plus</span>');
            $('div#asia_slider7 div.cap').animate({height:40});
            $('div#asia_slider7').animate({marginTop:0});
        }
    );

    $("#table_series_part2").css("display", "none");
    $("#table_switcher #data_back_link").click(function () {
        $("#table_series_part2").css("display", "none");
        $("#table_series_part1").css("display", "block");
        $("#data_next_link").css("display", "inline");
        $("#data_back_link").css("display", "none");
    });
    $("#table_switcher #data_next_link").click(function () {
        $("#table_series_part1").css("display", "none");
        $("#table_series_part2").css("display", "block");
        $("#data_next_link").css("display", "none");
        $("#data_back_link").css("display", "inline");
    });

    if (document.getElementById("share_page")) {
        document.getElementById("share_page").href += document.title + '%0D%0A' + document.URL;
    }

});

