var GlobalModal= {
	init: function(w,h){
		
		this.destroy();
	
		this.windowSizeW = w;
		this.windowSizeH = h;
	
		this.classOverlay= 'j_modal_charts_overlay';
		this.classWrapper= 'j_modal_charts';
		this.classClose= 'j_close_window';
		
		if(!w){
			this.windowSizeW= 800;
		}
		if(!h){
			this.windowSizeH= 400;
		}
		
		this.windowP=30;
		
		this.browserSizeW=jQuery(window).width();
		this.browserSizeH=jQuery(window).height();
		
		//alert(this.browserSizeW+'x'+this.browserSizeH);
		if(this.browserSizeH>480){
			this.position = 'fixed';
			this.TopPosition=(  (this.browserSizeH/2) - (this.windowSizeH/2)-40  );
		} else {
			this.position = 'absolute';
			this.TopPosition=30;
		}
		this.LeftPosition=(  (this.browserSizeW/2) - (this.windowSizeW/2)-this.windowP  );
		
		this.generateWindow();
		
		jQuery(".j_modal_charts, .j_modal_charts_overlay").mouseover(function(){
			Applet.hidden=1;
		});		
		jQuery("#people-list-close").remove();
		
	},
	generateWindow: function(){
		
		var html='';
		
		html+='<div style="display:none;background:black; position:fixed; z-index:6000; top:0; left:0; width:100%; height:100%;" class="'+this.classOverlay+'"></div>';
		html+='<div class="'+this.classWrapper+'" style="z-index:7000;padding:'+this.windowP+'px; -moz-border-radius:10px; display:none; background:white; position:'+this.position+'; top:'+this.TopPosition+'px; left:'+this.LeftPosition+'px; width:'+this.windowSizeW+'px; height:'+this.windowSizeH+'px">';
			html+='<img style="position:absolute; right:-20px; top:-20px; cursor:pointer" onclick="GlobalModal.hideWindow();" src="/lib/jquery/close_x.png">';
			html+='<div class="container">';
			html+='</div>';
		html+='</div>';
		
		jQuery("body").append(html);
		jQuery('.'+this.classOverlay).css("opacity","0.7");
		
		jQuery('.'+this.classOverlay).bind("click", function(){
			GlobalModal.hideWindow();
		});
	},
	
	showWindow: function(){
		
		jQuery(".j_modal_charts").css("background","white");
		
		if(GlobalModal.nobg){
			jQuery(".j_modal_charts").css("background","transparent");
		}
	
		jQuery('.'+this.classOverlay).fadeIn(100);
		jQuery('.'+this.classWrapper).fadeIn(100);
		
		if(typeof this.onShow =='function'){
			this.onShow();
		}		
		
		Applet.hidden=1;
		if(this.position=='absolute'){
			document.location.href="#";
		}
		
	},

	hideWindow: function(){
	
		jQuery('.'+this.classOverlay).fadeOut(100);
		jQuery('.'+this.classWrapper).fadeOut(100);
		
		Applet.hidden=0;
		
		jQuery(".datepicker").hide();
		
		if(typeof this.onHide =='function'){
			this.onHide();
		}
		
		GlobalModal.nobg=0;
		
		jQuery(".j_modal_charts").css("background","white");
		
	},	
	
	cleanHtml: function(){
		jQuery(".j_modal_charts").css("width",this.windowSizeW);
		jQuery("."+this.classWrapper+' .container').text("");
	},
	
	appendHtml: function(html){
		GlobalModal.cleanHtml();
		jQuery("."+this.classWrapper+' .container').html(html);
	},
	
	destroy: function(){
		if(jQuery(".j_modal_charts").length){
			jQuery(".j_modal_charts, .j_modal_charts_overlay").remove();
		}
	}
	
	
}

jQuery(document).ready(function(){
	GlobalModal.init();
});
