$(document).ready(function() {
  $("ul.menu li").each(function(i, elm) {
    $(elm).bind("mouseover", function() {
      hideBullet();

      showBullet(elm);
    });

    $(elm).bind("mouseout", function() {
      hideBullet();
    });
  });

  function showBullet(elm) {
    $("div.menu_bullet").clone().prependTo($(elm));

    $("div.menu_bullet:not(:first)").css("margin-top", "-15px");
    $("div.menu_bullet:not(:first)").css("margin-left", "-20px");

    $("div.menu_bullet:not(:first)").show();
  }

  function hideBullet() {
    $("div.menu_bullet:not(:first)").remove();
  }
});

/* A TARGET */
(function($) {
  $.fn.target = function() {
    return this.each(function(index, elm) {
      if (substr($(this).attr("class"), 0, 7) == 'target-') {
        $(this).attr("target", substr($(this).attr("class"), 7));
      }
    });
  }
})(jQuery);

$(document).ready(function() {
  $("a").target();
});

/* AUTO HEIGHT */
(function($) {
  $.fn.autoHeight = function(movement, type) {
    return this.each(function(index, elm) {

      if (type != 'non-full') {
        var parent_sibl_height = 0;
        var margins = 0;

        $(this).parent().siblings().each(function() {
          parent_sibl_height += $(this).height();

          /* ADDING TOP MARGIN TO HEIGHT */
          margins = $(this).css("margin-top");
          margins = margins.replace('px', '');

          if (margins != 'auto') {
            margins = parseInt(margins);

            parent_sibl_height += margins;
          }

          /* ADDING BOTTOM MARGIN TO HEIGHT */
          margins = $(this).css("margin-bottom");
          margins = margins.replace('px', '');

          if (margins != 'auto') {
            margins = parseInt(margins);

            parent_sibl_height += margins;
          }

        });

        $(this).parent().css("height", ($(window).height() - parent_sibl_height));
      }

      var sibl_height = 0;
      var parent_height = $(this).parent().height();
      var margins = 0;

      $(elm).siblings().each(function() {
        sibl_height += $(this).height();

        /* ADDING TOP MARGIN TO HEIGHT */
        margins = $(this).css("margin-top");
        margins = margins.replace('px', '');

        if (margins != 'auto') {
          margins = parseInt(margins);

          sibl_height += margins;
        }

        /* ADDING BOTTOM MARGIN TO HEIGHT */
        margins = $(this).css("margin-bottom");
        margins = margins.replace('px', '');

        if (margins != 'auto') {
          margins = parseInt(margins);

          sibl_height += margins;
        }

        if (movement == 'scroll' && type != 'non-full') {
          $(elm).parent().css("min-height", ($(window).height() + $(window).scrollTop()) + 'px');
        }

      });

      if (type == 'non-full') {
        if (parent_height > sibl_height) {
          $(this).css("min-height", parent_height + 'px');
        } else {
          $(this).css("min-height", sibl_height + 'px');
        }
      } else {
        $(this).css("min-height", (parent_height - sibl_height) + 'px');
      }

    });
  }
})(jQuery);

$(document).ready(function() {
  $(".auto-height").autoHeight(null, 'non-full');

  $("div.lang").children("a").bind("click", function() {
    var id = $(this).attr("id");

    var values = {
      sl_id: id
    }

    $.POST(window.location.href, values);
  });

  $('img[@src$=.png]').pngfix({
		sizingMethod: "scale",
		imageFixSrc: "/images/pixel.gif"
	});
});

$(window).scroll(function() {
  $(".auto-height").autoHeight('scroll', 'non-full');
});

$(window).resize(function() {
  $(".auto-height").autoHeight(null, 'non-full');
});


function search_store() {
  var category = $(":input[name='category']").val();
//  var branche = $(":input[name='branche']").val();
  var keyword = $(":input[name='keyword']").val();

  var url = '/winkel-zoeken/';

  if (category.length == 0 && keyword.length == 0) {
    alert('Er moet minimaal een criterium ingevuld worden.');
  } else {

    if (category.length > 0) {
      url += category;
    } else {
      url += 'null';
    }

    url += '/';

//    if (branche.length > 0) {
//      url += branche;
//    } else {
//      url += 'null';
//    }
//
//    url += '/';

    if (keyword.length > 0) {
      url += keyword;
    } else {
      url += 'null';
    }

    url += '/';

    if (url) {
      window.location.href = url;
    }
  }
}