(function($){  
	//Attach this new method to jQuery  
	$.fn.extend({
		ModalWindow_2: function(objStyle, loadingFrom/*for ajax*/,loadingImgUrl) {
			var $window = $(window);
			var $document = $(document);
			var $body = $("body");
			
			var maskHeight = 0;// = $document.height();
			var maskWidth = 0;// = $window.width();
			var mask = $("<div></div>");
			var closebtn = $("<div></div>");
			
			var popupWindow = $("<div class=\"popup_promotion\"></div>");
			
			function setupMask(){
				maskHeight = $document.height();
				maskWidth = $window.width();
			
				mask.css({
					"width": (maskWidth + "px"),
					"height": (maskHeight + "px"),
					"position": "absolute",
					"top": "0px",
					"left": "0px",
					"background-color": "#000000",
					zIndex: 9999
				});
			}
			
			function setupPopupWindow(){
				var relWidth = parseInt(objStyle["width"]);
				var relHeight = parseInt(objStyle["height"]);
			
				var scrolltop = $document.scrollTop();
				var centHorPos = maskWidth/2 - relWidth/2;
				var centVerPos = $window.height()/2 - relHeight/2 + scrolltop;
				var styleB = {
					"top": (centVerPos + "px"),
					"left": (centHorPos + "px"),
					"position": "absolute",
					"z-index": "10000"
					//"padding": "10px",
					//"background-color": "#FFF"
				};
				
				closebtn.css({
					//"width": (10 + "px"),
					//"height": (10 + "px"),
					"top": "5px",
					"right": "5px",
					//"background-color": "#0099FF",
					"position": "absolute",
					"z-index": "20001"
				});
				
				var fsetting = $.extend(objStyle, styleB);
				popupWindow.css(fsetting);
			}
			
			function setupAll(){
				setupMask();
				setupPopupWindow();
			}
			$document.scroll(setupAll);
			$window.resize(setupAll);
			
			mask.hide();
			popupWindow.hide();
			
			$body.append(mask);
			$body.append(popupWindow);
			
			mask.click(function(){
				mask.hide();
				popupWindow.hide();
			});
			
			function setupCloseBtn(){
				
				closebtn.addClass("close_popup_btn");
			
				closebtn.click(function(){
					mask.hide("slow");
					popupWindow.hide("slow");
				});
				
				closebtn.mouseenter(function(){
					closebtn.addClass("close_popup_btn_hover");
					closebtn.removeClass("close_popup_btn");
				});
				closebtn.mouseleave(function(){
					closebtn.removeClass("close_popup_btn_hover");
					closebtn.addClass("close_popup_btn");
				});
				popupWindow.append(closebtn);
				
			}
			
			//Iterate over the current set of matched elements  
			return this.each(function() {
				var $object = $(this);
				
				$object.click(function(event){
					event.preventDefault();
					
					setupAll();
					
					var scrolltop = $document.scrollTop();
					mask.show();
					mask.fadeIn(1000);
					mask.fadeTo("slow",0.8);
					
					popupWindow.css({
						"opacity": "0",
						"display": "block"
					});
					mask.css({
						"background-image": ("url(" + loadingImgUrl + ")"),
						"background-repeat": "no-repeat",
						"background-position": ("50% " + (scrolltop + 100) + "px")
					});
					
					$.ajax({
						url: loadingFrom,
						success: function(jxcontent){
							var relWidth = parseInt(objStyle["width"]);
							var relHeight = parseInt(objStyle["height"]);
							mask.css({
								"background-image": "none"
							});
							popupWindow.animate({"opacity": "1"});
							popupWindow.html(jxcontent);
							setupCloseBtn();
							$(document).scroll(function(event){
								//document.title += "x"
								//alert(var_dump(event));
							});
							
							//popupWindow.find(".scroller").height(relHeight).width(relWidth);
							popupWindow.find(".scroller").jScrollPane({showArrows:true});
						}
					});
				});
			});
		}
	});  
	//pass jQuery to the function,   
	//So that we will able to use any valid Javascript variable name   
	//to replace "$" SIGN. But, we'll stick to $ (I like dollar sign: ) )         
})(jQuery);

function var_dump(obj) {
   if(typeof obj == "object") {
      return "Type: "+typeof(obj)+((obj.constructor) ? "\nConstructor: "+obj.constructor : "")+"\nValue: " + obj;
   } else {
      return "Type: "+typeof(obj)+"\nValue: "+obj;
   }
}//end function var_dump

