﻿$(document).ready(
    function() 
    {        
        $("div#tw_logo, div#tw_block").hover(
            function() 
            {
                StopInvite();
                $("div#tw_block").animate({ width: "650px" }, { queue: false, duration: 600 });
            },
            function() 
            {
                $("div#tw_block").animate({ width: "1px" }, { queue: false, duration: 600 });                
                StartInvite();
            });

        $("div#tw_container").tweet(
        {
            username: "BrainSys",
            join_text: "auto",
            count: 1,
            auto_join_text_default: "",
            auto_join_text_ed: "",
            auto_join_text_ing: "",
            auto_join_text_reply: "",
            auto_join_text_url: "",
            loading_text: "caricamento in corso"
        });

        StartInvite();
    });


var interval = 30;
var duration = 1000;
var shake = 5;
var vibrateIndex = 0;
var selector = $('#tw_bar');

function startVibration() 
{
    vibrateIndex = setInterval(vibrate, interval);
    setTimeout(stopVibration, duration);
}

function vibrate() 
{
    $(selector).stop(true, false).css({ left: (Math.round(Math.random() * shake) - ((shake + 1) / 2)) - 50 + 'px'
                                          , top: Math.round(Math.random() * shake) - ((shake + 1) / 2) + 'px'
    });
}

function stopVibration() 
{
    clearInterval(vibrateIndex);
    $(selector).stop(true, false).css({ left: '-50px', top: '0px' });
    Invite();
};

var inviteId = null;
var inviteIsActive = false;

function StartInvite() 
{
    inviteIsActive = true;
    Invite();
}

function Invite() 
{
    if (inviteIsActive)
    {
        var ms = Math.ceil(Math.random() * 18000);
        inviteId = setTimeout("startVibration()", ms);
    }
}

function StopInvite() 
{
    if (inviteId != null) 
    {
        clearTimeout(inviteId);
        inviteId = null;
    }

    inviteIsActive = false;
}