-
-fs = require 'fs'
-window.jss = jss = require 'jss-browserify'
-Mustache = require 'mustache'
-
-
-
-# lists so that I can order the projects easily:
-
-projectList = [
-    "animus",
-    "Kipos",
-    "KairosHacks",
-    "LudumPad",
-    "ld48-29",
-    "L8RYO",
-    "rule#34",
-    "pzero",
-    "enitor",
-    "cellvorsum"
-]
-
-stuffList = [
-    "mocha",
-    "mustache.js",
-    "subclass-error",
-    "eximo.js"
-]
+jss = require 'jss-browserify'
 
 
 




# generate html for projects

projectsTemplate = fs.readFileSync 'mu/projects.mu', 'utf-8'

projectContainer = document.getElementById 'projects'
stuffContainer = document.getElementById 'stuff'

reqListener = ->
    database = JSON.parse @responseText

    projectList = (database[projectName] for projectName in projectList)
    stuffList = (database[projectName] for projectName in stuffList)

    projectContainer.innerHTML = Mustache.render projectsTemplate, projectList
    stuffContainer.innerHTML = Mustache.render projectsTemplate, stuffList

dbReq = new XMLHttpRequest()
dbReq.onload = reqListener
dbReq.open 'get', '/js/projects.json', true
dbReq.send()



# w0l0l0 button color change / rickroll / etc

getRandomColor = () ->
    letters = '0123456789ABCDEF'.split ''
    color = '#'
    for i in [0..5]
        color += letters[Math.floor(Math.random() * 16)]
    color

# http://www.sitepoint.com/javascript-generate-lighter-darker-color/
ColorLuminance = (hex, lum = 0) ->
    hex = String(hex).replace /[^0-9a-f]/gi, ''
    hex = hex[0]+hex[0]+hex[1]+hex[1]+hex[2]+hex[2] if hex.length < 6
    rgb = '#'
    for i in [0..2]
        c = parseInt (hex.substr i*2, 2), 16
        c = Math.round(Math.min(Math.max(0, c + c*lum), 255)).toString(16)
        rgb += ('00' + c).substr c.length
    rgb

preloadedSound = (src) ->
    audio = new Audio src
    audio.preload = true
    audio

wololo = preloadedSound 'snd/wololo.mp3'
signature = document.getElementById 'signature'
signature.onclick = () ->

    wololo.play()
    wololo = preloadedSound 'snd/wololo.mp3'

    #random chance of rick roll ftw
    if Math.random() < 0.05

getRandomLabel = ->
    labels[Math.floor(Math.random() * labels.length)]

replaceHTML = (id, lambda) ->
    document.getElementById id
    .innerHTML = lambda()

replaceHTML 'say-my-name', getRandomName


