$(document).ready(function() {

    /**** Make the skip nav links transparent in IE 8 ****/
    if (/MSIE (8)/.test(navigator.userAgent)) {
        var placeHolder = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
        $('div.navaid a:eq(1)').each(function() {
            var n1 = jQuery(this).text();
            jQuery(this).html('<span class="navaid">' + n1 + '</span>' + placeHolder);
            jQuery(this).css('text-decoration', 'none');
            jQuery(this).focus(function() {
                jQuery(this).html(n1);
            });
            jQuery(this).mouseover(function() {
                jQuery(this).html(n1);
            });
            jQuery(this).blur(function() {
                jQuery(this).html('<span class="navaid">' + n1 + '</span>' + placeHolder);
            });
            jQuery(this).mouseout(function() {
                jQuery(this).html('<span class="navaid">' + n1 + '</span>' + placeHolder);
            });
        });
        $('div.navaid a:eq(2)').each(function() {
            var n2 = jQuery(this).text();
            jQuery(this).html('<span class="navaid">' + n2 + '</span>' + placeHolder);
            jQuery(this).css('text-decoration', 'none');
            jQuery(this).focus(function() {
                jQuery(this).html(n2);
            });
            jQuery(this).mouseover(function() {
                jQuery(this).html(n2);
            });
            jQuery(this).blur(function() {
                jQuery(this).html('<span class="navaid">' + n2 + '</span>' + placeHolder);
            });
            jQuery(this).mouseout(function() {
                jQuery(this).html('<span class="navaid">' + n2 + '</span>' + placeHolder);
            });
        });
    }

    /**** Add 'Share this page' feature ****/
    if ($('div.bookmarkContainer').length > 0) {
        // English version
        if ($('html').attr('lang') == "en") {
            // Add container for top widget

            // ITSD; 12-Apr-2010
            // Removed top Share this Page as requested by PCO Comms.
            //$('div.center h1:first-child').before('<div class="bookmarkContainer bookmarkTop"><div class="bookmarkTitle">Share this page</div></div>');

            // Configure options
            $('div.bookmark').bookmark({
                favoriteText: 'Favourites',
                hint: 'Send to {s} (opens in a new window)',  // Popup hint for links, {s} is replaced by display name
                emailSubject: 'An interesting page on Canada\'s Economic Action Plan Web site',  // The subject for the e-mail 
                emailBody: 'I thought you might find this page interesting:\n{t} ({u})',
                sites: ['delicious', 'digg', 'facebook', 'friendfeed'],
                iconSize: 16, addEmail: true, addFavorite: false, compact: true, popup: false, icons: '/images/bookmarks.png'
            });

            // Add Twitter option
            $('div.bookmark ul').append($('div.bookmark li:eq(1)').clone());
            $('div.bookmark li:last-child span').each(function() {
                jQuery(this).parent().attr('href', 'http://twitter.com/home?status=' + jQuery("title").html() + ' - ' + window.location.href);
                jQuery(this).attr('title', 'Send to Twitter (opens in a new window)');
                jQuery(this).css('background', 'transparent url(/images/twitter16x16.gif) no-repeat');
            });
        }

        // French version
        else {
            // Add container for top widget

            // ITSD; 12-Apr-2010
            // Removed top Share this Page as requested by PCO Comms.
            //$('div.center h1:first-child').before('<div class="bookmarkContainer bookmarkTop"><div class="bookmarkTitle">Partagez cette page</div></div>');

            // Configure options
            $('div.bookmark').bookmark({
                favoriteText: 'Favoris',
                hint: 'Envoyer à : {s} (ouvre dans une nouvelle fenêtre)',  // Popup hint for links, {s} is replaced by display name
                emailSubject: 'Une page intéressante du site Web du Plan d\'action économique du Canada.',  // The subject for the e-mail 
                emailBody: 'J\'ai pensé que cette page vous intéresserait :\n{t} ({u})',
                sites: ['delicious', 'facebook', 'friendfeed', 'twithis'],
                iconSize: 16, addEmail: true, addFavorite: false, compact: true, popup: false, icons: '/images/bookmarks.png'
            });

            // Add Twitter option
            $('div.bookmark ul').append($('div.bookmark li:eq(1)').clone());
            $('div.bookmark li:last-child span').each(function() {
                jQuery(this).parent().attr('href', 'http://twitter.com/home?status=' + jQuery("title").html() + ' - ' + window.location.href);
                jQuery(this).attr('title', 'Envoyer à : Twitter (ouvre dans une nouvelle fenêtre)');
                jQuery(this).css('background', 'transparent url(/images/twitter16x16.gif) no-repeat');
            });
        }

        // ITSD; 12-Apr-2010
        // Removed top Share this Page as requested by PCO Comms.
        // Create duplicate at the top of the page
        //$('div.bookmarkTop').append($('div.bookmark').clone());

        // Enable keyboard focus tooltips for each option
        $('div.bookmark a').each(function() {
            jQuery(this).attr('title', jQuery(this).children('span').attr('title'));
        });
        if ((!/MSIE (8)/.test(navigator.userAgent) || !/Windows NT 5.1/.test(navigator.userAgent)) && typeof (Tltps) != "undefined" && typeof ($.readyOrDone) != "undefined")
            $.readyOrDone(Tltps.execute);

        // Make the share widget visible
        $('div.bookmarkContainer').css('display', 'block');
    }
});
