function d4initColorbox(nodeNum, maxWidth, maxHeight) {
	if(/Android|iPhone|iPad/.test(navigator.userAgent)) {
      if(!window.D4COLORBOXFIXED) {
        $(document.body).prepend('<style type="text/css">#cboxNext, #cboxPrevious { visibility: hidden; width: 0px; } #cboxCurrent {left: 5px !important} </style>');
		window.D4COLORBOXFIXED=true;
	  }
		// see https://github.com/jackmoore/colorbox/issues/107
		// disable left/right buttons...
	}
	$("a[rel='gallery-" + nodeNum + "']").colorbox({
		html: function() {
			var content = $('<table class="d4cbox"><caption align="bottom"></caption><tr><td><img/></td></tr></table>');
			var data;
			if(this.className.match(/(\{.*\})/)) {
				data = $.parseJSON(RegExp.$1);
			}
			
			var resize = function(dim, max) {
				if(dim.w > max.w || dim.h > max.h) {
					var ratio = Math.min(max.w/dim.w, max.h/dim.h);
					dim.w = Math.round(ratio * dim.w);
					dim.h = Math.round(ratio * dim.h);
				}
				return dim;
			};
			
			data = resize(data, { w: maxWidth, h: maxHeight} );
			data = resize(data, { w: $(window).width() - 50, h: $(window).height() - 100 });
			
			$(content).find('img')
				.load(function() { window.setTimeout(function() { $.fn.colorbox.resize }, 1000) } )
				.attr('src', this.href)
				.css({width: data.w, height: data.h})
			;
			$(content).find('caption').html(data.htmlCaption);
			return content;
		},
		current: '{current}/{total}',
		title: "&nbsp;",
		opacity: .7,
		onOpen: function(){
	        $('embed:visible').css('visibility','hidden').addClass('colorbox-hidden-fix');
		},
		onClosed: function(){
	        $('.colorbox-hidden-fix').css('visibility','visible');
		},
		loop: false
	});
}


