/**
 * Layout:       tabs-widget.js
 * Project:      WTG
 * Version:      1.0
 * Last change:  12/01/10
 * Assigned to:  Diego Lago (dl)
 * Primary use:  Website
 *
 *
 * Note: Rest of js from contractors
 */

// perform JavaScript after the document is scriptable.
$(document).ready(function() {

    $('.current').removeClass('current');

    // setup ul.tabs to work as tabs for each div directly under div.panes
    $('ul.tabs').tabs('div.panes > div.pane', {
        /* tabs configuration goes here */
        effect: 'fade'
    });

    $('div.panes .ext, #twitter #twitter_update_list a').live('click', function(){
        window.open(this.href);
        return false;
    });

    /**
    * Twitter widget
    */
    $('#tweets').getTwitter({
        userName: 'WTG_ltd',
        numTweets: 2,
        loaderText: 'Loading tweets...',
        slideIn: true,
        slideDuration: 750,
        showHeading: false,
        headingText: '',
        showProfileLink: false,
        showTimestamp: true
    });
	
    $.jGFeed('http://www.wtg.co.uk/blog/feed/rss/',
function(feeds) {
    // Check for errors
    if (!feeds) {
        return false;
    }
    // do whatever you want with feeds here
    for (var i = 0; i < feeds.entries.length; i++) {
        var entry = feeds.entries[i],
            teaser,
            html = '<div class="entry">';
            
        html += '<p class="entry-content news-link blog"><a href="' + entry.link + '" class="entry-title ext">' + entry.title + '</a></p>';

        // trim number of words to print
        var j = 0,
            maxWords = 14,
            entryPre = entry.contentSnippet.split(' '),
            entryPost = '';

        while (j < maxWords) {
            entryPost = entryPost + ' ' + entryPre[j];
            j++;
        }

        html += '<p class="teaser">' + entryPost + ' ...';
        html += '</p></div>';
        $('#blog .blog-entries').append($(html));
    }
}, 2);

});
