function activateCustomBox(Obj, isUrl){	
	$('body').append('<div id="CustomBoxOverlay" class="hidden"></div>');
	$('body').append('<div id="CustomBoxPopup"><div id="CustomBoxContentPlace" class="loading"></div></div>');
	
	var windowObj		= $(window);
	var windowWidth 	= str2int(windowObj.width());
	var windowHeight 	= str2int(windowObj.height());
	
	var popupObj		= $('#CustomBoxPopup');
	var ovelayObj		= $('#CustomBoxOverlay');
	var popupHeight		= getCompleteHeight(popupObj);
	var popupWidth		= getCompleteWidth(popupObj);

	var popupLeft		= str2int((windowWidth-popupWidth)/2);
	var popupTop		= str2int((windowHeight-popupHeight)/2);
	
	ovelayObj.css({ 'opacity': '0.01', 'width': '100%', 'height': '100%'});
	popupObj.css({'opacity': '0.01', 'left': popupLeft+'px'});
	
	ovelayObj.show();
	ovelayObj.animate({'opacity': 0.8}, 500, 'linear', function(){
		ovelayObj.click(function(){
			removeCustomBox();
		});
	});	
	
	SetCustomBoxControlls(Obj, isUrl);
		
	popupObj.animate({'opacity': 1}, 500, 'linear', function(){
		setTimeout(function(){														  
			SetCustomBoxContent(Obj, false, isUrl);
		},200);
	});
}

function removeCustomBox(){
	$('#CustomBoxPopup').animate({ 'opacity': 0}, 200, 'linear', function(){
		$('#CustomBoxPopup').remove();	
	});
	$('#CustomBoxOverlay').animate({ 'opacity': 0}, 200, 'linear', function(){
		$('#CustomBoxOverlay').remove();	
	});

}

function SetCustomBoxControlls(Obj, isUrl){
	$('#CustomBoxPopup').append('<div class="controls hidden"></div>');
	$('#CustomBoxPopup .controls').append('<a href="#" class="close">X sluiten</a>');
	
	$('#CustomBoxPopup .controls .close').click(function(){
		removeCustomBox();
		return false;
	});
}

function SetCustomBoxContent(Obj, reloadBox, isUrl){
	var ajaxUrl = (isUrl)? Obj : Obj.attr('href');
	
	$.ajax({
		url: ajaxUrl+(reloadBox === true? '?'+makeAjaxGetStr() : ''),
		cache: false,
		success: function(result){
			var parentObj 	= $('#CustomBoxContentPlace');
			
			parentObj.append(result);
			
			var childObj		= parentObj.children('*:first');
			var childHeight		= getCompleteHeight(childObj);
			var childWidth		= childObj.width();
			var parentWidth		= getCompleteWidth(parentObj);
			var pOffset 		= parentObj.offset();
			
			var newLeft = str2int((pOffset.left-((childWidth-parentWidth)/2)));
			var animate = (reloadBox === true)? {'height': childHeight+'px'} : {'left' : newLeft +'px', 'width': childWidth+'px', 'height': childHeight+'px'};
		
			$('#CustomBoxPopup').animate(animate , 200, 'linear',
			function(){
				parentObj.css({'width' : 800});
				$(".pngFix").pngfix();				
				childObj.removeClass('hidden');
				parentObj.removeClass('loading');
				$('.prev, .next, .open_contact').click(function(){					
					parentObj.empty();
					childObj.addClass('hidden');
					parentObj.addClass('loading');
					SetCustomBoxContent($(this), true);
					return false;
				});
				
				$('a.btn_niet_ok').click(function(){
					var $this = $(this);
					var DataString = 'animal='+$(this).attr('rel');
					var ajaxUrl = BaseURL+'/js/notok.php';
					
					$.ajax({
						type: 'POST',
						data: DataString,
						url: ajaxUrl,
						cache: false,
						complete: function(result, status){
							$this.hide();
							$this.parent().children('p').show();
							return false;
						}
					});

					return false;
				});

				$('a.thumb').click(function(){
					$('div.photo').css('background-image', 'url('+$(this).attr('href')+')');
					return false;
				});	
			});
		}
	});
}
