$(function(){
	
	$(".clickable").click( function() {
		href = $('a:eq(0)',this).attr('href');
		if( href != undefined ){
			if($('a:eq(0)',this).attr('target')=='_blank') {
				window.open($('a:eq(0)',this).attr('href'));
			} else {
				top.window.location.href=$('a:eq(0)',this).attr('href');
			}
		}
		return false;
	});
	
	//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];
				}
			});
		} 
	});

	
	$("#zoeken form").submit( function() {				
		document.location.href=$(this).attr('action') + '/' + encodeURI($('input[name="t"]').val());
		return false;
	});
	
	$("#zoeken input").focus(function(){		
		$('#zoeken').addClass('is_active');
	});

	$("#zoeken input").blur(function(){
		$('#zoeken').removeClass('is_active');
	});
	
	$('#content .menu .special a').append('<img src="img/default/special.png" />');
	
	$('#tabs .tabs ul li:eq(0)').addClass('is_active');
	$('#tabs .content:eq(0)').show();
	
	$('#tabs .tabs ul li').each(function(i,e) {
		$(e).click(function(){
			$('#tabs .tabs ul li').removeClass('is_active');
			$('#tabs .content').hide();	
			$('#tabs .tabs ul li').eq(i).addClass('is_active');
			$('#tabs .content').eq(i).show();	
		});
	});
	
	$('.artikelen .artikel:has(.hover)').hover(
		function(){
			$('.normal',this).hide();
			$('.hover',this).show();
		},
		function(){
			$('.hover',this).hide();
			$('.normal',this).show();
		}
	);
	
	$('.filters .filter input[type="checkbox"]').click(function(){
		document.location.href=$(this).val();	
	});
	

	$(".thumbs .thumb").each( function(i) {
		if(i==0) {
			$(this).addClass('is_active');
		}
		$(this).mouseover( function() {
			$(".thumbs .thumb").removeClass('is_active');
			$(this).addClass('active');			
			$(".images .image img").attr('src',$('img',this).attr('src').replace('/100/','/445/').replace('/100/','/455/'));
			$(".zoom img").attr('src',$('img',this).attr('src').replace('/100/','/2000/').replace('/100/','/2000/'));
		});
	});
	
	/* zoom */
	var afbeeldingVerhoudingX = 1;
	var afbeeldingVerhoudingY = 1;
	$('.zoom').hide();
	$('.images .image').mousemove(function(e) {		
		var x = ((e.pageX - $(this).offset().left) * -1 * afbeeldingVerhoudingX) + 175;
		var y = ((e.pageY - $(this).offset().top) * -1 * afbeeldingVerhoudingY) + 226;		
		$('.zoom .innerzoom table').css('left', x + 'px').css('top', y + 'px');
	}).mouseover(function() {
		$('.zoom').show();
		afbeeldingVerhoudingX = $('.zoom .innerzoom img').width() / $('.images .image img').width();
		afbeeldingVerhoudingY = $('.zoom .innerzoom img').height() / $('.images .image img').height();
		
		$('.zoom .innerzoom').width($('.images .image').width()*afbeeldingVerhoudingX);
		$('.zoom .innerzoom').height($('.images .image').height()*afbeeldingVerhoudingY);
		
		
	}).mouseout(function() {
		$('.zoom').hide();
	});	
	
	var switchActive = false;
	var switchThema = "";
	
	if($('.thema .thumb img').length > 1) {
		$('.thema .thumb img').eq(0).addClass('is_active');
		switchThema = setInterval('$.switchThema()', 6000 );
	}

	$.switchThema = function() {		
		if(!switchActive) {
			switchActive = true;
			$('.thema .thumb img').each( function(i,e) {
				if($(e).hasClass('is_active')) {				
					active = i;				
					next =  $('.thema .thumb img').eq(active).next('img').length ? i+1 : 0;
				}		    		
			});	
				
			$('.thema .thumb img').eq(active).addClass('last_active');
			
			$('.thema .thumb img').eq(next).css({opacity: 0.0})
		        .addClass('is_active')
		        .animate({opacity: 1.0}, 750, function() {
		        	$('.thema .thumb img').eq(active).removeClass('is_active last_active');	  
		        	switchActive = false;
		    });	   	
		}
	}
	
	
	$.initSelectbox();
});
