var DoMove=false;
var isOverNews=false;
var isOverDetail=false;
var moveElement="";
var xOffset=0;
var yOffset=0;
var curX=100;
var curY=20;

function StartMove(e) {
	if (!DoMove) {
		if (!e) e=window.event;

		var on=document.getElementById("news");
		var od=document.getElementById("detail");
		if (isOverNews) {
			on.style.zIndex=100;
			od.style.zIndex=50;
			on.style.cursor="move";
			
			xOffset=e.clientX-parseInt(on.style.left);
			yOffset=e.clientY-parseInt(on.style.top);
		
			moveElement="news";
			DoMove=true;
		} else if (isOverDetail) {
			od.style.zIndex=100;
			on.style.zIndex=50;
			od.style.cursor="move";
			
			xOffset=e.clientX-parseInt(od.style.left);
			yOffset=e.clientY-parseInt(od.style.top);
		
			moveElement="detail";
			DoMove=true;
		}

		if (DoMove) {
			document.body.onmousemove=Move;
			document.body.onmouseup=StopMove;
			document.body.ondrag = function () { return false; };
		    document.body.onselectstart = function () { return false; };

			/*document.body.onselectstart = function()
			{
				event.returnValue = false;
				return false;
			};
			document.getElementById("blurElem").focus();
			document.getElementById("blurElem").blur();*/

		} else return true;
	} else if (DoMove) StopMove();
	
	return false;

}

function StopMove(e) {
	if(!e) e=window.event;
	
	if (moveElement.length) {
		var o=document.getElementById(moveElement);
		var pos=getScrollPos();
		curX=parseInt(o.style.left);
		curY=parseInt(o.style.top)-pos;

		o.style.cursor="default";
		DoMove=false;
		document.body.onmousemove=null;
		document.body.onmouseup=null;
		document.body.onselectstart=null;
		document.body.ondrag=null;

		if (moveElement=="news") {
			saveNewsPos();
		} else {
			saveDetailPos();
		}

		moveElement="";
	}
	//isOver=false;
}

function getScrollPos() {
	var y;
	if (self.pageYOffset) // all except Explorer
	{
		y = self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
		// Explorer 6 Strict
	{
		y = document.documentElement.scrollTop;
	}
	else if (document.body) // all other Explorers
	{
		y = document.body.scrollTop;
	}
	return y;
}

function Move(e) {
	if (!e) e=window.event;
	var o=document.getElementById(moveElement);

	o.style.left=(e.clientX-xOffset)+"px";
	o.style.top=(e.clientY-yOffset)+"px";
	
	return false;
}

document.onmousedown=StartMove;

function formatDetail() {
	return;
/*	var newWidth=document.getElementById("detailContent").offsetWidth;
	var newHeight=document.getElementById("detailContent").offsetHeight;
	document.getElementById("detail").style.width=newWidth+60;
	document.getElementById("detail").style.height=newHeight+70;
	document.getElementById("detailSpacer1").width=newWidth+60;
	document.getElementById("detailSpacer1").height=newHeight+70;
	document.getElementById("detailSpacer2").width=newWidth+20;
	document.getElementById("detailSpacer2").height=newHeight+30;
	if (is("gecko")) document.getElementById("detailContent").style.top=20;
	if (is("opera")) {
		document.getElementById("detailClose").style.left=newWidth+15;
	} else {
		document.getElementById("detailClose").style.left=newWidth+25;
	}
	document.getElementById("detail").style.visibility="visible";*/
}

function showDetail(detailName) {
	debugPrint(detailName);
	var de=document.getElementById("detail");
	de.style.display="block";
	//de.style.visibility="visible";

	loadFragmentInToElement("details/d_"+detailName, 'detailContent');

	var pos=getScrollPos();
	var x=parseInt(readCookie("detailPosX"));
	var y=parseInt(readCookie("detailPosY"));

	if (!x && !y) {
		x=curX;
		y=curY;
	}
	
	if (y<0) y=0;
		
	de.style.left=x+"px";
	de.style.top=(y+pos)+"px";
	//alert(x+"/"+de.style.left+" : "+y+"/"+de.style.top+" / "+pos);

	return false;
}


function hideDetail() {
	isOverDetail=false;
	StopMove();
	//document.getElementById("detail").style.visibility="hidden";
	document.getElementById("detail").style.display="none"; //style.visibility="hidden";
	
	
	return false;
}

function saveDetailPos() {
	var ne=document.getElementById("detail");
	if (ne.style.visibility!="hidden") {
		var pos=getScrollPos();
		var x=parseInt(ne.style.left);
		var y=parseInt(ne.style.top)-pos;

		writeCookie("detailPosX",x,90);
		writeCookie("detailPosY",y,90);
	}
}


function changeTrans(elem,p) {
	var e=document.getElementById(elem);
	e.style.filter="alpha(opacity="+p+")";
	e.style.mozopacity=p/100;
	e.style.khtmlopacity=p/100;
	e.style.opacity=p/100;
}


