$(function() {	
	$(".clickable").click( function() {
		href = $('a:eq(0)',this).attr('href');
		if( href != undefined ){
			document.location.href=$('a:eq(0)',this).attr('href');
		}
		return false;
	});
	
	$(".zoeken form").submit( function() {
		document.location.href=this.action + '/' + this.t.value;
		return false;
	});
	
	if($(window).width() < 1024) {
		$('body').css("background","none");
	}
	
	//SUPPORT
	var values = new Array();
	var inputs = $(":input");
	
	inputs.each(function(i,e) {
		values[i] = e.value;
		if($(e).hasClass("empty")) {
			$(e).focus(function() {			
				if(e.value == values[i]) {				
					e.value = '';
				}
			});
			$(e).blur(function() {
				if(e.value == '') {
					e.value = values[i];
				}
			});
		} 
	});
	
	$(document).ready(function() {		
		$.setHeight();			   
	});
	
	$('#menu ul:not(".no-sub") li').each(function(i,cat){
		$(cat).mouseover(function(){
			$('#menu .submenu').eq(i).show();
			$('#menu ul.cat li').eq(i).addClass('is_active');
		});
		$(cat).mouseout(function(){
			$('#menu .submenu').eq(i).hide();	
			$('#menu ul.cat li').eq(i).removeClass('is_active');
		});
	});
	$('#menu .submenu').each(function(i,cat){
		$(cat).mouseover(function(){
			$('#menu .submenu').eq(i).show();
			$('#menu ul.cat li').eq(i).addClass('is_active');
		});
		$(cat).mouseout(function(){
			$('#menu .submenu').eq(i).hide();	
			$('#menu ul.cat li').eq(i).removeClass('is_active');
		});
	});
	
	$('.shop_menu > .menu > ul > li').each(function(){
		$(this).addClass('bg'+Math.ceil(Math.random()*5));
	});
	
	$('.filter select').change(function(){
		document.location.href=this.value;
	});
	
	$('.filter input').click(function(){
		document.location.href=this.value;
	});
	
	$('.details .maat label').click(function(){
		$('.details .maat label').removeClass('is_active');
		$('.details .maat label input').removeAttr('checked');
		$(this).addClass('is_active');
		$('input',this).attr('checked','checked');
		
		$.ajax({
			url: 'shop/getprijs/',
			data: { artikelnr: $('input[name="artikelnr"]:checked').val()},
			dataType: 'html',
			type: 'POST',
			success: function(data) {
				$('.details .prijs').html(data);
			}	
		});
		return false;
	});
	
	$('.details .info .tabs .tab').each(function(i,e) {
		if(i>0) {
			$('.details .info .content').eq(i).hide();
		} else {
			$(e).addClass('is_active');
		}
		$(e).click(function(){
			$('.details .info .content').hide();
			$('.details .info .tabs .tab').removeClass('is_active');
			$('.details .info .content').eq(i).show();
			$('.details .info .tabs .tab').eq(i).addClass('is_active');
		});
	});
	
	$("form[name='bestellen']").submit(function(){
		if($("input[name='artikelnr']").attr('type')=='radio') {
			if ($("input[name='artikelnr']:checked", this).val()==undefined) {
				$('.error',this).show();
				return false;
			}
		}
	});
	
	$('label img').click(function(){
		$(this).parent('label').find('input').attr('checked','checked');
	});
	
	$('.merk').hover(
		function() {
			$(this).append('<div class="layer"></div>');
		}, function(){
			$('.layer',this).remove();
		}
	);
	
	$("a.open").click(function(){		
		window.open($(this).attr("href"),$(this).attr("title"),"status=0,toolbar=0,menubar=0,scrollbars=0,height=630,width=860")
		return false;
	});
});


$.setHeight = function() {
	$('.background').each( function() {
		$(this).height($(this).parent().height()+'px');
	});
}

$.nieuwsbrief = function() {	
	$.ajax({
		url: "nieuwsbrief/nb/",
		type: 'POST',
		data: $(".nb form[name='nb']").serialize(),
		dataType: 'html',
		success: function(data) {
			$('.nb').html(data);
		}
	});	
	return false;	
}
