﻿var orderDoc;
function loadXml(path) {
    orderDoc = null;
    if (window.ActiveXObject) {
        orderDoc = new ActiveXObject("MSXML2.DOMDocument.3.0");
        orderDoc.async = false;
        orderDoc.load(path);
        if (orderDoc.firstChild.nodeName == "xml") {
            _root = orderDoc.childNodes[1];
            return _root;
        }
        else {
            _root = orderDoc.firstChild;
            return _root;
        }

    }
//    else if (document.implementation
//   && document.implementation.createDocument) {

//        Document.prototype.__defineGetter__("xml", function() {
//            return (new XMLSerializer()).serializeToString(this);
//        }
//      );
//        Node.prototype.__defineGetter__("xml", function() {
//            return (new XMLSerializer()).serializeToString(this);
//        }
//      );
//        orderDoc = document.implementation.createDocument("", "", null);
//        orderDoc.async = false;
//        orderDoc.load(path);
//        if (orderDoc.firstChild != undefined)
//            return orderDoc.firstChild;
//        orderDoc.onload = function() {
//            _root = orderDoc.firstChild;
//            return _root;
//        }
//      ;

//    }

}

$(document).ready(function() {
    LoadSlidep();
});

function LoadSlidep() {
    
    //loadXml("../SlideplaySource.xml");
    
//    if (orderDoc != null) {
//    
//        var imagesDoc = orderDoc.lastChild;
//        var html = '';

//        for (var i = 0; i < imagesDoc.childNodes.length; i++) {
//            var title = imagesDoc.childNodes[i].childNodes[0].text;
//            var url = imagesDoc.childNodes[i].childNodes[1].text == "" ? "javascript:void(0);" : imagesDoc.childNodes[i].childNodes[1].text;
//            var name = imagesDoc.childNodes[i].childNodes[2].text;
//            html += '<li>';
//            html += '<a target="_blank" href="' + FormatUrl(url) + '"><img alt="" src="../SlideplayerPic/' + name + '" />';
//            html += '<p>' + title + '</p>';
//            html += '</a></li>';
//        }
//        document.getElementById("pub_slideplay").innerHTML = "你是朋友";
//        document.getElementById("divMsg").innerHTML = "你是朋友";
//        $("#pub_slideplay").html(html);

//        new dk_slideplayer("#pub_slideplay", { width: "450px", height: "220px", fontsize: "12px", time: "5000" });
//    }

//    var imagesDoc = orderDoc.lastChild;
//    var html = '';

//    for (var i = 0; i < imagesDoc.childNodes.length; i++) {
//        var title = imagesDoc.childNodes[i].childNodes[0].text;
//        var url = imagesDoc.childNodes[i].childNodes[1].text == "" ? "javascript:void(0);" : imagesDoc.childNodes[i].childNodes[1].text;
//        var name = imagesDoc.childNodes[i].childNodes[2].text;
//        html += '<li>';
//        html += '<a target="_blank" href="' + FormatUrl(url) + '"><img alt="" src="../SlideplayerPic/' + name + '" />';
//        html += '<p>' + title + '</p>';
//        html += '</a></li>';
    //    }
//    var imagesDoc = orderDoc.lastChild;
//    alert(orderDoc.lastChild);
//    document.getElementById("pub_slideplay").innerHTML = "你是朋友";
    //    document.getElementById("divMsg").innerHTML = "你是朋友";
    
//    $.post('data.xml', function(data) {
//        // 查找所有的book节点 
//        
//        //        var s = "";
//        //        $(data).find('item').each(function(i) {
//        //            debugger;
//        //            var name = $(this).children('title').text();
//        //        });
    //    });

    $.ajax({
        type: "get",

        datatype: "xml",

        url: "../SlideplaySource.xml",
        error: function(xhr, textStatus, error) { alert('XML loading filed.'); },
        success: function(data) {
            var html = '';
            $(data).find('item').each(function(i) {

                var title = $(this).children('title').text();
                var url = FormatUrl($(this).children('url').text());
                var name = $(this).children('name').text();
                html += '<li>';
                html += '<a target="_blank" href="' + url + '"><img alt="" src="../SlideplayerPic/' + name + '" />';
                html += '<p>' + title + '</p>';
                html += '</a></li>';
            });
            $("#pub_slideplay").html(html);
            new dk_slideplayer("#pub_slideplay", { width: "450px", height: "220px", fontsize: "12px", time: "5000" });
        }
    });


    
}

function FormatUrl(url) {
  
    url = url.replace("$", "&");
    return url
}

