$(document).ready(function() {

$(".social-links img").hover(
    function(){
        if($(this).attr("src").indexOf("_color") == -1) {
            ext = getImgExtension($(this).attr('src'));
            var newSrc = $(this).attr("src").replace(ext,"_color"+ext+"#hover");
            $(this).attr("src",newSrc);
        }
    },
    function(){
        if($(this).attr("src").indexOf("_color"+ext+"#hover") != -1) {
            var oldSrc = $(this).attr("src").replace("_color"+ext+"#hover",ext);
            $(this).attr("src",oldSrc);
        }
    }
);

});

function getImgExtension(imgSrc) {
  return imgSrc.substr(imgSrc.lastIndexOf('.'), 4);
}
