

$(window).load(function () {
    $("body").delegate(".icoShare", "click", function () {
        var socialRel = $(this).attr("idShare")
        var UrlToShare = window.location.href;
        share(socialRel, UrlToShare)
    })
    /* SOCIAL SHARE */
    $(".ico_share").click(function () {
        $(".boxShare").fadeIn()
    })
})


// SHARE
function share(social, UrlToShare) {
    
    encodedURL = encodeURIComponent(UrlToShare);

    switch (social) {
        case 'facebook':
            window.open('http://www.facebook.com/sharer.php?u=' + encodedURL + '&r='+getRandomInt(9000, 9999)+'', '', 'width=600, height=550');
            break;

        case 'twitter':
            window.open('http://twitter.com/home?status=Sta leggendo ' + UrlToShare, '', 'width=600, height=550');   // TWITTER ACCETTA (SOLO?) URL NON CODIFICATI
            break;

        case 'digg':
            window.open('http://digg.com/submit?url=' + encodedURL, '', 'width=600, height=550');
            break;

        case 'delicious':
            window.open('http://www.delicious.com/save?v=5&noui&jump=close&url=' + encodedURL + '&title=' + jQuery(document).attr('title'));
            break;

        case 'gplus':
            window.open('https://plus.google.com/share?url=' + encodedURL + '&title=' + jQuery(document).attr('title'), '', 'width=600, height=550');
            break;

        case 'google':
            window.open('https://www.google.com/bookmarks/mark?op=add&bkmk=' + encodedURL + '&title=' + jQuery(document).attr('title'), '', 'width=600, height=550');
            break;

        case 'pinterest':
            sharePinterest()
    };

}




function sharePinterest() {
    if (($.cookie('civicAllowCookies') == "yes") || ($.cookie('civicAllowCookies') == null)) {
        var e = document.createElement('script');
        e.setAttribute('type', 'text/javascript');
        e.setAttribute('charset', 'UTF-8');
        e.setAttribute('src', 'http://assets.pinterest.com/js/pinmarklet.js?r=' + Math.random() * 99999999);
        document.body.appendChild(e);
    } else {
        cookieAlert();
    }
}

//---------------------------------- COOKIE ALERT
function cookieAlert() {

}