//epi redirect for facebook share
//redirects URLs that end with ?chapter=3 to #ch3
function getParameterByName( name ) {
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results === null )
    return "";
  else
    return decodeURIComponent(results[1].replace(/\+/g, " "));
}

var epi_param = getParameterByName( 'chapter' );
if( epi_param ) {
	window.location.hash = '#ch'+epi_param;
	window.location.search = window.location.search.replace( /([\&]{1})?chapter=([^&#]*)([\&]{1})?/, '' );
}
