var resizeTimer = null;

function initslideshow () {
	$("#thumbnails ul li img").each(
		function (i) {
			$(this).css('cursor','pointer');
			$(this).mouseover(function () { $(this).fadeTo("fast", 0.50); });
			$(this).mouseout(function () { $(this).fadeTo("slow", 1); });
			$(this).click(function () { var newscr = $(this).attr('id'); $('img#big-image').attr('src',newscr); });
	});
}

$(document).ready(function(){
	initslideshow();

	DD_roundies.addRule('.thumb', '1px', true);
	DD_roundies.addRule('button, .btn', '3px', true);
	DD_roundies.addRule('#content-inner-wrapper', '10px', true);
	DD_roundies.addRule("#logo, .error, .feedback");
	DD_roundies.addRule("#balloon","5px", true);
	
	$("#ulwrapper").jCarouselLite({
		btnNext: ".next",
		btnPrev: ".prev",
		circular: false,
		scroll: 2,
		mouseWheel: true,
		easing: 'easeout',
        visible: 6
	 });
	
	$("a.zoom").lightbox();
	$("a.thumb").lightbox();
	
	$('#sfeerbeelden div').cycle({ 
	    fx:    'fade', 
	    speed:  300,
		timeout: 3500,
		random: 1
	 });
	 
	 $('.sfeerbeeld_link a').cycle({ 
	    fx:    'fade', 
	    speed:  300,
		timeout: 3500,
		random: 1
	 });
	 
	 if($("#balloon")){
	 	$("#balloon #closeme").click(function() { $("#balloon").css("display", "none"); });
	 	if($.browser.msie){
	 		$("#balloon #arrow").css("top", "76px");
	 	}
	 }
	 	 
	 $(window).resize(function(){
		if (resizeTimer) clearTimeout(resizeTimer);
	    resizeTimer = setTimeout(doResize, 100);	
	});
	
	$("a.toevoegen").each(
		function (i) {
			$(this).click(function(event){
				event.preventDefault();
				
				var popup = $(this).next();
				popup.css('display', 'block');
				
				var produrl = popup.find('input.productURL').val();	
				var anc = popup.find('a');
				
				$(anc).click(function(event){
					event.preventDefault();
					var txt = popup.find('input.txt');
					var aant = txt.val();
					
					if(isNaN(aant)){
						$(txt).attr('value', '');
						return;
					}
					$(popup).load(produrl + '/' + aant);
					
					//nieuw icoontje
					var verwijder_anc = popup.prev();
					var icon = verwijder_anc.find('img').attr('src').replace('mandje.png', 'mandje_verwijder.png');
					var url = $(verwijder_anc).attr('href').replace('toevoegen', 'verwijderen');
					$(verwijder_anc.find('img')).attr('src', icon);
					verwijder_anc.click(function(){ location.href = url });
					
				});
				
			});
		}
	);
	
	doResize();
});

function doResize()
{
     try
     {
     	x = screen.availLeft; // ns only
    	y = screen.availTop;
	    window.moveTo(x,y);
     	window.resizeTo(screen.availWidth,screen.availHeight);
     } catch(e) {
     	if (resizeTimer) clearTimeout(resizeTimer);
	    resizeTimer = setTimeout(doResize, 100);
     }
}