var masterURL = "http://download.go.cd/";
init();

function registerShowCheckSumLinks() {
    $('.show-sha1, .show-md5').click(function() {
        $(this).next().show();
        $(this).hide();
        return false;
    });
}

function fetchArtifacts(callbackFn) {
    $.ajax.send("http://download.go.cd/local/releases.json", function(ArtifactList, status) {
        callbackFn(JSON.parse(ArtifactList).reverse());
    });
}

function init() {
    var selectRevisions = $('#revisions-holder #revisions');
    fetchArtifacts(function(artifactList) {
        selectRevisions.change(function() {
            renderArtifacts(artifactList, $(this)[0].selectedIndex)
        });
        var i = 0;
        while (i < artifactList.length) {

            var artifact = artifactList[i];
            var isSelected = "";
            var releaseType = "";
            if (artifact.release_type == "supported") {
                isSelected = "selected";
                releaseType = " [" + artifact.release_type + "]";
            }
            selectRevisions.append("<option " + isSelected + ">" + artifact.version + releaseType + "</option>");

            if (artifact.release_type == "supported") {
                $('#latestVersion').html(artifact.version);
                renderArtifacts(artifactList, i)
            }
            i++;
        }
    });
    registerShowCheckSumLinks();
}

function getArtifactByType(artifactsForVersion, type) {
    var j = artifactsForVersion.files.length;
    while (j--) {
        if (artifactsForVersion.files[j].type === type)
            return artifactsForVersion.files[j];
    }
}

function renderArtifact(artifactList, artifactType, agentOrServer) {
    var artifact = getArtifactByType(artifactList, artifactType);

    if (typeof artifact !== "undefined" || artifact != null) {
        var fileName = artifact.name;
        //for GTM analytics
        // TODO : remove these conditions after JSON modification 

        var splitArtifactType = artifactType.split("-");
        var GTMID = splitArtifactType[0].charAt(0).toUpperCase() + splitArtifactType[0].slice(1) + '-' + splitArtifactType[1].charAt(0).toUpperCase() + splitArtifactType[1].slice(1);
        //ends : for GTM analytics

        $('.download-links .' + artifactType).html('<a class="icon-download" id="' + GTMID + '" href="'  + masterURL + "gocd/" + fileName + '">' + agentOrServer + '</a>');

        $('.checksum .sha1 .' + artifactType).html(artifact.sha1sum);
        $('.checksum .md5 .' + artifactType).html(artifact.md5sum);

    } else {
        $('.download-links .' + artifactType + ' + .intallers-not-available').show();
        $('.download-links .' + artifactType + ' + .separator').hide();
        $('.checksum > div .' + artifactType).hide();
    }
}

function renderArtifacts(ArtifactList, versionIndex) {
    var artifactList = ArtifactList[versionIndex];
    $('.intallers-not-available').hide();
    $('.separator, .checksum span').css({
        "display": "inline"
    });

    $('.windows-server, .windows-agent, .mac-server, .mac-agent, .linuxdeb-server, .linuxdeb-agent, .linuxrpm-server, .linuxrpm-agent, .solaris-server, .solaris-agent, .package-server, .package-agent').children().remove();

    renderArtifact(artifactList, "windows-server", "Server");
    renderArtifact(artifactList, "windows-agent", "Agent");

    renderArtifact(artifactList, "mac-server", "Server");
    renderArtifact(artifactList, "mac-agent", "Agent");

    renderArtifact(artifactList, "linuxDeb-server", "Server");
    renderArtifact(artifactList, "linuxDeb-agent", "Agent");

    renderArtifact(artifactList, "linuxRpm-server", "Server");
    renderArtifact(artifactList, "linuxRpm-agent", "Agent");

    renderArtifact(artifactList, "solaris-server", "Server");
    renderArtifact(artifactList, "solaris-agent", "Agent");

    renderArtifact(artifactList, "package-server", "Server");
    renderArtifact(artifactList, "package-agent", "Agent");


    renderCheckSum(artifactList);
}

function renderCheckSum(artifactList) {
    $('#sha1-download').html('<a class="icon-download" href="' + masterURL + 'local/' + artifactList.version + '/sha1.checksum">SHA1</a>');
    $('#md5-download').html('<a class="icon-download" href="' + masterURL + 'local/' + artifactList.version + '/md5.checksum">MD5</a>');
}

@@ -31,17 +31,16 @@
 ad.go.cd
-/
 %22;%0Ainit(
@@ -1680,16 +1680,32 @@
 OrServer
+, downloadSubDir
 ) %7B%0A    
@@ -2364,12 +2364,31 @@
  + %22
-gocd
+/%22 + downloadSubDir + %22
 /%22 +
@@ -3307,32 +3307,40 @@
 erver%22, %22Server%22
+, %22gocd%22
 );%0A    renderArt
@@ -3375,32 +3375,40 @@
 -agent%22, %22Agent%22
+, %22gocd%22
 );%0A%0A    renderAr
@@ -3442,32 +3442,40 @@
 erver%22, %22Server%22
+, %22gocd%22
 );%0A    renderArt
@@ -3506,32 +3506,40 @@
 -agent%22, %22Agent%22
+, %22gocd%22
 );%0A%0A    renderAr
@@ -3578,32 +3578,44 @@
 erver%22, %22Server%22
+, %22gocd-deb%22
 );%0A    renderArt
@@ -3651,32 +3651,44 @@
 -agent%22, %22Agent%22
+, %22gocd-deb%22
 );%0A%0A    renderAr
@@ -3727,32 +3727,44 @@
 erver%22, %22Server%22
+, %22gocd-rpm%22
 );%0A    renderArt
@@ -3800,32 +3800,44 @@
 -agent%22, %22Agent%22
+, %22gocd-rpm%22
 );%0A%0A    renderAr
@@ -3875,32 +3875,40 @@
 erver%22, %22Server%22
+, %22gocd%22
 );%0A    renderArt
@@ -3947,24 +3947,32 @@
 nt%22, %22Agent%22
+, %22gocd%22
 );%0A%0A    rend
@@ -4022,16 +4022,24 @@
 %22Server%22
+, %22gocd%22
 );%0A    r
@@ -4090,16 +4090,24 @@
  %22Agent%22
+, %22gocd%22
 );%0A%0A%0A   
@@ -4250,32 +4250,33 @@
  + masterURL + '
+/
 local/' + artifa
@@ -4398,16 +4398,17 @@
 rURL + '
+/
 local/' 

Fix deb and rpm links in download page.