$(document).ready(function() {
    
    // Preload all rollovers
    $(".navigation a").each(function() {
        // Set the original src
        rollsrc = $(this).children("img").attr("src");
        rollON = rollsrc.replace(/.png$/ig,"-dark.png");
        $("<img>").attr("src", rollON);
        
        // Disable texts
        if ($(this).attr("href") == currentLocation) {
            $(this).children("img").attr("src", rollON);
        }
        $(this).children("p").css("display", "none");
    });
    
    
    // Navigation rollovers
    $(".navigation a").mouseover(function(){
        imgsrc = $(this).children("img").attr("src");
        matches = imgsrc.match(/-dark/);
        
        // Don't do the rollover if state is already ON
        if (!matches) {
          imgsrcON = imgsrc.replace(/.png$/ig,"-dark.png"); // strip off extension
          $(this).children("img").attr("src", imgsrcON);
        }
        $(this).children("p").css("display", "block");
        
    });
    $(".navigation a").mouseout(function(){
        $(this).children("img").attr("src", imgsrc);
        $(this).children("p").css("display", "none");
        
    });
    
});

function swapLanguage() {

  var url = document.location.toString();

  if  (/\/es\//.test(url)) {
    document.location = url.replace(/\/es\//, "/en/");
  }
  if  (/\/en\//.test(url)) {
    document.location = url.replace(/\/en\//, "/es/");
  }

}
