jQuery(document).ready(function() {
    var socObj = jQuery('#social');
    connectPosition(socObj);
    connectScroll(socObj);
    connectSocial(socObj);    
});    

function connectPosition(socObj) {

    /*var socialHeight = jQuery('#social').height();
    var viewHeight = jQuery(window).height();
    
    if(viewHeight >= socialHeight) {
        jQuery('#social').css('top', (viewHeight/2)-(socialHeight/2));
    } else {
        jQuery('#social').css('top', 10);
    }*/
    
    var socialWidth = jQuery('#social').width();
    var viewWidth = jQuery(window).width();
    var contentWidth = jQuery('.center').width();
    
    
    socObj.unbind();
    
    if(((viewWidth - contentWidth) / 3) - socialWidth > - 15) {
        socObj.css('right', ((viewWidth - contentWidth) / 2) - socialWidth - 15);        
    } else {
        var right = 
            (((viewWidth - contentWidth) / 2) - socialWidth - 10 > - socialWidth + 5) ? 
            ((viewWidth - contentWidth) / 2) - socialWidth - 10 : - socialWidth + 5;
        socObj.css('right', right);

        socObj.hover(function() {
            if(socObj.is(':animated')) return false;
            socObj.animate({right: -1}, - right * 3);
        },
        function() {
            if(socObj.is(':animated')) return false;
            socObj.animate({right: right}, - right * 3);
        });
    }
    
    if(!socObj.data('resize')) {
        socObj.data('resize', true);
        jQuery(window).resize(function() {
            connectPosition(socObj);
        });
    }
}    

function connectScroll(socObj) {
    var defaultTop = socObj.data('defaultTop') ? socObj.data('defaultTop') : socObj.css('top').replace('px', '');
    socObj.data('defaultTop', defaultTop);
   
    if(jQuery(this).scrollTop() >= defaultTop - 10) {
        socObj.css('top', 10);
    } else {
        socObj.css('top', defaultTop - jQuery(this).scrollTop());
    }
 
   
    if(!socObj.data('scroll')) {
        socObj.data('scroll', true);
        jQuery(window).scroll(function() {
            connectScroll(socObj);
        });
    }
}

function connectSocial(socObj) {
    jQuery('.linkarena .stLarge', socObj).click(function() {
        window.open('http://linkarena.com/bookmarks/addlink/?url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title)+'&desc=&tags=');
        return false;
    });
    
    jQuery('.yigg .stLarge', socObj).click(function() {
        window.open('http://yigg.de/neu?exturl='+encodeURIComponent(location));
        return false;
    });
    
    jQuery('.wikio .stLarge', socObj).click(function() {
        window.open('http://www.wikio.com/sharethis?url='+encodeURIComponent(location)+'&title='+encodeURIComponent(document.title));
        return false;
    });
    
    jQuery('.readster .stLarge', socObj).click(function() {
        window.open('http://www.readster.de/submit/?url='+encodeURIComponent(document.location)+'&title='+encodeURIComponent(document.title));
        return false;
    });
    
    jQuery('.infopirat .stLarge', socObj).click(function() {
        window.open('http://infopirat.com/node/add/userlink?edit[url]='+encodeURIComponent(document.location)+'&edit[title]='+encodeURIComponent(document.title));
        return false;
    });
    
    jQuery('.gamebuzz .stLarge', socObj).click(function() {
        window.open('http://gamebuzz.de/node/add/buzz?url='+encodeURIComponent(document.location));
        return false;
    });
    
    jQuery('.colivia .stLarge', socObj).click(function() {
        window.open('http://www.colivia.de/submit2.php?url='+encodeURIComponent(document.location));
        return false;
    });
}



          

