
var roundedcorners = function(_el){
	// rounded corners (rc)
	var el = _el||'.rc';
	$(el).each(function(){
		var marginB = parseInt($(this).css('margin-bottom'));
		if(!marginB) marginB = 0;
		var marginL = parseInt($(this).css('margin-left'));
		if(!marginL) marginL = 0;
		var height = parseInt($(this).outerHeight())+marginB;
		var width = parseInt($(this).outerWidth())+marginL;

		var cornercontainer = $('<div></div>');
			var lt = $('<div class="lt">&nbsp;</div>').css({top: (-height-1)+'px', left:-1+'px'});
			var rt = $('<div class="rt">&nbsp;</div>').css({top: (-height-1)+'px', left: (width-4)+'px'});
			var lb = $('<div class="lb">&nbsp;</div>').css({top: (-4-marginB)+'px', left:-1+'px'});
			var rb = $('<div class="rb">&nbsp;</div>').css({top: (-4-marginB)+'px', left: (width-4)+'px'});
		
		
		$(lt).appendTo(cornercontainer);
		$(rt).appendTo(cornercontainer);
		$(lb).appendTo(cornercontainer);
		$(rb).appendTo(cornercontainer);
		
		$(cornercontainer).attr('class', 'corner-container ').insertAfter($(this));
	});
	
	
	//$('.mp-block img').jacg({'radius': '5px'});
	//$('.imglist2 img').jacg({'radius': '5px'});
}


function empty_recursive(el){
	$(el).val($(el).val().substring(0, $(el).val().length-1));
	if($(el).val() != ''){
		setTimeout(function(){
			empty_recursive($(el));
		}, 2);
	}
}
function refill_recursive(el){
	$(el).val($(el).attr('defVal').substring(0, $(el).val().length+1));
	if($(el).val() != $(el).attr('defVal')){
		setTimeout(function(){
			refill_recursive($(el));
		}, 2);
	}
}


$(function(){
	new droplist();
	
	$('.droplist').change(function(){
		window.location = base+($(this).attr('val')+'/'+(window.location+"").replace(base, '').replace(/^(\/?(nl|en|de))/, '')).replace(/\/\//g, '/');
	});
	
	$('#menu>li').css('position', 'relative');
	// ie fix
	$('#menu>li .msubmenu').each(function(){ $(this).show().css('width', $(this).width()+'px').hide(); });
	
	
	$('#menu>li').mouseenter(function(){
		$(this).find('.msubmenu').stop(false, true).slideDown(100);
		$(this).addClass('active');
	});
	$('#menu>li').mouseleave(function(){
		var e = $(this);
		if($(this).find('.msubmenu').size() == 0) $(e).removeClass('active');
		$(this).find('.msubmenu').stop(false, true).slideUp(100, function(){
			$(e).removeClass('active');
		});
	});
	$('#menu>li .msubmenu ul li a').mouseenter(function(){
		$(this).addClass('active');
	});
	$('#menu>li .msubmenu ul li a').mouseleave(function(){
		$(this).removeClass('active');
	});

	
	$('input[type=text]').each(function(){
		if($(this).val().length > 0){
			$(this).attr('defVal', $(this).val());
			$(this).focus(function(){
				if($(this).val() == $(this).attr('defVal')){
					empty_recursive($(this));
				}
			});
			$(this).blur(function(){
				if($(this).val() == ''){
					refill_recursive($(this));
				}
			});
		}
	});

	$('.sthumb').each(function(){
		var src = $(this).attr('src');
		$(this).wrap('<div class="imgparent" style="background-repeat:no-repeat;background-position:1px 1px;background-image:url(\''+src+'\');display:block;">');
		$(this).attr('src', './images/sthumb.corners.png');
	});
	
	
	
	$("a.fancylink").fancybox();
	$("a.fancyvidiconlink").fancybox({'width': 960, 'height': 304});
	roundedcorners($('.imglist2'));
});
