var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;
var mx = 0;
var my = 0;
var bubbleShowing = false;
function getMouseXY(e) {
	if (IE) { // grab the x-y pos.s if browser is IE
    	if (document.body) {
			tempX = event.clientX + document.body.scrollLeft
    		tempY = event.clientY + document.body.scrollTop
		}
	} else {  // grab the x-y pos.s if browser is NS
    	tempX = e.pageX
    	tempY = e.pageY
	}
	if (bubbleShowing) positionBubble();
		
	//window.status = "x = " + tempX + ", y = " + tempY;
}
function positionBubble() {
	var bubble = document.getElementById('dg_glossary_bubble');
	if (IE) {
		bubble.style.left = (document.documentElement.scrollLeft + tempX - 34) + "px";
		bubble.style.top = (document.documentElement.scrollTop + tempY + 12) + "px";
		
	} else {
		bubble.style.left = (tempX - 34) + "px";
		bubble.style.top = (tempY + 12) + "px";
	}
}
function glossaryClose() {
	document.getElementById('dg_glossary_wrapper').style.display = 'none';
	document.getElementById('dg_white_shade').style.display = 'none';
}
function glossaryOpen() {
	
}
function glossaryLoadSummary(word) {
	var r = Math.random();
	var url = "../lib/get_glossary.php?w=" + escape(word) + "&r=" + r;
	ajaxLoad('dg_glossary_bubble_middle', url);
}
function glossaryOver(e, word) {
	var bubble = document.getElementById('dg_glossary_bubble');
	if (bubble == null) {
		bubble = createDiv('dg_glossary_bubble');
		bubble.appendChild(createDiv('dg_glossary_bubble_top'));
		bubble.appendChild(createDiv('dg_glossary_bubble_middle'));
		bubble.appendChild(createDiv('dg_glossary_bubble_bottom'));
		document.body.insertBefore(bubble, document.body.firstChild);
	} else {
		bubble.style.display = 'block';
	}
	document.getElementById('dg_glossary_bubble_middle').innerHTML = '<p>Fetching...</p>';
	positionBubble();
	glossaryLoadSummary(word);
	bubbleShowing = true;
}
function createDiv(id) {
	var div = document.createElement('div');
	div.setAttribute('id' , id);
	return div;
}
function glossaryOut() {
	var bubble = document.getElementById('dg_glossary_bubble');
	if (bubble != null) bubble.style.display = 'none';
	bubbleShowing = false;
}
function glossaryResize() {
	return;
	var gMain = document.getElementById('dg_glossary_content_main');
	var gParent = document.getElementById('dg_glossary_content_parent');
	var gMiddle = document.getElementById('dg_glossary_middle');
	if (gMain.offsetHeight > 350) {
		gParent.style.height = gMain.offsetHeight + 'px';
		gMiddle.style.height = (gMain.offsetHeight - 309) + 'px';
	} else {
		gParent.style.height = '350px';
		gMiddle.style.height = '41px';
	}
}	
function glossaryLoad(word) {
	glossaryOut();
	var gMain = document.getElementById('dg_glossary_wrapper');
	var whiteBack = document.getElementById('dg_white_shade');
	var holder = document.getElementById('dg_glossary_main');
	if (gMain == null) {
		gMain = document.createElement('div');
		gMain.setAttribute('id', 'dg_glossary_wrapper');
		//document.body.insertBefore(gMain, document.body.firstChild);
		//alert(document.body.firstChild);
		document.body.insertBefore(gMain, document.body.firstChild);
	}
	//gMain.style.top = document.documentElement.scrollTop + 'px';
	if (IE) {
		gMain.style.left = '0px';
		gMain.style.top = document.documentElement.scrollTop + 'px';
	} else {
		gMain.style.left = ((document.body.clientWidth - 603)/2) + 'px';
		gMain.style.top = document.body.scrollTop + 'px';
	}
	if (whiteBack == null) {
		whiteBack = document.createElement('div');
		whiteBack.setAttribute('id', 'dg_white_shade');
		//gMain.appendChild(whiteBack);
		//
		document.body.insertBefore(whiteBack, document.body.firstChild);
	}
	
	if (holder == null) {
		holder = document.createElement('div');
		holder.setAttribute('id', 'dg_glossary_main');
		gMain.appendChild(holder);
	}
	
	gMain.style.display = 'block';
	whiteBack.style.display = 'block';
	whiteBack.style.width = document.body.offsetWidth + 'px';
	whiteBack.style.height = document.body.offsetHeight + 'px';
	
	var r = Math.random();
	url = "../content/glossary_test.php?w=" + escape(word) + "&r=" + r;
	var tmp = '<div id="dg_glossary_content_top">' +
				'<div id="dg_glossary_close_box">' +
				'<a href="#" onmouseup="glossaryClose(); return false;">CLOSE WINDOW</a>' +
				'</div>' +
				'<h1>Glossary: <span class="dg_glossary_word">Loading</span></h1>' +
        		'</div>' +
        		'<div id="dg_glossary_content_main">' +
                '<p style="clear:left">&nbsp;</p>' +
        		'</div>' +  
        		'<div id="dg_glossary_bottom">' +
        		'<div id="dg_glossary_more">' +
				'<a href="#" onmouseup="glossaryMore(); return false;">VIEW FULL GLOSSARY</a>' +
				'</div>' +
				'</div>';
	ajaxLoad('dg_glossary_main', url, glossaryResize, tmp);
}
function loadGlossary(word) {
	glossaryLoad(word);
}
function glossaryMore() {
	document.location = "../content/?tag=glossary";
}
function openCaptions(file) {
	window.open("../content/video_captions.php?file=" + file, "captions_window", "status=0,toolbar=0,location=0,menubar=0,directories=0,width=400,height=550");
}
function startQuoteScroll() {
	//$('quote').style.marginLeft = -100;
}
function showQuotation() {
	if ($('quote_span')) {
		ajaxLoad('quote_span', '../content/get_comment.php', startQuoteScroll, 'fetching comment');
	} else {
		ajaxLoad('quote', '../content/get_comment.php');
	}
}
function clearBox(el) {
	el.value = '';	
}
function newsJump(id) {
	document.location = "../newsandviews/?id=" + id;	
}
function tagJump(tag) {
	document.location = "../content/?tag=" + tag;
}
