$(document).ready(function() {

    var social = $('#socialBookmarks'),
			button = social.find('.button'),
			bubble = social.find('.bubble'),
			icons = bubble.find('a'),
			caption = bubble.find('.caption'),
			tip = bubble.find('.tip'),
			title = 'test';


    if (icons.size() % 2) {

        icons.last().remove();

        icons = bubble.find('a');

    };

    bubble.css('width', ((icons.size() / 2) * 28) + 5);
    caption.css('left', ((caption.width() / 2) * -1) + bubble.width() / 2).hide();
    bubble.css('marginLeft', ((bubble.width() / 2) * -1)).hide();


    if ($.browser.version == '6.0') {

        tip.css('bottom', -7);

    };

    social.removeClass('noJS').css('overflow', 'visible').unbind().bind('mouseenter', function() {

        bubble.fadeIn(300);

    }).bind('mouseleave', function() {
        ShareThis_hidediv('ShareThis_GP1');
        ShareThis_showdiv('ShareThis_Icons');
        bubble.fadeOut(600);
        caption.fadeOut(100);

    });


    icons.unbind().bind('mouseenter', function() {

        if (caption.css('display') == 'none') {
            caption.fadeIn(200);
        };

        $(this).find('img').stop().animate({ 'width': 32, 'height': 32, 'marginTop': 0, 'marginLeft': 0 }, 150);

        caption.html($(this).attr('caption'));

    }).bind('mouseleave', function() {

        $(this).find('img').stop().animate({ 'width': 16, 'height': 16, 'marginTop': 8, 'marginLeft': 8 }, 100);

    }).bind('click', function() {

        if ($(this).attr('id') == 'GP1') {
            gp1iframe = $('#socialBookmarks').find('iframe')
            gp1iframe.css('border', 'none');
            gp1iframe.css('margin', '0 0 0 0');
            gp1iframe.css('padding', '0');
            gp1iframe.css('width', '38');
            gp1iframe.css('height', '24');

            ShareThis_showdiv('ShareThis_GP1');
            ShareThis_hidediv('ShareThis_Icons');

        }
        else {
            window.open($(this).attr('href'));
        }
        return false;

    }).each(function() {

        var thisIcon = $(this);

        thisIcon.attr('caption', thisIcon.attr('title')).removeAttr('title');

    }).find('img').removeAttr('title');

});

function ShareThis_hidediv(ID) {
    var ele = document.getElementById(ID);
    ele.style.display = "none";
}

function ShareThis_showdiv(ID) {
    var ele = document.getElementById(ID);
    ele.style.display = "block";
}
    
