function Lightbox(text){
	var $bod = $("body");
	//var $lb = $("#lightbox2");
	debug.log("-- overlay:");
//	debug.log(text);
	if(text !== false){
		var st = $(window).scrollTop();
		var wh = $(window).height();
		var ww = $(window).width();
		
		$oldLB = $("#mdlDialog");
		$oldOL = $("#mdlOverlay");
		
		if($oldLB.length > 0 || $oldOL.length > 0){
			$oldLB.remove();
			$oldOL.remove();
		}
		
		$bod
			.height(wh)
			.css('overflow','hidden')
			.append("<div id='mdlOverlay'></div><div id='mdlDialog'>"+text+"</div>");
			
		var $ol = $("#mdlOverlay");
		var $lb = $("#mdlDialog");
		
		var ah = $lb.height();
		var aw = $lb.width();
		var nh = (wh/2) - (ah/2) + st;
		var nw = (ww/2) - (aw/2);	
		
		//debug.log($("#mdlDialog"));
		//debug.log($("#mdlOverlay"));
		
		$("#lbOK").click(function(){
			Lightbox(false);
		});
		
		$("#mdlOverlay").css({'top':st}).fadeTo(100, 0.8, function(){
			$lb.css({'top':nh, 'left':nw}).fadeIn("slow");
		});
		
		
	}else{
		var $ol = $("#mdlOverlay");
		var $lb = $("#mdlDialog");
		
		$lb.fadeOut(200, function(){
			$(this).html("&nbsp;").remove();
			$ol.fadeOut(100).remove();
		});
		
		$bod.css('overflow','auto');
	}
}

function Add2Cart(item,qty){
	//var qty = $("#qty"+item).val();

	$.get("/include/AJAX/add2cart.php", {"itm": item, "qty": qty}, function(data){
			Lightbox(data);
		});
}

function Add2Cartv2(item,desc){
	var qty = $("#qty"+item).val();

	$.get("/include/AJAX/add2cart.php", {"itm": item, "qty": qty, "desc": desc}, function(data){
			Lightbox(data);
	});
}

// ************************************
// Loading overlay
jQuery.fn.LoadMsg = function(remove){
	if(remove === undefined){var remove = false;}
	var $this = $(this);
	var $Lwin = $this.children(".loading");

	if(remove){
		if($Lwin.length > 0){return this;}
		$this.append("<div class='loading'>&nbsp;</div>");
		var $loadWin = $this.children(".loading");
		$loadWin
			.unbind()
			.fadeTo("fast",0.4);
	}else{
		$Lwin.fadeOut("fast",function(){$Lwin.remove();});
	}
	return this;
};

$(document).ready(function(){

});
