/// <reference path="../GeneratedArtifacts/viewModel.js" />
/// <reference path="../Scripts/c1ls-4.0.20142.37.js" />

if (typeof c1ls === "undefined") {
    window.location.href = "http://bit.ly/c1ls-nuget";
}

myapp.Home.ScreenContent_render = function (element, contentItem) {

    var ul = "<ul class='msls-tile-list ui-listview' style='margin: 0px;' data-role='listview' data-inset='false'>";
    var liClass = "ui-li ui-btn ui-btn-up-a";
    var divClass = "msls-presenter msls-list-child msls-ctl-group-custom-control msls-vauto msls-hstretch msls-compact-padding msls-presenter-content msls-hscroll";
    var border = "border-left-width:1px; border-right-width:1px; border-top-width:1px; border-bottom-width:1px;";
    var width = "width:254px;";
    var d3Color = "background:#5d7798;";
    var vsColor = "background:#68217a;";

    var items = [];
    var excluded = ["Screen", "ViewGame", "ViewGDP", "AddEditProduct"];
    excluded.push(contentItem.screen.details.getModel().name);

    $.each(myapp, function (key, value) {
        if (key.slice(0, 4) === "show") {
            var name = key.substring(4);

            if (excluded.indexOf(name) < 0) {
                myapp[name].prototype.constructor([], undefined);
                var model = myapp[name].prototype.details.getModel();
                var display = model.displayName;
                var tap = " onclick=myapp." + key + "()";
                var d3 = name.slice(0, 2) === "D3" ? d3Color : "";
                var li = "<li title='" + display + "' class='" + liClass + "' data-msls='true' style='" + width + border + d3 + "'" + tap + ">";
                var div = "<div class='" + divClass + "'><table><tr><td><img src='Icons/" + name + ".png'/></td><td><span>" + display + "</span></td></tr></table></div></li>";
                items.push(li + div);
            }
        }
    });

    items.sort();

    if (myapp.rootUri.indexOf("componentone.com") > 0) {
        var display = "VS2012: Download Project";
        var tap = " onclick=window.location.href='c1lshtml2012.zip'";
        var li = "<li title='" + display + "' class='" + liClass + "' data-msls='true' style='" + width + border + vsColor + "'" + tap + ">";
        var div = "<div class='" + divClass + "'><table><tr><td><img src='Icons/Download.png'/></td><td><span>" + display + "</span></td></tr></table></div></li>";
        items.push(li + div);
    }

    if (myapp.rootUri.indexOf("componentone.com") > 0) {
        var display = "VS2013: Download Project";
        var tap = " onclick=window.location.href='c1lshtml2013.zip'";
        var li = "<li title='" + display + "' class='" + liClass + "' data-msls='true' style='" + width + border + vsColor + "'" + tap + ">";
        var div = "<div class='" + divClass + "'><table><tr><td><img src='Icons/Download.png'/></td><td><span>" + display + "</span></td></tr></table></div></li>";
        items.push(li + div);
    }

    ul = ul + items.join("\r\n") + "</ul>";
    $(ul).appendTo($(element));
};