/*global window,jQuery */
/*jslint browser: true, undef: true, newcap: true */

(function($) {

  // checkout step 1: sets value for legitimatienummer field and triggers bubble when needed
	var setIdNumber = function(val) {
		switch(val) {
			case "V":
				$("#id-nr-bubble").removeClass("bubble-inactive");
				// $("#id-nr").val("NLD").focus(); Mantis: 8045; automatisch NLD in veld zetten is ongewenst
                // -- SB, Tue Feb 08 15:09:43 CET 2011
				$("#id-nr").val("").focus();
        break;
			default:
				$("#id-nr").val("");
				$("#id-nr-bubble").addClass("bubble-inactive");
        break;
		}
	};

  //Document ready
  $(function() {

    $(".lightbox-content").hide();

    $(".frames .frame-active h3 a").click(function() {
      return false;
    });

    $(".phonebox .checkbox-compare input[type=checkbox]").each(function() {
      this.checked = false;
    });

    var delay = 400;
    function hideMenu() {
      if (!$(".custom_button").data("in") && !$(".hover_menu").data("in") && !$(".hover_menu").data("hidden")) {
        $(".hover_menu").fadeOut("fast");
        $(".custom_button").removeClass("active");
        $(".hover_menu").data("hidden", true);
      }
    }
    $(".custom_button, .hover_menu")
      .mouseenter(function() {
        $(".hover_menu").fadeIn("fast");
        $(".custom_button").addClass("active");
        $(this).data("in", true);
        $(".hover_menu").data("hidden", false);
      })
      .mouseleave(function() {
        $(this).data("in", false);
        setTimeout(hideMenu, delay);
    });

		/* checkout */
		$("#id-type").change(function() {
			setIdNumber(this.value);
		});

    $(".arrow-specificaties, .reviewlink").click(function() {
      $(".tabs").telfortTabs($(this).attr("href"));
      $("body").scrollTo(".tabs", 500);
      return false;
    });

    /**
     * tabs are not scrollTo'd properly in IE. Because a stylefix is not possible
     * due to the complex nature of the tabs, we'll have to give an offset as
     * compensation.
     * TODO: it's strange the default behaviour is not triggered and we need
     * to manually scroll to these tabs. this needs to be fixed
     */
    var scrollToOptions = jQuery.browser.msie ? { offset: -40 } : null;
    if (window.location.hash == '#open-tab:tab-reviews') {
      $("body").scrollTo(".tabs", 500, scrollToOptions);
    }
    if (window.location.hash == '#open-tab:tab-telefoon-specificaties') {
      $("body").scrollTo(".tabs", 500, scrollToOptions);
    }

/*
	$(".radio-col-suboptions").find(".suboptions").hide();
	$(".radio-col-suboptions > .radio-field input:radio").each(function() {
		$(this).bind("change click", function(e, data) {
			var initial = typeof data == "object" && data.initial === true;
			if ($(this).is(":checked")) {
				var suboptions = $(this).parent().parent().parent().find(".suboptions");
				if($(this).attr("class")=="radio-suboptions-open") { 
					suboptions.showHideSlider(initial, "show");
				} else {
					suboptions.showHideSlider(initial, "hide");
				}
			}
		})
		.trigger("change", { initial: true })
	});
*/
	
	$('#withoutkvk').hide(); $('#withkvk').hide();
	$("#rechtsvorm").each(function() {
		$(this).bind("change", function(e, data) {
			var initial = typeof data == "object" && data.initial === true;
			if ($(this).val().length > 0) {
				var withoutkvk = $('#withoutkvk');
				var withkvk = $('#withkvk');
				if( $(this).val() === '10' || $(this).val() === '11' ) {
					withoutkvk.showHideSlider(initial, "show");
					withkvk.showHideSlider(initial, "hide");
				} else { 
					withoutkvk.showHideSlider(initial, "hide");
					withkvk.showHideSlider(initial, "show");					
				}
			}
		})
		.trigger("change", { initial: true })
	});
	$(".checkout_url").each(function() {
		var target = $(this).attr("value");
		$(this).parent().find("input[type=radio]").click(function() {
			window.location = target;
		});
	});
  });

  $.easing.easeInOutQuad = function (x, t, b, c, d) {
    if ((t/=d/2) < 1) return c/2*t*t + b;
    return -c/2 * ((--t)*(t-2) - 1) + b;
  };

}(jQuery));

