$(document).ready(function() {

  reader = {
      getRecords : function(json){
        try{return json.W3MAN.SEARCH.SUGGEST.LOOP[0]?json.W3MAN.SEARCH.SUGGEST.LOOP[0]:[];}catch(e){return[];}
      },getLabel : function(o) {
        return o;
      },getValue : function(o) {
        return o;
      }
  };

  handleFire = function(label, value) {
      this.input.value=label;
      this.input.form.submit();
  };

  CndSuggest.prototype.handleFire = handleFire;
  CndSuggest.init(reader);

  $("#nlsubmit").click(function() {
    $("#newsletterReg").submit();
  });

  $("#agentSubmit").click(function() {
    $.ajax({
      type: "GET",
      url: $("#auth").attr("action"),
      username: $("#login").val(),
      password: $("#password").val(),
      dataType: "html",
      processData: false,
      success: function(data) {
        window.location = $("#auth").attr("action");
      }
    }).error(function() { 
      // Fehler
    });
  });

  $("#searchbox").autocomplete("search.php", {
    width: 260,
    selectFirst: false
  });

  $("div.address").click(function() {
    window.location = $("#AdressePage").attr("href");
    return false;
  });

  $("#colors div").toggle(
    function() {
      $(this).find("span.open").animate({width: "hide"}, 100);
      $(this).find("div.bar").animate({width: "show"}, 200);
    },
    function() {
      $(this).find("div.bar").animate({width: "hide"}, 200);
      $(this).find("span.open").animate({width: "show"}, 100);    
    }
  );

  $("#colors div div.bar").click(function() {
    $(this).parent().trigger('click');
  });

  $("#colors div div.bar ul li a").click(function() {
    window.location = $(this).attr('href');
  });

  // Lightbox
    $("a.lightbox").lightBox({
      imageLoading:   'http://www.schober-gmbh.de/media/80/lightbox-ico-loading.gif',    // (string) Path and the name of the loading icon
      imageBtnPrev:   'http://www.schober-gmbh.de/media/82/lightbox-btn-prev.gif',    // (string) Path and the name of the prev button image
      imageBtnNext:   'http://www.schober-gmbh.de/media/84/lightbox-btn-next.gif',    // (string) Path and the name of the next button image
      imageBtnClose:  'http://www.schober-gmbh.de/media/81/lightbox-btn-close.gif',    // (string) Path and the name of the close btn
      imageBlank:     'http://www.schober-gmbh.de/media/83/lightbox-blank.gif',    // (string) Path and the name of a blank image (one pixel)
      txtImage:       '',  // (string) Specify text "Image"
      txtOf:          '/',    // (string) Specify text "of"
      keyToClose:     'c',    // (string) (c = close) Letter to close the jQuery lightBox interface. Beyond this letter, the letter X and the SCAPE key is used to.
      keyToPrev:      'v',    // (string) (p = previous) Letter to show the previous image
      keyToNext:      'n'     // (string) (n = next) Letter to show the next image.
    });
});
