// **** PANEL **** //
// **** PANEL **** //
// **** PANEL **** //

function PMG_panel(p){
	this.disable = document.getElementById("window_immobilize");
	this.container = document.getElementById("full_screen_container");
	this.panel = document.getElementById(p + "_panel_container");
	// check for dropdown items to hide in IE //
	if(gBrowser.vendor == "IE"){
		this.hide_forms = document.getElementsByTagName('select');
	}
	
	this.openPanel = function(){
		// Center the panel on the screen //
		this.showHideForms();
		this.panel.style.display = "block";
		this.panel.style.left = ((document.body.clientWidth/2) + document.body.scrollLeft) - (this.panel.clientWidth/2) + "px";
		this._top = ((document.body.clientHeight/2) + document.body.scrollTop) - (this.panel.clientHeight/2);
		this._height = (document.body.scrollHeight > this.container.clientHeight)? document.body.scrollHeight : this.container.clientHeight;	
	
		if(this._top < 0){
			this._top = 25;
		}
		
		this.panel.style.top = this._top + "px";
		
		// Non IE browsers have a opacity in the css //	
		if(gBrowser.vendor == "IE"){
			this.disable.style.filter = "alpha(opacity=60)";
		}else{
			this.disable.style.opacity = "0.6";
		}
		
		//lDisable.innerHTML = "";
		this.disable.style.width = this.container.clientWidth + "px";
		this.disable.style.height = this._height + "px";
	
		this.disable.style.visibility = "visible";
		this.panel.style.visibility = "visible";
		
	}
	
		
	this.closePanel = function(){
		this.showHideForms(true);
		this.disable.style.visibility = "hidden";
		this.panel.style.visibility = "hidden";
		this.panel.style.display = "none";
		// Stop the Flash //
		if(p == "flash"){location.href = location.href}
	}
	
	// IE needs to hide all drop down forms //	
	this.showHideForms = function(p_show){
		if(this.hide_forms){
			var lShow = "hidden";
			if(p_show){
				lShow = "visible";
			}
	
			for(var prop in this.hide_forms){
				var lObj = this.hide_forms[prop];
				if(typeof(lObj) == "object"){
					if(typeof(lObj.style) == "object"){
						lObj.style.visibility = lShow;
					}
				}
			}
		}
	}

}

// Add the "Tell A Friend" panel to the onload function //
if(window.attachEvent){
	window.attachEvent("onload", PMG_appendOnload);
}else{
	window.addEventListener("load", PMG_appendOnload, false)
}
function PMG_appendOnload(){
	gPanel.objects.friend = new PMG_panel('tell_a_friend');
	if (typeof showTAF != "undefined" && showTAF){
		gPanel.objects.friend.openPanel();
	}
}


function PMG_writePanel(p){
	
	var w = '';
	w += '<div id="' + p.id + '_panel_container" class="panel_container">';
	w += '<div class="panel_top"></div>';
	w += '<div class="panel_div">';
	w += '<div class="panel_tile">';
	w += '<div class="panel_header"><a href="javascript:void(0);" onclick="gPanel.objects[\'' + p.id + '\'].closePanel(); return false;" onfocus="this.blur();" class="panel_close_link">Close X</a></div>';
	w += '<div class="panel_content_top">';
	w += '<div class="panel_content_header">' + p.title + '</div>';
	w += '<div class="panel_content">' + p.content + '</div>';	
	w += '</div>';
	w += '<div class="panel_content_footer"></div>';
	w += '<div class="panel_footer"></div>';
	w += '</div>';
	w += '</div>';
	w += '<div class="panel_bottom"></div>';
	w += '</div>';
	
	if(p.inline){
		return w;
	}else{
		document.write(w);
	}
	
	gPanel.objects[p.id] = new PMG_panel(p.id);
	return true;

}
