$(document).ready(function() {
    
  $(".product .photo").prepend("<img src='images/products/product_top.png' alt='' class='product_top' />");
  // Switch tussen aan- en afmelden nieuwsbrief
  var newsletterFirst = $("#nieuwsbriefblok .block_special h2:first, #nieuwsbriefblok .block_special p:first, #nieuwsbriefblok .block_special form:first");
  var newsletterSecond = $("#nieuwsbriefblok .block_special h2:last, #nieuwsbriefblok .block_special p:last, #nieuwsbriefblok .block_special form:last");
  $(newsletterSecond).hide();
  $("#nieuwsbriefblok .block_special a").click(function () {
    $(newsletterSecond).toggle();
    $(newsletterFirst).toggle();
    return false;
  });
  

  // Equal height selectors
  $("#indexblocks .block_outline, #indexblocks .block_special").equalHeights();
  $(".product").equalHeights();
  // Voeg deelnemer toe

  $("#pntDetailsForm fieldset.deelnemer").after("<a href='javascript:void(0)' id='deelnemer_toevoegen' class='form_link'>"+cobraParticipantAddMessage+"</a>");

  
  $("#deelnemer_toevoegen").click(function(){
    var deelnemerFieldset = $("#pntDetailsForm fieldset.deelnemer:last");		
    var clone = $(deelnemerFieldset).clone();
    var prevId = parseInt($(clone).find("legend").text().split(" ").pop()) 
    var cloneId = prevId +1;
		clone.removeClass('deelnemer'+prevId);
		clone.addClass('deelnemer'+cloneId);
		
		var voorletters = pntGetRequestParam("deelnemer_voorletters_"+cloneId);
		var naam = pntGetRequestParam("deelnemer_name_"+cloneId);
		var email = pntGetRequestParam("deelnemer_email_"+cloneId);
		var strLegend = cobraParticipantMessage.replace('[nummer]', cloneId);

    $(clone).find("legend").text(strLegend);
    
    $(clone).find("label[for^='deelnemer_voorletters']").attr("for","deelnemer_voorletters_"+cloneId);
    $(clone).find("input[name^='deelnemer_voorletters']").attr("name","deelnemer_voorletters_"+cloneId).attr("id","deelnemer_voorletters_"+cloneId);
    if (pntIsDefined(voorletters)) $(clone).find("input[name^='deelnemer_voorletters']").attr("value",voorletters);
    $(clone).find("label[for^='deelnemer_name']").attr("for","deelnemer_name_"+cloneId);
    $(clone).find("input[name^='deelnemer_name']").attr("name","deelnemer_name_"+cloneId).attr("id","deelnemer_name_"+cloneId);
    if (pntIsDefined(naam)) $(clone).find("input[name^='deelnemer_name']").attr("value",naam);
    $(clone).find("label[for^='deelnemer_email']").attr("for","deelnemer_email_"+cloneId);
    $(clone).find("input[name^='deelnemer_email']").attr("name","deelnemer_email_"+cloneId).attr("id","deelnemer_email_"+cloneId);
    if (pntIsDefined(email)) $(clone).find("input[name^='deelnemer_email']").attr("value",email);
	  $(clone).insertBefore(this);
    
    if (cloneId > 1) $(clone).find("legend").append("<a href='javascript:void(0)' class='verwijder_deelnemer'>"+cobraDeleteMessage+"</a>");
    
    $(".verwijder_deelnemer").click(function () {
      $(this).closest("fieldset.deelnemer").remove();
      return false;
    });
  
  });
  
  var $tabs = $('#tabwrapper #tab_navigation > ul.inline').tabs();
  $('#andere_downloads').click(function() { // bind click event to link
    $tabs.tabs('select', 3); // switch to third tab
    return false;
  });
  $('.meerlezen').click(function() { // bind click event to link
    $tabs.tabs('select', 1); // switch to third tab
    return false;
  });
  $('.productcontent .call_to_action').click(function() { // bind click event to link
    $tabs.tabs('select', 5); // switch to third tab
    return false;
  });
  
  // Printlink toevoegen. Deze werkt niet zonder javascript, wordt dus ook niet getoond zonder javascript
  $("ul.servicelist li").after("<li class='print'><a href='javascript:void(0)' onclick='print()'>"+cobraPrintPageMessage+"</a></li>");
  
  $(".clickable_td tr").hover(function(){
    $(this).find("td").addClass("hover");
  },function(){
    $(this).find("td").removeClass("hover");
  });
  
  $(".clickable_td tr").bind("click", function(){
    var aHref = $(this).find("a:first").attr("href");
    window.location = aHref;
  });
  
  
  
  if (!pntIsDefined(pntGetRequestParam('deelnemer_name_1'))) {
  	$("#deelnemer_toevoegen").click.call($("#deelnemer_toevoegen"));
  }
  

});

jQuery.fn.equalHeights=function() {
  var maxHeight=0;
  this.each(function(){
   if (this.offsetHeight>maxHeight) {maxHeight=this.offsetHeight;}
  });
  this.each(function(){
   $(this).height(maxHeight + "px");
   if (this.offsetHeight>maxHeight) {
    $(this).height((maxHeight-(this.offsetHeight-maxHeight))+"px");
   }
});
};

$(document).ready(function(){
	$('#bevestig_button').click(function(){
		$(this).attr('disabled', true);
		$('#cartForm').submit();
	})
});
