// JavaScript Document



var popMsg = {	
	Init:
		function(_url) {
			if (!_url) { alert("popMsg requires an ajax/json URL!"); return false; } 
			this.url = _url;
			this._class = "popMsg";
			
			this.LoadStyle("http://op.chamberlandhosting.com/js/jquery/plugin/popMsg/default.css");			
	},
	
	Show: 		
		function(_mode) {
			if (!this.url) { alert("popMsg requires an ajax/json URL!"); return false; } 
			var _url = this.url;

			if (_url.toString().indexOf("?") > -1) {
				_url += "&mode="+ _mode;
			} else {
				_url += "?mode="+ _mode;
			}
//cDebug("URL: "+ _url);						
			$.get(_url, 
				function(_xml) {
					
					var _class = popMsg._class;
					$("#"+ _class).empty().remove();				

					var _width = "";
					var _msg = "";
					
					$(_xml).find("item").each(
						function(i) {
							_width = $(this).find("width").text();
							_msg = $(this).find("info").text();
						});
					
					_top = $("#header").height();
					if (!_top) { _top = 100; }
					else { _top += 100; }
					
					var _html = ''+
						'<div id="'+ _class +'" align="center" '+
						'style="position:absolute; width:100%; height:'+ $(document).height() +'px; top:0px; left:0px; z-index: 10000;"'+
						'class="popMsg-overlay">'+
							
							'<div style="display:inline-block; margin:0; margin-top:'+ _top +'px; padding:10px;" '+
							'class="popMsg-shadow ui-corner-all">'+		
														
								'<div align="left" class="ui-widget ui-widget-content ui-corner-all" style="padding:10px;">'+
									'<div align="right">'+
										'<span id="'+ _class +'Close" class="ui-icon ui-icon-circle-close pointer"></span>'+
									'</div>'+
										_msg								
								'</div>'+								

							'</div>'+		

						'</div>';					

					if (_msg) {
						$("body").append(_html);
						$("#"+ _class +"Close").live("click",
						function() {
							$("#"+ popMsg._class).empty().remove();
						});
						
						$(window).resize(function() {
							popMsg.Show(_mode);
						});
						
					} 	

				}, 'xml');
	},
	
	
	LoadStyle:	function (_path) {
					var _ok = 1;
					var _head = document.getElementsByTagName('head').item(0);
					var _script = _head.getElementsByTagName('link');
					for (var i=0; i < _script.length; i++) {
						var _src = _script[i].src;
						if (_src) {
							if (_src.toString().indexOf(_path) > -1) {
								_ok = 0;
							}
						}			
					}	
					if (_ok) {
						var Node = document.createElement('link');
						Node.type = 'text/css';
						Node.rel = 'stylesheet';
						Node.href = _path;
						Node.media = 'screen';
						_head.appendChild(Node);
					}
					return true;
	}
}





















