/* Initialisation for JS capable browsers */

var offsetxpoint=-60; //Customize x offset of tooltip
var offsetypoint=20; //Customize y offset of tooltip
var ie=document.all;
var ns6=document.getElementById && !document.all;
var enabletip=false;
var tipobj;

var hasInnerText;

function makeHttpRequest(url, callback_function, return_xml)
{
	var http_request = false;
    if (window.XMLHttpRequest) { // Mozilla, Safari,...
       http_request = new XMLHttpRequest();
       if (http_request.overrideMimeType) {
           http_request.overrideMimeType('text/xml');
       }

   } else if (window.ActiveXObject) { // IE
       try {
           http_request = new ActiveXObject("Msxml2.XMLHTTP");
       } catch (e) {
           try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
           } catch (e) {}
       }
   }

   if (!http_request) {
       return false;
   }
   http_request.onreadystatechange = function() {

       if (http_request.readyState == 4) {
           if (http_request.status == 200) {
               if (return_xml) {
			   var XML = http_request.responseXML;
                   eval(callback_function + "(http_request.responseXML)");
               } else {
			       eval(callback_function + "(http_request.responseText)");
               }
           } else {
            //   alert('There was a problem with the request.(Code: ' + http_request.status + ')');
           }
       }
   }
   http_request.open('GET', url, true);
   http_request.send(null);
}

function GetNextPhoto()
{
    var url = 'getaphoto.php';
    makeHttpRequest(url, 'loadPic', true);
}
function loadPic(xml)
{

	var img_tag = xml.getElementsByTagName("content").item(0).firstChild.nodeValue;
    document.getElementById("slideshow").innerHTML = img_tag

    try {
        clearTimeout(to);
    } catch (e) {}

    to = setTimeout("GetNextPhoto()", parseInt(xml.getElementsByTagName("reload").item(0).firstChild.nodeValue));

}

function GetNews()
{
    var url = 'getnews_v2.asp';
    makeHttpRequest(url, 'loadnews', true);
}

function loadnews(xml)
{

	var news_html = xml.getElementsByTagName("content").item(0).firstChild.nodeValue;
    document.getElementById("newshls").innerHTML = news_html

}
function GetCalEvents()
{
    var url = '../calendar/upcomingz.php';
    makeHttpRequest(url, 'loadevents', true);
}

function loadevents(xml)
{

	var cal_html = xml.getElementsByTagName("content").item(0).firstChild.nodeValue;
    document.getElementById("calhls").innerHTML = cal_html

}

function getevententry(url)
{

    makeHttpRequest(url, 'loadEventTT', true );
}

function loadEventTT(xml)
{

	var event_html = xml.getElementsByTagName("content").item(0).firstChild.nodeValue;
	balloontip(event_html,'', 300);

}

function changeTextById(elementId,changeVal){
    if(!hasInnerText){
        elementId.textContent = changeVal;
    }else{
        elementId.innertext = changeVal;
    }
}

function init()
{
    tipobj=document.getElementById("balloon_tooltip");
 
    hasInnerText = (document.getElementsByTagName("body")[0].innerText != undefined) ? true : false;
	GetNews();
	GetCalEvents();
    GetNextPhoto();
    return true;
}


/***********************************************
* Cool DHTML tooltip script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function balloontip(thetext, thecolor, thewidth){
if (ns6||ie){
if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px";
if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
var xxx = document.getElementById("balloon_content").innerHTML=thetext
enabletip=true
return false
}
}

function positiontip(e){
if (enabletip){
var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
//Find out how close the mouse is to the corner of the window
var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20
var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20

var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000

//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<tipobj.offsetWidth)
//move the horizontal position of the menu to the left by it's width
tipobj.style.left=ie? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+"px" : window.pageXOffset+e.clientX-tipobj.offsetWidth+"px"
else if (curX<leftedge)
tipobj.style.left="5px"
else
//position the horizontal position of the menu where the mouse is positioned
tipobj.style.left=curX+offsetxpoint+"px"

//same concept with the vertical position
if (bottomedge<tipobj.offsetHeight)
tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px"
else
tipobj.style.top=curY+offsetypoint+"px"
tipobj.style.visibility="visible"
}
}

function hideballoontip(){
if (ns6||ie){
enabletip=false
tipobj.style.visibility="hidden"
tipobj.style.left="-1000px"
tipobj.style.backgroundColor=''
tipobj.style.width=''
}
}

document.onmousemove=positiontip

window.onload = init;