﻿$(document).ready(function () {
    $('#upstairs').html("").append('<img src="/img/loading.gif" id="LoadingImg" class="loadingicon" />');
    $.ajax({
        url: '/DesktopModules/Events/EventRSS.aspx?mid=414&tabid=73',
        success: function (rssdata) {
            $("#upstairs").html("");
            var rootLevel = rssdata;
            var tmp = '<table class="events"><tbody>';
            var color = "white";

            $(rootLevel).find("item").each(function (id) {
                if (id < 9) {
                    var description = $(this).find("description").text();
                    var title = $(this).find("title").text();

                    if (title.length > 40) {
                        title = title.substring(0, 40) + "...";
                    }

                    var link = "/Bar/EventsUpstairs.aspx";
                    var tmpArray = new Array();
                    tmpArray = description.split("/");

                    var day = tmpArray[0];
                    var month = tmpArray[1];
                    var weekday = tmpArray[2];

                    tmp = tmp + createGig(title, day, month, weekday, link, color);
                    if (color == "white") {
                        color = "gray";
                    } else {
                        color = "white";
                    }
                }
            });

            tmp = tmp + '</tbody></table>';
            $("#upstairs").append(tmp);
        }
    });

    $.ajax({
        url: '/DesktopModules/Events/EventRSS.aspx?mid=415&tabid=73',
        success: function (rssdata) {

            var rootLevel = rssdata;
            var tmp = '<table class="events"><tbody>';
            var color = "white";

            $(rootLevel).find("item").each(function (id) {
                if (id < 9) {
                    var description = $(this).find("description").text();
                    var title = $(this).find("title").text();

                    if (title.length > 35) {
                        title = title.substring(0, 35) + "...";
                    }

                    var link = "/Venue/Listings.aspx";
                    var tmpArray = new Array();
                    tmpArray = description.split("/");

                    var day = tmpArray[0];
                    var month = tmpArray[1];
                    var weekday = tmpArray[2];

                    tmp = tmp + createGig(title, day, month, weekday, link, color);
                    if (color == "white") {
                        color = "gray";
                    } else {
                        color = "white";
                    }
                }
            });

            tmp = tmp + '</tbody></table>';
            $("#downstairs").append(tmp);
        }
    });

    function createGig(title, day, month, weekday, link, color) {
        return '<tr><td>' + weekday + ' - ' + day + ' ' + month + ' </td><td class="' + color + '"><a href="' + link + '">' + title + '</a></td></tr>';
    };
});
