$(function() {	
	
	jQuery.httpbase = function( ){
		return $('base')[0].href;
	}
	
	//SUPPORT
	var values = new Array();
	var inputs = $(":input");
	
	inputs.each(function(i,e) {
		values[i] = e.value;
		if($(e).hasClass("clear")) {
			$(e).focus(function() {			
				if(e.value == values[i]) {				
					e.value = '';
				}
			});
			$(e).blur(function() {
				if(e.value == '') {
					e.value = values[i];
				}
			});
		} else if($(e).hasClass("password")) {
			$(e).focus(function() {			
				if(e.value == values[i]) {				
					e.value = '';
					e.type = 'password';
				}		
			});
			$(e).blur(function() {
				if(e.value == '') {
					e.value = values[i];
					e.type = 'text';
				}				
			});
		}
	});
	
	$(".clickable").click( function() {					
		document.location.href=$('a:eq(0)',this).attr('href');
		return false;
	});
	
	//als class firstlink is dan hele blok als link door middel van 1 a tag
	$('.firstlink').each(function() {
		$(this).click(function() {
			document.location.href = $(this).find('a[href]').get(0).href;
		});
		$(this).bind('mouseenter',function() {
			$(this).find('a[href]').eq(0).addClass('hover');
		});
		$(this).bind('mouseleave',function() {
			$(this).find('a[href]').eq(0).removeClass('hover');
		});
	})
	
	// zoekblok tekst
	$('.input-search').each( function() {
		valueSearch = $(this).val();		
		$(this).focus( function() {
			if($(this).val() == valueSearch) {
				$(this).attr("value","");
			}
		});
		$(this).blur( function() {
			if($(this).val() == "") {
				$(this).attr("value",valueSearch);
			}
		});
	});
	
	$("#shoppen img").hover( 
		function(){
			$(this).attr('src',$(this).attr('src').replace('.jpg','_hover.jpg'));
		},
		function() {			
			$(this).attr('src',$(this).attr('src').replace('_hover.jpg','.jpg'));
		}
	);	
	
	$("#menu .item").each( function() {
		$(this).hover(
			function(){
				$('.items',this).show();
			},function(){
				$('.items',this).hide();
			}
		);
	});
	
	$("#form .orderitems .aantal form select").change( function() {
		$(this).parent("form").submit();
	});
	
	$(".detail .checkbox").bind('click', function() {
		if($(this).hasClass("active")) {
			$(this).removeClass("active");
			$('input',this).removeAttr('checked');
		} else {
			$(this).addClass("active");
			$('input',this).attr('checked','checked');
			$.get('shop/opsterkte/'+$("#detail input[name='artikel_id']").val(), function(data) {
				$.popup.show(data);
				$("#bestellen .checkbox").bind('click', function() {
					if($(this).hasClass("active")) {
						$(this).removeClass("active");
						$('input',this).removeAttr('checked');
						$('#bestellen span').removeAttr("disabled");
						$('#bestellen select').removeAttr("disabled");
					} else {
						$(this).addClass("active");
						$('input',this).attr('checked','checked');
						$('#bestellen span').attr("disabled","disabled");	
						$('#bestellen select').attr("disabled","disabled");	
					}
					return false;
				});
				$(".info").hover( 
					function() {
						$('span',this).show();
					},
					function() {
						$('span',this).hide();
					}	
				);
			});
		}
		return false;
	});
	
	$("#detail form[name='bestellen']").submit( function() {
		if($("input[name='opsterkte']",this).is(":checked")) {
			$.get('shop/opsterkte/'+$("#detail input[name='artikel_id']").val(), function(data) {
				$.popup.show(data);
				$("#bestellen .checkbox").bind('click', function() {
					if($(this).hasClass("active")) {
						$(this).removeClass("active");
						$('input',this).removeAttr('checked');
						$('#bestellen span').removeAttr("disabled");
						$('#bestellen select').removeAttr("disabled");
					} else {
						$(this).addClass("active");
						$('input',this).attr('checked','checked');
						$('#bestellen span').attr("disabled","disabled");	
						$('#bestellen select').attr("disabled","disabled");	
					}
					return false;
				});
				$(".info").hover( 
					function() {
						$('span',this).show();
					},
					function() {
						$('span',this).hide();
					}	
				);
			});
			return false;
		} 
	});
	
	$(".view").click(function() {
		if($(this).hasClass("zij")) {
			$(".items .item .img_zij").show();
			$(".items .item .img_voor").hide();
			$(this).addClass('active');
			$(".view.voor").removeClass('active');
			$.ajax({
				url: "shop/setview",
				type: "get",
				data: ({view: 'zij'})
			});
		} else if($(this).hasClass("voor")) {
			$(".items .item .img_zij").hide();
			$(".items .item .img_voor").show();
			$(this).addClass('active');
			$(".view.zij").removeClass('active');
			$.ajax({
				url: "shop/setview",
				type: "get",
				data: ({view: 'voor'})
			});
		} 
	});
	
});
