var CHRONOSHARE;

var PAGE; // no default page anymore (no reason to have)
var PARAMS = [];
var URIPARAMS = "";

function nav_anchor(aurl)
{
  aurl = aurl.split('#');
  if (aurl[1]) {
    aurl_split = aurl[1].split('&');
    page = aurl_split[0];

    vars = [];
    for (var i = 1; i < aurl_split.length; i++) {
      hash = aurl_split[i].split('=');
      vars.push(hash[0]);
      // there is strange double-encoding problem...
      vars[hash[0]] = decodeURIComponent(decodeURIComponent(hash[1]));
    }

    // if (page != PAGE)
    // {
    //     PAGE = page;
    //     PARAMS = vars;
    //     URIPARAMS = aurl[1];

    //     if (CHRONOSHARE) {
    //         CHRONOSHARE.run ();
    //     }
    // }
    // else if (aurl[1] != URIPARAMS)
    // {
    //     PARAMS = vars;
    //     URIPARAMS = aurl[1];

    //     if (CHRONOSHARE) {
    //         CHRONOSHARE.run ();
    //     }
    // }

    // this way we can reload by just clicking on the same link
    PAGE = page;
    PARAMS = vars;
    URIPARAMS = aurl[1];

    if (CHRONOSHARE) {
      CHRONOSHARE.run();
    }
  }
}

$(document).ready(function() {
  nav_anchor(window.location.href);

  if (!PARAMS.user || !PARAMS.folder) {
    $("#error").html("user and folder must be be specified in the URL");
    $("#error").removeClass("hidden");
    return;
  }
  else {
    // update in-page URLs
    $(".needs-get-url").each(function(index, element) {
      this.href +=
        "&user=" + encodeURIComponent(encodeURIComponent(PARAMS.user)) +
        "&folder=" + encodeURIComponent(encodeURIComponent(PARAMS.folder));
    });
    $(".needs-get-url").removeClass("needs-get-url");
  }

  CHRONOSHARE = new ChronoShare(PARAMS.user, PARAMS.folder);
  CHRONOSHARE.run();

  $(window).on('hashchange', function() {
    nav_anchor(window.location.href);
  });

  $("#reload-button").click(function() {
    nav_anchor(window.location.href);
  });
});
