var x = 0;
var y = 0;
var title = '';
var url = '';

$(function() {
             
    $('#share').hide();           

    title = $('title').html();
    url = window.location.href;

    title = title.replace("&", "%26");
    title = title.replace("?", "%3F");
    title = title.replace("#", "%23");

    url = url.toLowerCase();
    url = url.replace("http://", "")
    url = url.replace("https://", "")                

    setEmail(title, url);
    setFacebook(title, url);
    setMySpace(title, url);
    setLive(title, url);
    setDelicious(title, url);
    setPreferiti(title, url);
    setTwitter(title, url);
    setLinkedIn(title, url);
    setGoogle(title, url);
    setSegnalo(title, url);
    
    $('#lnkShare').attr('href', 'javascript:void(0);');    
    $('#mainShare').css('width', $('#imgShare').width());
    $('#mainShare').css('height', $('#imgShare').height());
    
//    $('#lnkShare').click(function() 
//    {                
//        /*
//        if($('#share').is(':visible'))
//        {
//            $('#share').hide();
//        }
//        else
//        {
//            $('#share').show();
//        }
//        */
//                                                                                                                                               
//        if ($('#share').css('opacity') > 0) 
//        {                          
//            $('#share').fadeTo(700, 0.0);     
//        } 
//        else
//        {                
//            $('#share').show();                
//            $('#share').fadeTo(700, 1.0);
//        }
//    });
    
    /*   
    $('#mainShare').hover(function() {
        // on hovering over, find the element we want to fade *up*
        var fade = $('#share', this);
    
        // if the element is currently being animated (to a fadeOut)...
        if (fade.is(':animated'))
        {
            // ...take it's current opacity back up to 1
            fade.stop().fadeTo(250, 1);
        } 
        else 
        {
            // fade in quickly
            fade.fadeIn(250);
        }
    }, function () {
        // on hovering out, fade the element out
        var fade = $('#share', this);
        if (fade.is(':animated')) 
        {
            fade.stop().fadeTo(250, 0);
        }
        else 
        {
            // fade away slowly
            fade.fadeOut(250);
        }
    });
    */
    
    $('#mainShare').hover(function() {
        $('#share').show();
    }, function () {
        $('#share').hide();
    });                                                                                     
});

function setEmail(title, url)        
{
    url = 'sendEmail.asp?u='+url+'&t='+title
    $('#lnkEmail01').attr('href', url);
    $('#lnkEmail02').attr('href', url);
}

function setFacebook(title, url)        
{   
    url = 'http://www.facebook.com/sharer.php?u='+url+'&t='+title
    $('#lnkFacebook01').attr('href', url);
    $('#lnkFacebook02').attr('href', url);
}

function setMySpace(title, url)
{   
    url = 'http://www.myspace.com/Modules/PostTo/Pages/?t='+title+'&u='+url
    $('#lnkMySpace01').attr('href', url);
    $('#lnkMySpace02').attr('href', url);
}

function setLive(title, url)
{   
    url = 'https://skydrive.live.com/sharefavorite.aspx/.SharedFavorites?url='+url+'&title='+title
    $('#lnkLive01').attr('href', url);
    $('#lnkLive02').attr('href', url);
}

function setDelicious(title, url)
{   
    url = 'https://secure.delicious.com/login?v=5&partner=addthis&jump=http%3A%2F%2Fdelicious.com%2Fsave%3Furl%3D'+url+'%26title%3D'+title+'%26notes%3D%26tags%3D%26noui%3Dno%26share%3Dyes%26jump%3Dyes%26time%3D1246954038%26partner%3Da'
    $('#lnkDelicious01').attr('href', url);
    $('#lnkDelicious02').attr('href', url);
}
    
function setPreferiti(title, url)
{        
    $("#lnkPreferiti01").attr("href", "javascript:AddToFavorites('"+title+"', '"+url+"');");
    $("#lnkPreferiti02").attr("href", "javascript:AddToFavorites('"+title+"', '"+url+"');");
}
    
function AddToFavorites() 
{
    if (window.sidebar) { // Mozilla Firefox Bookmark
            window.sidebar.addPanel(document.title,location.href,'');                
    } 
    else if( window.external ) { // IE Favorite                
            window.external.AddFavorite(location.href,document.title);
    }
    else if(window.opera && window.print) { // Opera Hotlist                
            window.alert( 'Premi Ctrl+D per aggiungerlo al segnalibro' );
    }
}

function setTwitter(title, url)
{   
    url = 'http://twitter.com/home?status='+url
    $('#lnkTwitter01').attr('href', url);
    $('#lnkTwitter02').attr('href', url);
}

function setLinkedIn(title, url)
{   
    url = 'http://www.linkedin.com/shareArticle?mini=true&url='+url+'&title='+title
    $('#lnkLinkedIn01').attr('href', url);
    $('#lnkLinkedIn02').attr('href', url);
}

function setLinkedIn(title, url)
{   
    url = 'http://www.linkedin.com/shareArticle?mini=true&url='+url+'&title='+title
    $('#lnkLinkedIn01').attr('href', url);
    $('#lnkLinkedIn02').attr('href', url);
}

function setGoogle(title, url)
{   
    url = 'http://www.google.com/bookmarks/mark?op=add&bkmk='+url+'&title='+title
    $('#lnkGoogle01').attr('href', url);
    $('#lnkGoogle02').attr('href', url);
}

function setSegnalo(title, url)
{   
    url = 'http://segnalo.virgilio.it/login.html.php?uri=%2Fpost.html.php%3Furl%3D'+url+'%26title%3D'+title+'%26descr%3D'
    $('#lnkSegnalo01').attr('href', url);
    $('#lnkSegnalo02').attr('href', url);
}