//var img = ooc = null;
var agt=navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);
var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var _IE6 = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );

$(document).ready(function()
{
  // Input velden bewerken: datumvelden, reset knop en defaultvalues
  $("input:text:not([no_reset_img=true])").each(function(idx)
  {
    $(this).attr("def_val", $(this).attr("value"));
    if (typeof($(this).attr("short_date")) != "undefined") 
    { // Date input
      $(this).attr("def_short_date", $(this).attr("short_date"));
      img = document.createElement("img");
      img.className = "click calendar_img";
      img.input = $(this)[0];
      img.title = "Kalender openen.";
      img.onclick = open_calendar;
      img.src = "./webimages/calendar.jpg";
      $(this).bind("blur", input_date_blur).bind("focus", input_date_focus);
      $(this).parent().prepend(img);
      $(this)[0].img = img;
    } else
    { // Reset knop
      $(this).bind("change", function(e)
      {
        input_change(e);
      });
      
      img = document.createElement("img");
      img.className = "click reset_input_img";
      img.input = $(this)[0];
      img.title = "De waarde terugzetten naar de originele waarde (" + $(this).attr("value") + ").";
    
      img.onclick = reset_input;
      img.src = "./webimages/" + (_IE6 ? "IE6/reset.jpg" : "reset.png");
      $(this).parent().prepend(img);
      $(this)[0].img = img;
    }
    if (typeof($(this).attr("empty_value")) != "undefined" && ($(this).attr("value") == "" || $(this).attr("value") == $(this).attr("empty_value")) )
    { // Default values
      $(this).bind("focus", function(e) { input_def_val_focus(e); });
      $(this).bind("blur", function(e) { input_def_val_blur(e); });
      if (typeof($(this).attr("value")) == "undefined" || $(this).attr("value") == "")
        $(this).attr("value", $(this).attr("empty_value"));
      $(this).addClass("grayed");
    }
  });
  $("input:text, input:password").bind("focus", 
    function() { $(this).parent().addClass("input_focus"); }).bind("blur",
    function() { $(this).parent().removeClass("input_focus"); }
  );

  if (_IE6) $("#fade").centerScreen();
  $("#ajax_load_img").centerScreen();
  
  window.onscroll = function(e) 
  {
    if (_IE6)
    {
      $("#fade").css("top", get_scroll_top() + "px");
      $("#wait").css("top", get_scroll_top() + "px");
    }
  }
  // Geen title, wel alt? Title de alt dan
  $(":[alt]:not([title]):not([no_hint])").each(function()
  {
    $(this).attr("title", $(this).attr("alt"));
  });
  $(window).bind("keydown", check_keys);
  
  // Email adressen
  $("a.liame").each(function()
  {
    var v = $(this).attr("href").substr(7);
    var v_new = v.replace("[emat]", "@").replace(/\[emdot\]/g, ".");

    $(this).attr("href", "mailto:" + v_new);
    if ($(this).text() == v) $(this).text(v_new);
  });
  // Zorg dat alle input velden met een enter een submit doen
  $("input:text, input:password").bind("keypress", function(e)
  {
    var c = e.charCode || e.keyCode;
    if (c == 13) $(this).closest("form").find("#form_submit").trigger("click");
  });
  $("img").bind("error", function() { $(this).hide(); });
  $("#photo_fade").bind("click", function() { if (cancel_func) cancel_func(); });
});
