
var timer_files_count = null;
var hide_switch = true;

function DropClear()
{
	if($("#drpDiv").length > 0) { document.body.removeChild($("#drpDiv")[0]); }
	if($("#arwDiv").length > 0) { document.body.removeChild($("#arwDiv")[0]); }
	hide_switch = true;
}

function UploaderClose()
{
	if($("#drpDiv2").length > 0) { document.body.removeChild($("#drpDiv2")[0]); }
	if($("#arwDiv2").length > 0) { document.body.removeChild($("#arwDiv2")[0]); }
}

var hide_loop = 0;
var timer_hide = null;
function DropClearAction()
{
	if(hide_switch == false) return;
	if(hide_loop < 10) { hide_loop++; return; }
	hide_loop = 0;
	DropClear();
	clearInterval(timer_hide);
}

function DropIconClear()
{
	hide_loop = 0;
	if(hide_switch == false) return;
	timer_hide = setInterval("DropClearAction()", 100);
}

function MarkAction(id,prj,atype,v1,v2)
{
	var cmd = "1";
	if(v1 == v2) cmd = "-1";
	$.post("/Utility/MarksCreate.aspx", { cmd: cmd, id : id , prj : prj, type : atype, value : v1 }, function(result) {
		$("#blog_editable_0").html(result);
		if($("#marks_of_" + id).length > 0) {
			$("#marks_of_" + id).html(result);
		}
		DropClear();
	});
}

function MarkAction_Mobile(id,prj,atype,v1,v2)
{
	var cmd = "1";
	if(v1 == v2) cmd = "-1";
	$.post("/Utility/MarksCreate.aspx", { cmd: cmd, id : id , prj : prj, type : atype, value : v1 }, function(result) {
		//$("#blog_editable_0").html(result);
		//if($("#marks_of_" + id).length > 0) {
		//	$("#marks_of_" + id).html(result);
		//}
		parent.window.location.reload();
	});
}

function DropAjax(ref,obj,w,h,aurl,mode,pos)
{
	$.ajax({
		url: aurl,
		type : 'GET',
		error : function(XMLHttpRequest, textStatus, errorThrown) {
			alert(aurl + " " + XMLHttpRequest.status + " " + XMLHttpRequest.readyState + " " + textStatus);
        },
		success : function(result){
			if(result.length > 1) {
				DropFloat(ref,obj,w,h,result,"ajax",pos);
			}
		}
	});
}

function DropFloat(ref,obj,w,h,url,mode,pos)
{
	DropClear();
	UploaderClose();

	var objThis = obj;
	var pos1 = AbsolutePosition(obj);
	var pos2 = AbsolutePosition(ref);
	var hy = obj.offsetHeight + 2;
	h += 15;

	var pre = "";
	if(url.toLowerCase().indexOf("/imageone.aspx") > 0) pre = "2";

	var arObj = document.createElement("div");
	arObj.id = "arwDiv" + pre;
	arObj.style.cssText = "position:absolute;left:0px;top:0px;width:13px;height:6px;text-align:center;z-index:2002;";
	arObj.style.left = (pos1.x + parseInt(obj.offsetWidth/2,10) - 5) + "px";
	arObj.style.top = (pos1.y + hy) + "px";
	arObj.innerHTML = "<img src=\"/images/blog/drop-arw.gif\">"
	document.body.appendChild(arObj);

	opObj = document.createElement("div");
	opObj.id = "drpDiv" + pre;
	opObj.className = "clsDrop";
	opObj.style.cssText = "width:" + w + "px;";

	if(pos == "middle") {
		opObj.style.left = (pos2.x + 0) + "px";
		opObj.style.top = (pos2.y + hy + 5) + "px";
	}
	if(pos == "right") {
		opObj.style.left = (pos1.x - w + obj.offsetWidth - 2) + "px";
		opObj.style.top = (pos2.y + hy + 5) + "px";
	}

	var pre_hide = "<div class=\"HideIcon\" onclick=\"DropClear()\" style=\"text-align:right;padding-top:3px;padding-right:20px;font-size:10px;cursor:pointer;\">[CLOSE]</div>";
	var result = pre_hide + url;
	if(url.substr(0,1) == "/") {
		if(url.toLowerCase().indexOf("/include/image") > 0) pre_hide = "";
		result = pre_hide + "<iframe id=\"imageFrame\" width=\"100%\" height=\"100%\" border=\"0\" bordercolor=\"#000000\" frameborder=\"no\" scrolling=\"no\" src=\"" + url + "\"></iframe>";
	}
	opObj.innerHTML = result;
	
	document.body.appendChild(opObj);
	$("div#drpDiv" + pre).animate({height:h},"fast");

	opObj.onmouseover = function() { hide_switch = false; }
	opObj.onmouseout = function() { hide_switch = true; }

	function DropHide(e)
	{
		e = e || window.event;
		var mobj = e.srcElement || e.target;
		if(mobj == objThis) return;
		if(FindRoot(mobj)) return;
		if(mobj.tagName == "INPUT") return;

		DropClear();
	}
	
	function FindRoot(o)
	{
		if(o.parentNode==null) return false;
		while(o.parentNode) {
			if(o.className=="clsDrop") return true;
			o = o.parentNode;
		}
		return false;
	}
	timer_files_count = setInterval("UploadEcho()", 1000);
	document.body.onclick = DropHide;
}

function DropMobile(obj,w,h,url)
{
	window.open(url, "_blank", "width=320,height=486,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no");
}
