

function expand_ma() {
	
	
	if(!Q || !$("ma_expand")) return;
	
	if (document.getElementById("dialog-lightbox")) {
		document.getElementById("dialog-lightbox").style.display="block";
	}
	else {		
		var lightbox = document.createElement("div");
		lightbox.setAttribute("id", "dialog-lightbox");
		lightbox.style.position = "absolute";
		lightbox.style.top = "0px";
		lightbox.style.left = "0px";
		lightbox.style.width = "100%";
		lightbox.style.height = "100%";
		lightbox.style.zIndex = 50;
		lightbox.style.backgroundColor = "#888888";
		lightbox.style.opacity="0.50";
		lightbox.style.filter="alpha(opacity=50)";
		document.body.appendChild(lightbox);
		
		
	}
	
	//set height of lightbox for IE
	var browser=navigator.appName;
	var b_version=navigator.appVersion;
	//var version=parseFloat(b_version);
	
	if ((browser=="Microsoft Internet Explorer")) {
		b_version_short = b_version.substring(b_version.indexOf("MSIE ")+4);
		b_version_short = b_version_short.substring(0,b_version_short.indexOf(";"));
		var version=parseFloat(b_version_short);
		if (version<7) {
			var window_height = document.documentElement.clientHeight;
			$('dialog-lightbox').style.height=window_height;
		}
	}
	
	var query = (($("q") && $("q").value != "") ? $("q").value : "");
	
	if (document.getElementById("dialog-window")) {
		if (Q.ma_full) {
			maRenderFull(Q.ma_full);
		}
		else {
			$("dialog-window").innerHTML = "<i>loading...</i>";
			callOut("maRenderFull(j)",server_to_use+"/index.php?action=ajax&rs=wfGetArticleJSON&rsargs%5B%5D=Mini:"+encodeURIComponent(Q.q)+"&rsargs%5B%5D=maRenderFull&rsargs%5B%5D=0");
		}
		$("dialog-window").style.display="block";
	}
	else {		
		//var query = $("q").value;
		//bg_selector_query = query;
		var window_width = 0;
		var dialog_margin = 0;
		var related_box = document.createElement("div");
		related_box.setAttribute("id", "dialog-window");
		related_box.innerHTML = "<i>loading...</i>";
		callOut("maRenderFull(j)",server_to_use+"/index.php?action=ajax&rs=wfGetArticleJSON&rsargs%5B%5D=Mini:"+encodeURIComponent(Q.q)+"&rsargs%5B%5D=maRenderFull&rsargs%5B%5D=0");
		
		// something to make it change
		
		if ( typeof( window.innerWidth ) == 'number' ) {
		    //Non-IE
		    window_width = window.innerWidth;
		} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		    //IE 6+ in 'standards compliant mode'
		    window_width = document.documentElement.clientWidth;
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		    //IE 4 compatible
		    window_width = document.body.clientWidth;
		}
		dialog_margin = (window_width - 500) / 2;
		related_box.style.left = dialog_margin + "px";
		related_box.style.position = "absolute";
		related_box.style.top = "50px";
		related_box.style.width = "500px";
		related_box.style.textAlign = "left";
		related_box.style.zIndex = 100;
		document.body.appendChild(related_box);
		
	}
	
	document.body.style.overflow="hidden";
	scroll(0,0);
	
}

function maRenderFull(j) {
	Q.ma_full = j;
	var return_str = "";
	return_str += "<div class=\"mini-article-full\">";
	return_str += "<div class=\"dialog-actions\">";
			return_str += "<a href=\"javascript:hide_ma_box(0);\">"+gettext("Close")+"</a>";
		return_str += "</div>";
	return_str += "<h2>"+gettext("Mini Article")+": " + j.title + "</h2>";	
	return_str += "<div id=\"ma-full-container\">";
		return_str += j.html;
	return_str += "</div>";
	return_str += "<div id=\"edit-links\">";
	return_str += "<input id=\"ma_edit_btn\" type=\"button\" value=\""+gettext("Edit", {id:'ma_edit_btn', param:'value'} )+"\" onclick=\"window.location='" + j.editurl + "'\"/>  ";
		return_str += "<input id=\"ma_full_btn\" type=\"button\" value=\""+gettext("Full Article", {id:'ma_full_btn', param:'value'})+"\" onclick=\"window.location='" + j.url + "'\"/>";
		//return_str += "<a href=\"javascript:hide_ma_box(0);\">"+gettext("Close")+"</a>";
	return_str += "</div>";
	$("dialog-window").innerHTML =  return_str;
	
	if (!Q.ma_full.offset_height) {
		var offset_height = $('ma-full-container').offsetHeight;
	}
	else offset_height = Q.ma_full.offset_height;
	if (offset_height>=350) {
		offset_height = 350;
		$('ma-full-container').style.overflowY = "scroll";
		$('ma-full-container').style.overflowX = "hidden";
	}
	Q.ma_full.offset_height = offset_height
	
	$('ma-full-container').style.height = offset_height + "px";
}

function hide_ma_box(save) {
	
	if (save) {
	
	}
	
	if (document.getElementById("dialog-window")) document.getElementById("dialog-window").style.display = "none";
	if (document.getElementById("dialog-lightbox")) document.getElementById("dialog-lightbox").style.display = "none";
	document.body.style.overflow="auto";
	
	
}
