// JQUERY CUSTOM COMMANDS
$(document).ready(function() {  // start javascript when document is loaded

	/* Place the Error class in the parent <li> Control for the UserData control */
	$('.formfields').find('.faulted').parent().parent().parent().addClass('error');

	/* ADD CLASSES FOR LAYOUT STYLING */
	$('#columnRight .box:last').addClass('last');


	/* MENU HOVERS */
	$('#mainMenu li, .selectors ul > li.hideSelector, .listRelative, .forwarding .dropdown, .contact .dropdown').hover(function() { // IE6 does not support :hover on elements other than <a>
		$(this).addClass('hover');
		$(this).next('li').addClass('afterActive');
	}, function() {
		$(this).removeClass('hover');
		$(this).next('li').removeClass('afterActive');
	});

	/* MAIN MENU active state */
	$('#mainMenu li.active').next('li').addClass('afterActive');

	// ACCOUNT INPUT LABELS as background
	/* <-- Moved to jquery.custom.language_{lc}.js */


	// CHECKBOXES DELIVERYADDRESS 06_afleveradres
	//Hide div w/id extra
	$(".addressTwo").css("display", "none");
	if ($(".cbDeliveryAddress").find("input").is(":checked")) {
		//show the hidden div
		$(".addressTwo").css("display", "block");
	}
	// Add onclick handler to checkbox w/id checkme
	$(".cbDeliveryAddress2").find("input").click(function() {
		// If checked
		if ($(".cbDeliveryAddress2").find("input").is(":checked")) {
			//show the hidden div
			$(".addressTwo").show("fast");
		}
		else {
			//otherwise, hide it
			$(".addressTwo").hide("fast");
		}

	});


	// ACCOUNT LINKS
	$(".boxAccount li.dropdown a").click(function() {
		$(this).parent('li').find('ul').show();
		return false;
	});


	// FILTERS
	// make filter active
	$('.customSelect:has(input)').removeClass('active');
	$('.customSelect:has(input:checked)').addClass('active');

	$(".customSelect input").click(function() {
		$('.customSelect:has(input)').removeClass('active');
		$('.customSelect:has(input:checked)').addClass('active');
	});
	// clear selection
	$(".clearSelection").click(function() {
		$('.filterBox .filters').find('input').attr('checked', '');
		$('.filterBox .filters .customSelect').removeClass('active');
		return false;
	});


	/* LISTER */                           /* zonder de td's werkt ie niet in mijn account pagina */
	$("tbody tr:odd td").addClass('odd');
	$("tbody tr:even td").addClass('even');
	$("tbody tr:first td").addClass('first');
	$("tbody tr:last td").addClass('last');
	$('tbody tr td').hover(function() {
		$(this).addClass('hover');
	}, function() {
		$(this).removeClass('hover');
	});


	// IE6- only
	if ($.browser.msie && $.browser.version == 6) {
		/* HIDE SELECTS ON ABSOLUTE HOVERS in lister pagina van toepassing*/
		$('.hideSelector').hover(function() {
			$('.sorting select, .sortbox select').hide();
		}, function() {
			$('.sorting select, .sortbox select').show();
		});
	}




	/* FAQ TOGGLE in faq*/
	$('.faqList .faqAnswer').hide();
	$('.faqList .faqQuestion a').click(function() {
		$(this).parents('.faqList').find(".faqAnswer").hide(); // Hide all answers
		$(this).parents('.faqList').find('li').removeClass("active");
		$(this).parents('li').find(".faqAnswer").show(); // Show current answer
		$(this).parents('li').addClass("active");
		return false;
	});


	/* FAQ TOGGLE                                              de slideup en doen zijn mooi maar werken nie op sommige pcs in ie6
	$('.faqList .faqAnswer').hide();
	$('.faqList .faqQuestion a').click(function() {
	$(this).parents('.faqList').find(".faqAnswer").slideUp(200); // Hide all answers
	$(this).parents('.faqList').find('li').removeClass("active");
	$(this).parents('li').find(".faqAnswer").slideDown(200); // Show current answer
	$(this).parents('li').addClass("active");
	return false;
	});
	*/

	/* SET PRICE CHECKBOX TOGGLE in bsbykmer details*/
	$('.setPriceBox .clickRow').click(function(event) {
		var $target = $(event.target);
		if ($target.is(":not('input, label')")) {
			$(':checkbox', this).trigger('click');
		}
	});
	$('.setPriceBox .clickRow').hover(function() {
		$(this).find('td').css({ 'background-color': '#fff', 'cursor': 'pointer' });
	}, function() {
		$(this).find('td').css({ 'background-color': 'transparent', 'cursor': 'default' });
	});

	/* IMAGE HOVER CLASS vergelijkpagina*/
	$('.compareTable td.image img').hover(function() { // IE6 does not support :hover on elements other than <a>
		$(this).addClass('hover');
	}, function() {
		$(this).removeClass('hover');
	});


	/* HIDE/SHOW TD's vergelijkpagina*/
	$(".compareTable tr").find("th.theadTh:gt(2)").hide();
	$(".compareTable tr").find("td:gt(2)").hide();
	$(".prev").hide();

	var n = $(".compareTable .theadTh").length; // aantal tableheads met class theadTh tellen
	var teller = 1; // teller begint op 1

	if (n <= 3) {
		$(".next").hide();
	}

	$('.next').click(function() {
		$("tr").find("td:visible:last, th.theadTh:visible:last").next("td:hidden, th.theadTh:hidden").show();
		$("tr").find("td:visible:first, th.theadTh:visible:first").hide();
		teller++;
		//alert(teller);
		showhideButtons(); // roep showhidefunctie op als je op next klikt
		return false;
	})


	$('.prev').click(function() {
		$("tr").find("td:visible:first, th.theadTh:visible:first").prev("td:hidden, th.theadTh:hidden").show();
		$("tr").find("td:visible:last, th.theadTh:visible:last").hide();
		teller--;
		// alert(teller);
		showhideButtons(); // roep showhidefunctie op als je op prev klikt
		return false;
	})

	function showhideButtons() {
		if (teller == (n - 2)) { // als teller opgeteld tot totaal aantal th's -2 dan next button hide, anders show
			$(".next").hide();
		} else {
			$(".next").show();
		}

		if (teller == 1) { // als teller beginwaarde prev hide, anders show.
			$(".prev").hide();
		} else {
			$(".prev").show();
		}
	}

	/* EQUAL HIGHTS gerelateerde producten*/
	equalHeight($("#top3 .row .rbcontentTop3"));
	function equalHeight(group) {
		tallest = 0;
		group.each(function() {
			thisHeight = $(this).height();
			if (thisHeight > tallest) {
				tallest = thisHeight;
			}
		});
		group.height(tallest);
	}
	
	$('#langSelect').hover(function() {
		$(this).addClass('hover');
	}, function() {
		$(this).removeClass('hover');
	});

});   // end ready function


