﻿$.fn.Menu = function(options) {
    var defaults = {
        targeturl: "./season20078.xml",
        season: '2009/10',
        tournament: 'Wsyl League'
    }
    var opts = $.extend(defaults, options);
    var container = this;
    var _currentSeason;
    $(container).empty();

    $.ajax({
        type: "GET",
        url: opts.targeturl, //Requesting simple.xml
        dataType: "xml", //Make sure that you specify the type of file you expecting (XML)
        complete: function(data) {

            var men = new Menu(data);

            var html = men.Print();
            $(container).append(html);
        }
    });
};

function Menu(xml) {
    this.data = xml;

    this.Print = function() {

        var html = "";
        html += "<ul class=\"nav main\">";
        html += "<li><a href=\"#\" onClick='content(\"Home\",\"\")'>Home</a>";

        //find each 'item' in the file and parse it
        $(this.data.responseXML).find('Season').each(function() {

            var $item = $(this);
            html += "<li><a href=\"#\" onClick='content(\"" + $item.attr("Name") + "\",\"\")'>" + $item.attr("Name") + "</a>";
            html += "<ul>";

            $item.find('Tournament').each(function() {
                var $tournament = $(this);
                html += "<li><a href=\"#\" onClick='content(\"" + $item.attr("Name") + "\",\"" + $tournament.attr("Name") + "\",\"" + $tournament.attr("Type") + "\")'>" + $tournament.attr("Name") + "</a></li>";
            });
            html += "</ul>";
            html += "</li>";
        });

        html += "</ul>";
        return html;
    }

}