$(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;
	});
	
	//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];
				}
			});
		} 
	});
	
	$('.add_corners').append('<div class="c t_l"></div>').append('<div class="c t_r"></div>').append('<div class="c b_l"></div>').append('<div class="c b_r"></div>');

	var switchActive = false;
	var switchBanner = "";
	   
	$('.acties.items .item').each(function(i,e) {
		if(i==0) {
			$('.acties.banners .item').eq(i).addClass('is_active');
			$('.acties.items .item').eq(i).addClass('is_active');
		}
		$(this).mouseover(function(){
			if(!switchActive) {										
				$('.acties.items .item').each( function(j,e) {
					if($(e).hasClass('is_active')) {				
						active = j;									
					}		    		
				});
				next = i;			
				if(active!=next) {
					switchActive = true;	
					clearInterval(switchBanner);		
					$('.acties.banners .item').eq(active).addClass('last_active');
					$('.acties.items .item').removeClass('is_active');
					$('.acties.items .item').eq(next).addClass('is_active');
					
					$('.acties.banners .item').eq(next).css({opacity: 0.0})
				        .addClass('is_active')
				        .animate({opacity: 1.0}, 250, function() {
				        	$('.acties.banners .item').eq(active).removeClass('is_active last_active');	
				        	switchBanner = setInterval('$.switchBanners()', 4000 );
				        	switchActive = false;
				    });	 
				}
			}
		});
	});
	
	if($('.acties.banners .item').length > 1) {
		$('.acties.banners .item').eq(0).addClass('is_active');
		switchBanner = setInterval('$.switchBanners()', 4000 );
	}
	
	if($(".merken").length > 0) {
		$(".merken").smoothDivScroll({
			autoScroll: "onstart",
			autoScrollDirection: "endlessloopright",
			autoScrollStep: 1,
	        autoScrollInterval: 30,
			scrollWrapper: "div.wrapper",
			scrollableArea: "div.area"
		});
		
	}
	
	
	
	
	$.switchBanners = function() {		
		if(!switchActive) {
			switchActive = true;
			$('.acties.banners .item').each( function(i,e) {
				if($(e).hasClass('is_active')) {				
					active = i;				
					next =  $('.acties.banners .item').eq(active).next('.item').length ? i+1 : 0;
				}		    		
			});	
				
			$('.acties.banners .item').eq(active).addClass('last_active');
			if($('.acties.items').length > 0) {
				$('.acties.items .item').removeClass('is_active');
				$('.acties.items .item').eq(next).addClass('is_active');
			}
			
			$('.acties.banners .item').eq(next).css({opacity: 0.0})
		        .addClass('is_active')
		        .animate({opacity: 1.0}, 750, function() {
		        	$('.acties.banners .item').eq(active).removeClass('is_active last_active');	  
		        	switchActive = false;
		    });	   	
		}
	}
	
	$(".thumbs .thumb").each( function(i) {
		if(i==0) {
			$(this).addClass('is_active');
		}
		$(this).click( function() {
			$(".thumbs .thumb").removeClass('is_active');
			$(this).addClass('active');			
			$(".images .image img").attr('src',$('img',this).attr('src').replace('/50/','/236/').replace('/50/','/266/'));
			$(".zoom img").attr('src',$('img',this).attr('src').replace('/50/','/2000/').replace('/50/','/2000/'));
		});
	});
	
	/* zoom */
	var afbeeldingVerhoudingX = 1;
	var afbeeldingVerhoudingY = 1;
	$('.zoom').hide();
	$('.images .image').mousemove(function(e) {		
		var x = ((e.pageX - $(this).offset().left) * -1 * afbeeldingVerhoudingX) + 270;
		var y = ((e.pageY - $(this).offset().top) * -1 * afbeeldingVerhoudingY) + 177;		
		$('.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();
	});		
	
	
});
