Index: Dev/branches/jos-branch/js/sequencerScripts.js
===================================================================
--- Dev/branches/jos-branch/js/sequencerScripts.js	(revision 233)
+++ Dev/branches/jos-branch/js/sequencerScripts.js	(revision 237)
@@ -123,4 +123,30 @@
 }
 
+function setSequencerSize() {
+    var seqContent = ge("seqContent");
+    switch (sequencer.settings.content.orientation.toLowerCase()) {
+        case "vertical":
+            var availHeight = window.innerHeight;
+            var yOffset = getPos(seqContent).Y;
+            var bottomControlsHeight = 36;
+            var bottomMargin = 12;
+            sequencer.settings.content.height = (availHeight - yOffset - bottomControlsHeight - bottomMargin);
+            sequencer.settings.content.width = 665;
+            seqContent.style.height = sequencer.settings.content.height+"px";
+            seqContent.style.width = sequencer.settings.content.width+"px";
+            addClass(seqContent, "vertical");
+            break;
+        case "horizontal":
+            sequencer.settings.content.width = 800;
+            sequencer.settings.content.height = 125;
+            seqContent.style.height = sequencer.settings.content.height+"px";
+            seqContent.style.width = sequencer.settings.content.width+"px";
+            addClass(seqContent, "horizontal");
+            break;
+        default:
+            break;
+    }
+}
+
 function initSequencer() {
     // Called from loadSequencer(). Sets sequencer.settings properties depending on content type and values passed by PHP in hidden fields (currently only one), then removes these fields.
@@ -129,26 +155,12 @@
     // load settings fields first
     var fContentType = ge("sContentTypeField");
-    var content = ge("seqContent");
-    //sequencer.settings.content.contentType = fContentType.value.toLowerCase();
     sequencer.settings.content.contentType = fContentType.value;
     //Then select settings from a few presets
-    
     switch (sequencer.settings.content.contentType.toLowerCase()) {
         case "session":
             sequencer.settings.content.orientation = "horizontal";
-            sequencer.settings.content.width = 800;
-            sequencer.settings.content.height = 125;
-            content.style.width = sequencer.settings.content.width+"px";
-            content.style.height = sequencer.settings.content.height+"px";
-            addClass(content, "horizontal");
             break;
         case "survey":
             sequencer.settings.content.orientation = "vertical";
-            sequencer.settings.content.width = 650;     //guesstimated
-            var roomH = screen.availHeight;
-            sequencer.settings.content.height = roomH - 200;
-            content.style.width = sequencer.settings.content.width+"px";
-            content.style.height = sequencer.settings.content.height+"px";
-            addClass(content, "vertical");
             break;
         default:
@@ -156,4 +168,6 @@
     }
     fContentType.parentNode.parentNode.removeChild(fContentType.parentNode);
+    
+    window.addEventListener("load", setSequencerSize, true);
 }
 
@@ -230,5 +244,5 @@
         requestString = "args="+JSON.stringify(args);
         newAjaxRequest(requestString, "returnObjectDisplay.php", function(result){
-            console.log(result.responseText);
+            //console.log(result.responseText);
             insertNewObjects(result.responseText, needsUpdating);
         }, true);
@@ -279,5 +293,5 @@
         requestString = "args="+JSON.stringify(args);
         newAjaxRequest(requestString, "returnObjectDisplay.php", function(result){
-            console.log(result.responseText);
+            //console.log(result.responseText);
             content.removeChild(loadingGif);
             insertNewObjects(result.responseText, needsUpdating);
@@ -392,5 +406,5 @@
     //console.log(responseText);
     // Container function that calls different insertNewX() functions depending on content type. Called from updateSequencer().
-    console.log(responseText);
+    //console.log(responseText);
     var response = JSON.parse(responseText);
     // For now I assume that only one type of element can be displayed in the editor at one time. Therefore, the type of response[0] is the type of all elements of response.
@@ -416,5 +430,5 @@
         
     newAjaxRequest(c, u, function(result) {
-        console.log(result.responseText);
+        //console.log(result.responseText);
         sequencer.survey.questions.uids.push(removeNL(result.responseText));
         sequencer.survey.questions.upToDate.push(false);
@@ -434,5 +448,5 @@
          */
     if (!response || !response.length > 0) return;
-    console.log(response);
+    //console.log(response);
     
     var content = ge("seqContentWrapper");
@@ -524,4 +538,6 @@
 
 function insertNewQuestions(response, needsUpdating) {
+    //TODO: QuestionDisplay ook classbased maken zoals de questionEditor?
+    
     //Code that inserts or replaces new object displays in the sequencer. Question version.
     var content = ge("seqContentWrapper");
@@ -571,8 +587,19 @@
         removeButton.className = "smallButton";
         editButton.addEventListener("click", function(e){
-            alert('Editing not yet supported!');
+            var targ;
+            if (!e) e = window.event;
+            if (e.target) targ = e.target;
+            else if (e.srcElement) targ = e.srcElement;
+            
+            do {
+                targ = targ.parentNode;
+            } while (!hasClass(targ, "question"));
+            
+            questionEditor.editQuestion(targ.id);
+            e.stopPropagation();
         }, false);
         removeButton.addEventListener("click", function(e){
             alert('Removing not yet supported!');
+            e.stopPropagation();
         }, false);
         controlsDiv.appendChild(editButton);
@@ -596,5 +623,17 @@
             }
             else {
-                content.replaceChild(frameDiv, content.childNodes[needsUpdating[j][0]*2]);
+                if (content.childNodes[needsUpdating[j][0]*2]) {
+                    content.replaceChild(frameDiv, content.childNodes[needsUpdating[j][0]*2]);
+                }
+                else {
+                    content.appendChild(frameDiv);
+                    // HACK TIME!
+                    for (var s = 0; s < content.childNodes.length; s++) {
+                        if (hasClass(content.childNodes[s], "loading")) {
+                            content.childNodes[s].parentNode.removeChild(content.childNodes[s]);
+                        }
+                    }
+                    // Serieus, dit moet beter...
+                }
             }
             sequencer.survey.questions.upToDate[needsUpdating[j][0]] = true;
@@ -622,5 +661,5 @@
             request.questions.uids = sequencer.survey.questions.uids;
             requestString = "args="+JSON.stringify(request);
-            console.log(request);
+            //console.log(request);
             newAjaxRequest(requestString, url, function(result){
                 console.log(result.responseText);
@@ -658,5 +697,5 @@
 function selectStep(uid) {
     // Called from clickStep(), manages CSS class assignment and updating of state variables. Also calls for info panel update.
-    
+    debugger;
     var element = ge(uid);
     if (element) {
@@ -674,5 +713,5 @@
                 break;
         }
-        (type != "survey") ? ajaxInfoRequest(uid, ge("infoPanelContent"), type) : type=type /*This does nothing*/;
+        (type != "Question") ? ajaxInfoRequest(uid, ge("infoPanelContent"), type) : type=type /*This does nothing*/;
         sequencer.state.selectedObject.uid = uid;
         sequencer.state.selectedObject.index = null;  //Don't know how to do this yet.
@@ -718,8 +757,8 @@
     requestString += "&sessionUid=";
     requestString += sequencer.session.uid;
-    console.log(requestString);
+    //console.log(requestString);
     newAjaxRequest(requestString, "savesession.php", function(result){
-        console.log(result.responseText);
-    }, true);
+        //console.log(result.responseText);
+        }, true);
 }
 
