if(window.XMLHttpRequest){

    /*
        If Opera, IE7, Mozilla, Safari, etc: Use native object.
    */
    var NewsHeadlineXMLHttpRequest = new XMLHttpRequest();

}else{

    if(window.ActiveXObject){

        /*
            Use the ActiveX control for IE5.x and IE6.
        */
        var NewsHeadlineXMLHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
          
    }

}

/*
    Set the frontpage_FirstRun var to boolean true.
    This is used to figure out whether or not this is the
    first time we're trying to fetch headlines.
*/
MAP.set("frontpage_FirstRun",true);

/*
    Start and Stop the fetching of news headlines into right_column_headlines
*/
function RightColumnFetchNewsHeadlines(){

    /*
        The ID of the interval we start with this.Start()
    */
    var IntervalId = null;

    /*
        Start the engines!
    */
    this.Start = function(){

        /*
            How often do we refresh the headlines section.
            1000 = 1 second.
        */
        var IntervalId = setInterval(StartXMLHttp,300000);
        MAP.set("IntervalId",IntervalId);

    }

    StartXMLHttp = function(){

        /*
            Lets create a timestamp, so "inferior" browsers don't cache
            the request URL.
            This timestamp must be appended to the URL. It has no effect serverside.
        */
        var date = new Date();
        var timestamp = date.getTime();

        /*
            The basic URL and querystring to be used by the NewsHeadlineXMLHttpRequest object.
        */
        if(MAP.get("frontpage_FirstRun") == true){
            
            MAP.set("frontpage_FirstRun",false);
            var QueryString = "firstrun=true&stamp=" + timestamp;
            
        }else{

            var QueryString = "stamp=" + timestamp;
    
        }

        NewsHeadlineXMLHttpRequest.open("POST","engines/headline_refresh.php?stamp=" + timestamp,true);
        NewsHeadlineXMLHttpRequest.onreadystatechange = RightColumnStateChange;
        NewsHeadlineXMLHttpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        NewsHeadlineXMLHttpRequest.send(QueryString);
        
    }

    RightColumnStateChange = function(){
        
        /*
            Container for the returned data.
        */
        var RightColumnData = null;

        if(NewsHeadlineXMLHttpRequest.readyState == 4){
            
            if(NewsHeadlineXMLHttpRequest.status == 200){
                    
                var RightColumnData = NewsHeadlineXMLHttpRequest.responseText;
                CreateHeadlineList(RightColumnData);
                
            }else{

                /*
                    Serverside script failed for some reason. Stop further execution.
                */
                var IntervalId = MAP.get("IntervalId");
                clearInterval(IntervalId);

            }

        }

    }

    CreateHeadlineList = function(RightColumnData){
        
        document.getElementById("headlines_ul").innerHTML = RightColumnData;

    }

}

RCFNH = new RightColumnFetchNewsHeadlines();
RCFNH.Start();