jQuery(document).ready(function() {
    $("#leftNav").accordion({
        initShow: "ul.current",
        collapsible: true
    });
    $("#leftNav").addClass("loaded");

    if ($("form").length > 0) {
        $('form').each(function(index) {
            $(this).attr('autocomplete', 'off');
        });
    }

    if ($('.popup').length > 0) {
        $('.popup').popupWindow();
    }

    if ($("#tweets").length > 0) {
        //$(".tweet_list").html("");
        var tweetlist = "";
        $.jTwitter('sportsspreadIRE', 3, function(data) {
            $.each(data, function(i, post) {
                //var tweetDate = post.created_at.split(" ")
                tweetlist += "<li>" + post.text + "</li>";
                //$(".tweet_list").append("<li>" + post.text + "</li>");
            });
            $(".tweet_list").html(tweetlist);
            $("#latestNews li:odd").addClass("alt");
        });
    }

    if ($("#centerMainContentPromotion").length > 0) {
        $("#centreTopButtons").html("");
        $("#centerMainContentPromotion").easySlider({
            auto: true,
            continuous: true, /*,
	    hoverPause: true*/
            pause: 8000,
            speed: 2000,
            numericId: 'centreTopButtons'
        });
    }

    try {
        var $a = $('#leftNav h3');
        $a.click(function() {
            $a.removeClass('on');
            $(this).addClass('on');
        });
    } catch (err) { alert(err); return false; }

    try {
        $.jGFeed('http://blog.sportsspread.com/feed/',
        function(feeds) {
            // Check for errors
            if (!feeds) {
                // there was an error
                return false;
            }
            // do whatever you want with feeds here
            $('#injectrssfeed').html('');
            for (var i = 0; i < feeds.entries.length; i++) {
                var entry = feeds.entries[i];
                // Entry title
                //entry.title;

                $('#injectrssfeed').append('<li><a href=\'' + entry.link + '\' target=\'_blank\' title=\'View this blog post\'><!--' + entry.publishedDate + '<br />--><strong>' + entry.title + '</strong><br />' + entry.contentSnippet + '</a></li>');
            }
        }, 3);
    } catch (err) { alert(err); return false; }
});                            // end document ready

// Put together the Social Networking links - TODO: add URLEncode
function getSocialNetworkingLink(networkName) {

    var currentPageTitle = getCurrentPageTitle();
    var currentPageURL = getCurrentPageURL();
    var socialNetworkingLink = "";
    var maxLength = 140;
    var twitterLink = "";
    
switch (networkName) {
    case 'twitter':
        twitterLink = window.location + " - " + document.title;
        if (twitterLink.length > maxLength) {
            twitterLink = twitterLink.substr(0, (maxLength - 3)) + '...';
        }
        twitterLink = encodeURIComponent(twitterLink);
        socialNetworkingLink = "<a href=\"http://twitter.com/home?status=" + twitterLink + "\" target=\"_blank\" />Twitter<\/a>";
        break;
    case 'digg':
        socialNetworkingLink = "<a href=\"http://digg.com/submit?url=" + currentPageURL + "&amp;title=" + currentPageTitle + "\" target=\"_blank\" />Digg<\/a>";
        break;
    case 'delicious':
        socialNetworkingLink = "<a href=\"http://del.icio.us/post?url=" + currentPageURL + "&amp;title=" + currentPageTitle + "\" target=\"_blank\" />Delicious<\/a>";
        break;
    case 'reddit':
        socialNetworkingLink = "<a href=\"http://reddit.com/submit?url=" + currentPageURL + "&amp;title=" + currentPageTitle + "\" target=\"_blank\" />Reddit<\/a>";
        break;
    case 'stumbleupon':
        socialNetworkingLink = "<a href=\"http://www.stumbleupon.com/submit?url=" + currentPageURL + "title=" + currentPageTitle + "\" target=\"_blank\" />StumbleUpon<\/a>";
        break;
    default:
        socialNetworkingLink = "<a href=\"#\"><!--error--></a>";
}
    return socialNetworkingLink;
};

// Get the current page title
function getCurrentPageTitle() {
    var pageTitle;
    if (document.title) {
        pageTitle = encodeURIComponent(document.title);
        if (pageTitle) {
            return pageTitle;
        }
    } else {
    pageTitle = escape("Sports Spread - Ireland's Sports Spread Betting Specialists");
        return pageTitle;
    }
}

// Get the current page title
function getCurrentPageURL() {
    var pageAddress;
    pageAddress = encodeURIComponent(window.location);
    return pageAddress;
}




