jQuery.noConflict();
jQuery(document).ready(function($){

	/* equal product height */
	$('.product-row').each(function(){
		$(this).find('.product .text').equalHeightColumns();
	});

	/* show login */
	$('#loginLink').click(function(e){
		e.preventDefault();
		$('#login').slideToggle();
	});

	/* present finder */
	var choose = $('#finder div.choose').find('input, select');
	choose.change(function(){
		var t = $(this);
		if (t.val()) $(this).parent().find('.info').show();
		else t.parent().find('.info').hide();
	});
	choose.each(function(){
		$(this).change();
	});
	var age = $('#finder div.age').find('select');
	age.change(function(){
		var t = $(this);
		var info = t.parent().find('.info');
		var changed = false;
		// validate age range
		if (age.last().val() && age.first().val() > age.last().val()) info.addClass('error');
		else info.removeClass('error');
		// check if at least 1 select is set
		age.each(function(){
			if ($(this).val()) changed = true;
		});
		if (changed) info.show();
		else info.hide();
	});
	age.each(function(){
		$(this).change();
	});

	/* image popup */
	$('#productimages a').fancybox({
		overlayOpacity: 0.8,
		overlayColor: '#000'
	});
	$("a.shippingcosts, a.popup").fancybox({
		'width'						: 800,
		'height'					: '80%',
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'						: 'iframe',
		overlayOpacity: 0.8,
		overlayColor: '#000'
	});
	
	/* checkout info buttons */
	$("a.popup_small").live("click",function(elem){
		elem.preventDefault();
		var href = this.href;
		$.fancybox({
			'href'					: href,
			'width'					: 400,
			'height'				: 300,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'type'					: 'iframe',
			overlayOpacity: 0.6,
			overlayColor: '#000'
		});
	});

	/* search */
	default_text = 'Ihr Suchbegriff...';
	$('#keywords').focusin(function(){
		$this = $(this);
		$this.css('color', '#333');
		if ($this.val() == default_text) {
			$this.val('');
		}
	}).focusout(function(){
		$this = $(this);
		$this.css('color', '#999');
		if ($this.val() == '') {
			$this.val(default_text);
		}
	});

	/* shopping cart update quantity */
	$('#cart_quantity select.shopping_cart').change(function(){
		$('#cart_quantity').submit();
	});

	/* js test logging*/
	if ($('#jstest').length) {
		$.get('inc/js_test.inc.php?js='+$('#jstest').attr('data-cartid'));
	}
});

function showWaitMessage() {
	document.getElementById("infoDiv").style.display = "none";
	document.getElementById("waitingDiv").style.display = "block";
}

