/*
 * jQuery ctRotator Plugin briget
 * Convert an ul or ol list to a useable data source for ctRotator
 * 
 * Under MIT license http://www.opensource.org/licenses/mit-license.php
 *
 * @author: Cuong Tham
 * @version: 1.0
 * @requires jQuery v1.2.6 or later
 * @requires ctRotator
 *
 * @headsTip: Examples and documentation at: http://thecodecentral.com/2008/11/12/ctrotator-a-flexible-itemimage-rotator-script-for-jquery
 */

function ctRotatorBridgeRss20(url, readyCallback){
 
  this.url = url;
  this.readyCallback = readyCallback;
}

ctRotatorBridgeRss20.prototype = {
    getDataSource: function() {
        var readyCallback = this.readyCallback;
        var dataSource = [];

        $.ajax({ type: "GET", url: this.url, dataType: ($.browser.msie) ? "text" : "xml", timeout: 5000, cache: false, async: false, success: function(data, errMsg) {
            var dataxml;
            if (typeof data == "string") {
                dataxml = new ActiveXObject("Microsoft.XMLDOM");
                dataxml.async = false;
                dataxml.loadXML(data);
            } else {
                dataxml = data;
            }
            $(dataxml).find('channel item').each(function() {
                var e = $(this);
                dataSource.push({
                    title: e.find('title').text(),
                    link: e.find('link').text(),
                    description: e.find('description').text(),
                    guid: e.find("guid").text()
                });
            });
            readyCallback(dataSource);
        }, error: function(reqObject, errMsg, ex) {
            alert("There was a problem accessing the News Feed.  The headlines will not be avaliable but you can see the archive at http://www.guidestarinternational.org/news.aspx. (The system said: " + errMsg + ")");
        }
        });
        return dataSource;
    }

};
