$(document).ready(function(){

	$("#slider1").slider({ min: 0000, max: 15000, slide: function(e,ui) {
			val = ui.value;
			fact = val / 14000;
			bgwidth = Math.round(165 * fact)-12;
			$('#sliderbg1').width(bgwidth);
			$('#ammount1').val((Math.round(val/100)*100));
		}
	});
	
	$("#slider2").slider({ min: 0, max: 3000, slide: function(e,ui) {
			val = ui.value;
			fact = val / 3000;
			bgwidth = Math.round(165 * fact)-3;
			$('#sliderbg2').width(bgwidth);
			$('#ammount2').val((Math.round(val/100)*100));
		}
	});
	
	$("#slider3").slider({ min: 0000, max: 15000, slide: function(e,ui) {
			val = ui.value;
			fact = val / 14000;
			bgwidth = Math.round(165 * fact)-12;
			$('#sliderbg3').width(bgwidth);
			$('#ammount3').val((Math.round(val/100)*100));
		}
	});
	
	$("#slider4").slider({ min: 0000, max: 15000, slide: function(e,ui) {
			val = ui.value;
			fact = val / 14000;
			bgwidth = Math.round(165 * fact)-12;
			$('#sliderbg4').width(bgwidth);
			$('#ammount4').val((Math.round(val/100)*100));
		}
	});
	
	$("#slider5").slider({ min: 0000, max: 15000, slide: function(e,ui) {
			val = ui.value;
			fact = val / 14000;
			bgwidth = Math.round(165 * fact)-12;
			$('#sliderbg5').width(bgwidth);
			$('#ammount5').val((Math.round(val/100)*100));
		}
	});
	
	$("#slider6").slider({ min: 0000, max: 15000, slide: function(e,ui) {
			val = ui.value;
			fact = val / 14000;
			bgwidth = Math.round(165 * fact)-12;
			$('#sliderbg6').width(bgwidth);
			$('#ammount6').val((Math.round(val/100)*100));
		}
	});
	
	$('.ammount').change(function(){
		val = Math.round($(this).val() / 100) * 100;
		$(this).next().slider( "moveTo", val) ;
	});
	
	$('#menu_home #fullmenu').hover(function(){
		$(this).addClass('over');
		$('.submenu').show();
	},function(){
		$('.submenu').hide();
		$(this).removeClass('over');
	});
	
	
	$('.berekenbutton, .berekenme').click(function(){
		$('#posme').show();
	});
	
	$('#berekend, #berekenpos .close, #berekenpos .again').click(function(){
		$('#posme').hide();
	});
	
	$('.tip').click(function(){
		$('.info', this).toggle();
	});
	
	$('#leenscan_mid .title').click(function(){
		if(!$(this).siblings('p').eq(0).is(':visible')){
			$('#leenscan_mid p:visible').slideUp();
			$(this).siblings('p').slideDown();
		
		}
	});
	
	$('.gaverder').click(function(){
		$(this).parent().slideUp();
		$(this).parents('li').next().children('p').slideDown();
	});
	
	$('.terug').click(function(){
		$(this).parent().slideUp();
		$(this).parents('li').prev().children('p').slideDown();
	});
	
	// limit between 0 and 482 px
	$('#leenscan_list input').click(function(){
		var  pos = $(this).val() + 'px';
	      $("#senorita").animate({ 
	        marginLeft: pos
	      }, 500 , function(){
	      
			min = 95;
			mid = 146;
			maxdist = 292-mid;
			
			current = parseInt($('#senorita').css('marginLeft')) - min;
			
			r = 153;
			g = 153;
			b = 153;
			
			ralt = 20;
			galt = 47;
			balt = -66;
			
			pcol = RGBtoHex(r, g, b);
			dcol =RGBtoHex(r, g, b);
			
			
			
			if(current > mid){
			
				offset = (current - mid) / maxdist
				r += ralt * offset;
				g += galt * offset;
				b += balt * offset;
			
				dcol =RGBtoHex(r, g, b);
			}else if(current < mid){
				
				offset = (mid - current) / maxdist
				r += ralt * offset;
				g += galt * offset;
				b += balt * offset;
			
				pcol =RGBtoHex(r, g, b);
			}
			
			
			$('#leenscan_persoonlijk').css({ backgroundColor: pcol });
			$('#leenscan_doorlopend').css({ backgroundColor: dcol });
		
		});
	
	
	});
	
	
});

// Convert Red/Green/Blue to Hex colour
function RGBtoHex(r, g, b){
	var r = new Array(r, g, b);
	var h = '0123456789ABCDEF';
	var f = 16;
	var c = '#';
 
	for(i in r){
		c = c + h.charAt((r[i] - r[i] % f) / f) + h.charAt(r[i] % f);
	}
 
	return c;
}
