function openLightbox(lb_URL, lb_width, lb_height, lb_top) {

	if(lb_top == null) {
		lb_top = 100;
	}
	
	/* check for IE6 */
	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
		var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
	}
	
	var lb_left = ($('body').width() / 2) - (lb_width / 2) - 10;
	var lb_middle = ($('body').width() / 2);
	
	if (ieversion<7) { /* use different values for IE6 */
		lb_left = lb_left - 5;
		lb_top = lb_top - 5;
	}
	
	$('body').append('<div id="lb-background"></div>'); /* <div class="iframecontent lb-resize" style="top: '+ (lb_top - 2) +'px; left: '+(lb_left - 2)+'px; width: '+lb_width+'px; height:'+lb_height+'px;"></div> */
	$('body').append('<div class="iframewrapper lb-resize" style="padding:0px; margin:0px; top: '+lb_top+'px; left: '+lb_left+'px; height: '+lb_height+'px; width: '+lb_width+'px;"><a href="#" class="iconbutton b-close" id="close"><img height="12" width="12" title="" alt="" src="typo3conf/ext/nidag_template/resource/public/image/extensions/nidag_product_management/button_close.gif"/></a><div id="lb_clear" style="clear:both" /><iframe id="lb-content" src="'+lb_URL+'" width="'+lb_width+'" height="'+lb_height+'"></iframe></div>');

	$('#lb-background').fadeTo(400, 0.5, function(){
		$('.iframewrapper').show();
		$('div.lb-resize').show();
	});

	$('.iframewrapper a.b-close').click(closeLightbox);

	return false;
}

/* Close Lightbox */
function closeLightbox() {

	$('#lb_clear').remove();

	$('.iframewrapper').fadeOut(400, function(){
		$(this).remove();
	})
	
	$('.iframecontent').fadeOut(400, function(){
		$(this).remove();
	})
	
	$('#lb-background').fadeOut(400, function(){
		$(this).remove();
	});

	return false;
}




$(document).ready(function()  {
	$('.lightbox').click( function() {
			
		var lb_element = '#'+$(this).attr('href');
		var size = $(this).attr('coords').split(',');
		
		lb_width   = size[0];
		lb_height  = size[1];
		if(size.length > 2) {
			lb_top = size[2];
		} else {
			lb_top = 100;
		}
		
		openLightboxInline(lb_element, lb_width, lb_height, lb_top);

		return false;
	});
	
});


/* This is for non-iFrames ;-) */
function openLightboxInline(lb_element, lb_width, lb_height, lb_top) {
	
	
	/* check for IE6 */
	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
		var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
	}
	
	var lb_left = ($('body').width() / 2) - (lb_width / 2) - 10;
	if (ieversion<7) { /* use different values for IE6 */
		lb_left = 0;
		lb_top = lb_top - 5;
		lb_width = parseInt(lb_width);
	}
	var lb_middle = ($('body').width() / 2);
	if(!$('#closeInline').length > 0) {
		
		$(lb_element).before('<div id="lb-background" style="height: ' + $('body').height() + 'px; width: ' + $('body').width() + 'px;"></div>');
/*		$('body').append('<div id="lb-background" style="height: '+$('body').height()+'px;"></div>'); */
		$(lb_element).wrap('<div class="inlinewrapper lb-resize" style="top: '+lb_top+'px; left: '+lb_left+'px; '+(lb_height = lb_height ? 'height: '+lb_height+'px;' : '')+' width: '+lb_width+'px;"></div>');
		$(lb_element+':first-child').prepend('<a href="'+lb_element+'" class="iconbutton b-close" id="closeInline"><img height="12" width="12" title="" alt="" src="typo3conf/ext/nidag_template/resource/public/image/extensions/nidag_product_management/button_close.gif" /></a>');
		$('a#closeInline').click(closeLightboxInline);
		
	}
		
	$('.inlinewrapper').fadeIn(400);
	$(lb_element).fadeIn(400);
	$('a#closeInline').show();
	$('div#lb-background').show();
	$('div#lb-background').fadeTo(400, 0.5);
		
	return false;
}

function closeLightboxInline() {

	var lb_element = $(this).attr('href');
	
	$(lb_element).fadeOut(400);
	$('#lb-background').fadeOut(400);
	$('#closeInline').fadeOut(400);
	$('.inlinewrapper').fadeOut(400);

	return false;
}