         
     # TODO: Handle denials, in the case of denial, just fail
     
+handleData = (data) ->
+    {type, content} = data
+
+    switch type
+        when "url"
+            a = $("<iframe src='#{content}'></iframe>")
+            a.css width: percentOfWidth(100) - 100, height: percentOfHeight(100) - 100
+        when "youtube"
+            time = if data.time then data.time else ""
+            a = $("<iframe src='http://www.youtube.com/embed/#{content}?autoplay=1\#t=#{time}' frameborder='0' autoplay=true allowfullscreen></iframe>")
+            a.css width: percentOfWidth(100) - 100, height: percentOfHeight(100) - 100
+
+        when "image"
+            $("body").append $("<img src='#{content}'></img>")
+        when "spotify"
+            document.location = "spotify:track:#{content}"
+        else
+            alert("Unknown")
+            return
+    a.hide()
+    a.appendTo('.content')
+    a.fadeIn('slow')
+
 socket.on 'frisbee', (data) ->
-    console.log data
-    {type, content} = data
     console.log data
 
     throwFrisbee ->
-        switch type
-            when "url"
-                a = $("<iframe src='#{content}'></iframe>")
-                a.css width: percentOfWidth(100) - 100, height: percentOfHeight(100) - 100
-            when "youtube"
-                a = $("<iframe src='http://www.youtube.com/embed/#{content}?autoplay=1' frameborder='0' autoplay=true allowfullscreen></iframe>")
-                a.css width: percentOfWidth(100) - 100, height: percentOfHeight(100) - 100
-
-            when "image"
-                $("body").append $("<img src='#{content}'></img>")
-            when "spotify"
-                document.location = "spotify:track:#{content}"
-            else
-                alert("Unknown")
-                return
-        a.hide()
-        a.appendTo('.content')
-        a.fadeIn('slow')
-
+        handleData data
 
 
 throwFrisbee = window.throwFrisbee = (cb) ->

    cloud.animate {left: -250}, 60000, 'linear', ->
        cloud.remove()

startAnimation = ->
    createCloud()
    window.setInterval ->

        , 200

$ ->
    search = window.location.search
    if search
        YT_SEARCH = ///youtube=([^&]*)///
        result = YT_SEARCH.exec search
        s = result[1]
        s = s.replace(',', ' ')

        YT_TIME = ///time=([^&]*)///
        result = YT_TIME.exec search
        time = result[1]

        console.log 'hey'

        performYTSearch s, (videoId) ->
            throwFrisbee ->
                handleData type: 'youtube', content: videoId, time: time
    else
        startAnimation()





