Index: Dev/trunk/js/sequencerScripts.js
===================================================================
--- Dev/trunk/js/sequencerScripts.js	(revision 167)
+++ Dev/trunk/js/sequencerScripts.js	(revision 168)
@@ -3,4 +3,19 @@
  * and open the template in the editor.
  */
+var timeDiff  =  {
+    setStartTime:function (){
+        d = new Date();
+        time  = d.getTime();
+    },
+
+    getDiff:function (){
+        d = new Date();
+        return (d.getTime()-time);
+    }
+}
+
+
+
+
 
 function IsItemSelected(check, target) {
@@ -36,4 +51,5 @@
     var pipelineType = document.getElementById("pipelineTypeField");
     var pipelineUpdated = document.getElementById("pipelineUpdatedField");
+    document.getElementById("numSteps").value++;
     
     newAjaxRequest(c, u, function(result){
@@ -70,4 +86,6 @@
 
 function selectStep(uid) {
+    /*
+    
     var nodes = document.getElementById("seqContentWrapper").childNodes;
     for (var i = 0; i < nodes.length; i++) {     //loop through childNodes. Skip first node (whitespace)
@@ -86,9 +104,44 @@
         }
     }
-    
-    // Update selected step field with uid of currently selected step.
+    */
+    // Hier is een snellere manier voor!
+    var element = document.getElementById(uid);
+    var prevElement = document.getElementById(document.getElementById("selectedStepField").value);
+    
+    if (!element || !hasClass(element, "displayStep")) {
+        return;
+    }
+    // misschien nog checks inbouwen of het echt wel een element is?
     var selectedStepField = document.getElementById("selectedStepField");
-    selectedStepField.value = uid;
-    
+    if (!hasClass(element, "selected")) {
+        if (prevElement) {
+            removeClass(prevElement, "selected");
+        }
+        addClass(element, "selected");
+        selectedStepField.value = uid;
+        
+        var pl = stringToArray(document.getElementById("pipelineStringField").value, ",");
+        var plType = stringToArray(document.getElementById("pipelineTypeField").value, ",");
+        var type = plType[pl.indexOf(uid)];
+        ajaxInfoRequest(uid, document.getElementById("infoPanelContent"), type);
+        
+        
+    }
+    else {
+        deselectStep(uid);
+    }
+    
+    
+// Update selected step field with uid of currently selected step.
+    
+    
+}
+
+function deselectStep(uid) {
+    var field = document.getElementById("selectedStepField");
+    field.value = "";
+    var element = document.getElementById(uid);
+    removeClass(element, "selected");
+    document.getElementById("infoPanelContent").innerHTML = "";
 }
                                                                             
@@ -148,7 +201,7 @@
 }
 
-function ajaxInfoRequest(id, el) {
-    var uid = id;
+function ajaxInfoRequest(uid, el, type) {
     var c = "uid="+uid;
+    c += "&type="+type;
     var u = "getInfo.php";
     newAjaxRequest(c, u, function(result) {
@@ -169,77 +222,110 @@
 }
 
-function drawSteps() {
-    
-}
-
-function updateSequencer() {
+
+function updateSequencer(firstLoad) {
+    // Load hidden field values
     var plString = document.getElementById("pipelineStringField").value;
     var plTypeString = document.getElementById("pipelineTypeField").value;
     var plUpdatedString = document.getElementById("pipelineUpdatedField").value;
-    
-    
-    var pl = stringToArray(plString, ",");    
-    var plType = stringToArray(plTypeString, ",");    
-    var plUpdated = stringToArray(plUpdatedString, ",");
-    
-    var count = pl.length;
-    
-    document.getElementById("numSteps").value = count;
-    
-    for (var i = 0; i < pl.length; i++) {   // loop through pipeline contents
-        if (plUpdated[i] == "0") {   // if the element is not up to date
-            // first remove the step representation from the sequencer
+    var count = document.getElementById("numSteps").value;
+    
+    if (count < 1) {
+        return;
+    }
+    // If this is on page-load time
+    if (firstLoad == true) {
+        requestString = plString.slice(0, -1);
+        requestString = requestString.replace(/,/g, ",divider,");
+        newAjaxRequest("uids="+requestString, "returnStep.php", function(result) {
             var seqContent = document.getElementById("seqContentWrapper");
-            var element = document.getElementById(pl[i]);
-            if (element == null) {
-                element = document.createElement("div");
-                element.name = "placeholder";
-                seqContent.appendChild(element);
+            seqContent.innerHTML = result.responseText;
+        }, true);
+        
+        plUpdatedString = "";
+        for (var i = 0; i < plString.split(",").length-1; i++) {
+            plUpdatedString += "1,";
+        }
+        
+        document.getElementById("pipelineUpdatedField").value = plUpdatedString;
+    }
+    else {      // if not
+        var pl = stringToArray(plString, ",");    
+        var plType = stringToArray(plTypeString, ",");    
+        var plUpdated = stringToArray(plUpdatedString, ",");
+    
+        var count = pl.length;
+    
+        document.getElementById("numSteps").value = count;
+        var seqContent = document.getElementById("seqContentWrapper");
+        if (seqContent.childNodes.length > (2*count)-1) {
+            seqContent.removeChild(seqContent.childNodes[0]);
+            
+        }
+        
+        
+        for (var i = 0; i < pl.length; i++) {   // loop through pipeline contents
+            if (plUpdated[i] == "0") {   // if the element is not up to date
+                // first remove the step representation from the sequencer
+                //timeDiff.setStartTime();
+                
+            
+                // IMPROVISE !!!!!!!!!!
+                var elementByIndex = seqContent.childNodes[2*i];    // works with moved steps
+                var elementById = document.getElementById(pl[i]);   // works with ???, not moved steps though... Keeping this in here for future bugfixing. This value is not currently used.
+                var element = elementByIndex;
+            
+            
+                // END IMPROVISE !!!!!!!!!!!!
+                if (element == null) {
+                    element = document.createElement("div");
+                    element.name = "placeholder";
+                    seqContent.appendChild(element);
+                }
+                if (element.nextSibling) {
+                    var nextElement = element.nextSibling;
+                }
+                else {
+                    var nextElement = document.createElement("div");
+                    nextElement.name = "placeholderNext";
+                    seqContent.appendChild(nextElement);
+                }
+            
+                // now request a new step representation and insert it after previousElement
+                var holderDiv = document.createElement("div");
+                var requestString = "uids="+pl[i];
+            
+                if (plType[i]) {
+                    requestString += "&types="+plType[i];
+                }
+                // globally declare newDiv so it can be passed to the updateDividers function
+                var newDiv;
+            
+                newAjaxRequest(requestString, "returnStep.php", function(result) {
+                    holderDiv.innerHTML = result.responseText;
+                    newDiv = holderDiv.childNodes[1];            
+                    seqContent.replaceChild(newDiv, element);
+                    if (nextElement.name == "placeholderNext") {
+                        seqContent.removeChild(nextElement);
+                    }
+                    plUpdated[i] = "1";
+                }, false);
+            
+                       
+                // ALTERNATIVE METHOD TO REPLACECHILD!!!
+                //seqContent.removeChild(element);
+                //seqContent.insertBefore(newDiv, nextElement);
+            
+                // Now check if dividers are necessary.
+            
+                //alert("INSERT CODE FOR UPDATEDIVIDERS HERE!");
+                //alert(timeDiff.getDiff());
+                updateDividers(newDiv);
             }
-            if (element.nextSibling) {
-                var nextElement = element.nextSibling;
-            }
-            else {
-                var nextElement = document.createElement("div");
-                nextElement.name = "placeholderNext";
-                seqContent.appendChild(nextElement);
-            }
-            
-            // now request a new step representation and insert it after previousElement
-            var holderDiv = document.createElement("div");
-            var requestString = "uids="+pl[i];
-            
-            if (plType[i]) {
-                requestString += "&types="+plType[i];
-            }
-            // globally declare newDiv so it can be passed to the updateDividers function
-            var newDiv;
-            
-            newAjaxRequest(requestString, "returnStep.php", function(result) {
-                holderDiv.innerHTML = result.responseText;
-                newDiv = holderDiv.childNodes[1];            
-                seqContent.replaceChild(newDiv, element);
-                if (nextElement.name == "placeholderNext") {
-                    seqContent.removeChild(nextElement);
-                }
-                plUpdated[i] = "1";
-            }, false);
-            
-                       
-            // ALTERNATIVE METHOD TO REPLACECHILD!!!
-            //seqContent.removeChild(element);
-            //seqContent.insertBefore(newDiv, nextElement);
-            
-            // Now check if dividers are necessary.
-            
-            //alert("INSERT CODE FOR UPDATEDIVIDERS HERE!");
-            updateDividers(newDiv);
-        }
-    }
-    
-    // afterwards, convert the arrays back to strings and set to appropriate fields
-    var newUpdatedString = arrayToString(plUpdated, ",");
-    document.getElementById("pipelineUpdatedField").value = newUpdatedString;
-    
+        }
+    
+        // afterwards, convert the arrays back to strings and set to appropriate fields
+        var newUpdatedString = arrayToString(plUpdated, ",");
+        document.getElementById("pipelineUpdatedField").value = newUpdatedString;
+    }
 }
 
@@ -366,5 +452,5 @@
     // eerst saven, dan de object type zoeken in de typelist, dan redirecten naar de goede pagina
     savePipeline(false);
-    debugger;
+    
     var pipeline = document.getElementById("pipelineStringField").value;
     var pipelineTypes = document.getElementById("pipelineTypeField").value;
@@ -375,5 +461,5 @@
     
     var postForm = document.createElement("form");
-    postForm.action = stepType.toLowerCase()+"Editor.php";
+    postForm.action = stepType.toLowerCase()+"Editor.php";      //redirect to "type"editor.php
     postForm.method = "POST";
     var objectUid = document.createElement("input");
@@ -388,5 +474,5 @@
 function moveStep (direction) {
     // misschien maar eens een loadhiddenfields functie maken voor deze meuk?
-    debugger;
+    
     var selectedStep = document.getElementById("selectedStepField").value;
     
@@ -402,7 +488,14 @@
     
     var id = pipeline.indexOf(selectedStep);
-    // Dit werkt niet, hij replaced dingen de verkeerde kant op. Lelijke versie met placeholder variables maar weer doen?
-    pipeline[id] = pipeline.splice(pipeline[id+direction], 1, pipeline[id])[0];
-    pipelineTypes[id] = pipelineTypes.splice(pipelineTypes[id+direction], 1, pipelineTypes[id])[0];
+    if ((id == 0 && direction == -1) || (id == pipeline.length-1 && direction == 1)){
+        alert("Cannot move out of bounds!");
+        return;
+    }
+    var tempString = pipeline[id], tempType = pipelineTypes[id];
+    
+    pipeline[id] = pipeline[id+direction];
+    pipelineTypes[id] = pipelineTypes[id+direction];
+    pipeline[id+direction] = tempString;
+    pipelineTypes[id+direction] = tempType;
     updated[id] = "0";
     updated[id+direction] = "0";
@@ -417,5 +510,5 @@
     updateSequencer();
     
-    
-    
-}
+    // Then reselect the previously selected step
+    addClass(document.getElementById(selectedStep), "selected");
+}
