$(function(){
	$('#pageback').click(function() {
		window.history.back();
	});

	$('.product-search-price-categorie-option').bind('mousemove',function(event) {
		var msg = $(this).children('.product-search-price-categorie-description').html();
		$('#product-search-price-categorie-description').html(msg);
		
		var mouseX = event.pageX;
		$('#product-search-price-categorie-description').css({'left':mouseX, 'display': 'block'});
	});
	
	$('.product-search-price-categorie-option').bind('mouseout',function(event) {
		$('#product-search-price-categorie-description').hide();
	});

});


$(function(){
	//position the result info
	var columnHeight = 0;
	$('.product-search-column').each(function(){
		if($(this).height() > columnHeight){
				columnHeight = $(this).height();
				$('.product-search-column').height(columnHeight+10);
			}
	});
	
	if(columnHeight>80){
		var marginTop = columnHeight+10-45;
		$("#product-search-resultInfo").css('marginTop',marginTop);
	}

	
	//checkbox replacement
	$('#product-search-container input:checkbox').checkBox(); 
	$('#product-search').live('change',submitSearchForm);
	$('#product-search-search-ref-field').live('keyup',submitSearchForm);
	$('.ui-checkbox').bind('click',submitSearchForm);
	
	//submit the form
	$('#product-search-submit').click(function() {
		$('#product-search').submit();
	});
});


function submitSearchForm(event) {
		$('#product-search').ajaxSubmit({
			dataType: 'json',
			url: '/nl/deuren/count',
			success: function(data, responseCode) {
				var output = '';
				var multiple = false;
				
				if(data==0) {
					output = '0 producten';
					multiple= true;
				} else if(data==1) {
					output = '1 product';
				} else {
					output = data+' producten';
					multiple= true;
				}
				
				$('#product-search-result-amount').html(output);
				if(multiple) {
					$('#product-search-result-text').html('voldoen');
				}else{
					$('#product-search-result-text').html('voldoet');
				}
		 }
	});
	
}



function adjustActiveMenu (menu) {
	$(window).load(function() {
		$('#mainmenu ul li').each(function() {
			if($(this).children('a').html()==menu)
				$(this).addClass('active');
			else
				$(this).removeClass('active');
		});
	});
}

// zoom
function productZoom () {
	$(function() {
		var options = {
					zoomType: 'reverse',
					zoomWidth: 499,
					zoomHeight: 343,
					xOffset: 12,
					title: false,
					yOffset: 0,
					hideEffect:'fadeout',
          fadeoutSpeed: 'slow',
					position: "right" //and MORE OPTIONS
		};
		$('.product-detail-image').jqzoom(options);
	});
}

// select options by categorie header
$(function() {
	$('.product-search-column h1').bind('click',function() { 

		var allChecked = true;
		$(this).parents('.product-search-area').children('div').each(function() {
			if($(this).children('input').attr('checked')==false)
			allChecked = false;
		})
		

		$(this).parents('.product-search-area').children('div').each(function() {
			if(allChecked){
				$(this).children('input').checkBox('changeCheckStatus',false);
			}else{
				$(this).children('input').checkBox('changeCheckStatus',true);
			}
		})
		submitSearchForm();
	});
});

if( typeof Array.prototype.push != "function") {
	Array.prototype.push = ArrayPush;function ArrayPush(value){this[this.length]=value;}
}

function log(msg){
	if(window.console)
	window.console.log(msg);
}
