Hash.ify = function(a) {
	answer = $H();
	a.each(function(el) { answer.set(el.id, el)})
	a.get = answer.get.bind(answer)
	a.keys = answer.keys.bind(answer)
	return answer;
}

Array.prototype.empty = function() { return this.size() == 0 }

Array.prototype.sum = function(){
	for(var i=0,sum=0;i<this.length;sum+=this[i++]);
	return sum;
}


function loaded()
{
	$$(".highlight").each(function(link) {
		var href = link.href;
		var id = href.substr(href.indexOf("#") + 1)
		var target = $(id)
		
		if (target)
		{
			link.href = "#"
			Event.observe(link, "click", function() {
				new Effect.ScrollTo(target, {duration: 0.75, afterFinish: function() {
					window.location = window.location + id
					target.pulsate()
					target.nextSiblings().first().pulsate()
					//new Effect.Highlight(target, {startcolor: "#A99162"});
					//new Effect.Highlight(target.nextSiblings().first(), {startcolor: "#A99162"})			
				}})
			});
		}
	})

  $$("#outer input[type='checkbox']").each(function(b) {
    replacement = new Element("div", {"class": "pseudocheck"});
    replacement.original = b
    
    if (b.checked)
    {
      replacement.update(new Element("img", {src: "/icons/tick.png"}))
    }
    
    b.hide()
    
    replacement.observe("click", function(e) {
      r = e.element()
      
      if (r.tagName == "IMG") r = r.parentNode
      
      o = r.original
      if (o.checked)
      {
        r.update("");
      }
      else
      {
        r.update(new Element("img", {src: "/icons/tick.png"}))
      }
      
      o.checked = !o.checked
    })
    
    b.insert({"before": replacement})
  });
  
  if ($("track_file"))
  {
    //new Form.Element.Observer($("track_file"), 1, um.update.bind(um))
    $("track_file").observe("change", $("upload").show.bind($("upload")))
  }
}

Event.observe(window, "load", loaded)
