
function getQueryString(key, default_)
{
  if (default_==null) default_="";
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(window.location.href);
  if(qs == null)
    return default_;
  else
    return qs[1];
} 
  
//alert (currentQuestion);

function getObjRef(obj) {
	if (document.getElementById) {
		return document.getElementById(obj);
	}
	else if (document.all) {
		return document.all[obj];
	}
	else {
		return null;
	}
}

function prepNews (newsID) {
	newsListNodes = getObjRef(newsID).getElementsByTagName('li');
	newsListItem = getObjRef(newsID).firstChild;
	
	allLinks = getObjRef(newsID).getElementsByTagName('a');
	for (n = 0; n < allLinks.length; n++) {
		theLink = allLinks[n];
		//alert(theLink.parentNode.tagName);
		//if (theLink.parentNode.tagName == 'H3') {
			//storyLink = theLink.href;
			//alert(theLink.href);
			theLink.onclick=function(){loadStory(this.href); return false;};
			theLink.onkeypress=function(){if (theLink.keyCode == 13) {loadStory(this.href); return false;}};
		//}
	}
}

function popupStory (newsID) {
	storyLink = '/content/news-story~action=view,nid='+newsID+'#storyTop';
	ajax_loadContent('newsStory',storyLink);
	getObjRef('newsBox').style.display = 'block';
	getObjRef('newsBoxInner').style.top = getScrollY()+'px';
}

function loadStory (storyLink) {
	storyLink = storyLink.replace('content/news/archive~', 'content/news-story~');
	storyLink = storyLink.replace('content/news~', 'content/news-story~');
	storyLink = storyLink+'#storyTop';
	ajax_loadContent('newsStory',storyLink);
	getObjRef('newsBox').style.display = 'block';
	getObjRef('newsBoxInner').style.top = getScrollY()+'px';
}

function domNews (newsID) {
	newsListNodes = getObjRef(newsID).getElementsByTagName('li');
	newsListItem = getObjRef(newsID).firstChild;
	
	allLinks = getObjRef(newsID).getElementsByTagName('a');
	for (n = 0; n < allLinks.length; n++) {
		theLink = allLinks[n];
		//alert(theLink.parentNode.tagName);
		//if (theLink.parentNode.tagName == 'H3') {
			//storyLink = theLink.href;
			//alert(theLink.href);
			theLink.onclick=function(){redirectStory(this.href); return false;};
			theLink.onkeypress=function(){if (theLink.keyCode == 13) {redirectStory(this.href); return false;}};
		//}
	}
}

function redirectStory (storyLink) {
	storyLink = storyLink.replace('/content/news/news~action=view,nid=', '/content/news?newsID=');
	window.location.href = storyLink;
}

function closeNews () {
	getObjRef('newsStory').innerHTML = "";
	getObjRef('newsBox').style.display = 'none';
}

function getScrollY() {
 var scrOfY = 0;

  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
  } else if( document.body && document.body.scrollTop ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
  } else if( document.documentElement && document.documentElement.scrollTop ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
  }
  pageHeight = getObjRef('sizeOfPage').clientHeight;
  boxHeight = getObjRef('newsBoxInner').clientHeight;
  if ((scrOfY + boxHeight) > pageHeight) {
	scrOfY = (pageHeight - boxHeight)
  }
  if (scrOfY < 200) {
	  scrOfY = 200 
  }

  return scrOfY;
}

function checkQuery() {
	var newsID = getQueryString('newsID');
	//alert (newsID);
	if (newsID) {
		popupStory (newsID);
	}
}
