//////////////////////////////////////////////////////////////////
// Web Rockstars Speedy Feed Reader
// --------------------------------------------------------------
// Published at dmxzone.com
// Author: Aarron Walter, http://aarronwalter.com
// File: ajaxRSS.js
//
// Requires the use of Prototype (http://prototype.conio.net/)
//////////////////////////////////////////////////////////////////


// Create an event listener to initialize the Ajax call to the server
Event.observe(window, 'load', initRSS, false);


// Initialize RSS feed reader
function initRSS() {
  if (document.getElementsByTagName) {
    var divs = document.getElementsByTagName("div");
    for (var i=0; i < divs.length; i++) {
		if (divs[i].className == "loadingfeed") {
		  getFeed(divs[i].getAttribute("title"),divs[i].getAttribute("id"));	
        };
    }
  }
}


// Fetch parsed RSS using Ajax, and refresh every minute
function getFeed(params,boxId) {
  // Update user interface with loading animation
  $(boxId).innerHTML = '<img src="i/loading.gif" alt="Loading RSS Headlines" class="loading" />';
  
  // Prepare GET variables needed for PHP to parse RSS (split into an array)
  splitParams = params.split(',');
  var pars = 'url=' + escape(splitParams[0])+'&numHeadlines='+escape(splitParams[1]);
  // Go-go gadget Ajax call using Prototype
  var myAjax = new Ajax.Updater(boxId, 'inc/parseRSS.php', {method: 'get', parameters: pars});
  // Auto-update feeds every minute (60 seconds)
  var MyAjaxUpdater = new Ajax.PeriodicalUpdater(boxId, 'inc/parseRSS.php', {method:'get', parameters:pars, asynchronous:true, frequency:60});
}

function newWindow(mypage,myname,w,h,features) {
	if(screen.width){
		var winl = (screen.width-w)/2;
		var wint = (screen.height-h)/2;
	} else { winl = 0;wint =0; }
  if (winl < 0) winl = 0;
  if (wint < 0) wint = 0;
  var settings = 'height=' + h + ',';
  settings += 'width=' + w + ',';
  settings += 'top=' + wint + ',';
  settings += 'left=' + winl + ',';
  settings += features;
  win = window.open(mypage,myname,settings);
  win.window.focus();
}