// DBX3.0 :: Docking Boxes (dbx) >>> Remote Controls
// *****************************************************
// DOM scripting by brothercake -- http://www.brothercake.com/
// GNU Lesser General Public License -- http://www.gnu.org/licenses/lgpl.html
//******************************************************
dbxGroup.prototype._getBoxIndex = function(ref){var collection = [this];for(i=0; i<collection.length; i++){for(var j in collection[i].boxes){if(!dbx.unwanted(collection[i].boxes, j)){if(ref == collection[i].boxes[j]){return j;}}}}return null;};dbxGroup.prototype.toggle = function(ref, state){if(!dbx.supported || typeof ref == 'undefined') { return false; }if(typeof ref == 'object'){ref = this._getBoxIndex(ref);if(!ref) { return false; }}if(typeof state == 'undefined') { state = null; }switch(state){case 'open' : state = true; break;case 'close' : state = false; break;case 'toggle' : state = null; break;}state = state === true ? false : state === false ? true : state;var collection = [];if(ref == '*'){for(var i in this.boxes){if(!dbx.unwanted(this.boxes, i)){if(typeof this.buttons[i] != 'undefined'){collection.push(this.buttons[i]);}}}}else{if(typeof this.boxes[ref] != 'undefined' && typeof this.buttons[ref] != 'undefined'){collection.push(this.buttons[ref]);}}if(collection.length == 0) { return false; }for(var i=0; i<collection.length; i++){if(state !== null && collection[i].className.indexOf('dbx-toggle-' + (state ? 'closed' : 'open')) != -1){var result = false;}else{this.toggleBoxState(collection[i], true, true, state);result = true;}}if(collection.length == 1) { return result; }else { return true; }};dbxGroup.prototype.move = function(ref, direction){if(!dbx.supported || typeof ref == 'undefined') { return false; }if(typeof ref == 'object'){ref = this._getBoxIndex(ref);if(!ref) { return false; }}if(typeof direction == 'undefined') { direction = true; }if(typeof direction == 'string') { direction = direction.toLowerCase(); }if(this.orientation != 'freeform'){direction = direction.split('-')[0];switch(direction){case 'up' : case 'left' : case 'n' : case 'w' : case 'north' :case 'west' : direction = false; break;case 'down' : case 'right' : case 's' : case 'e' : case 'south' : case 'east' :direction = true; break;}}else{switch(direction){case 'up' :case 'north' :direction = 'N';break;case 'up-right' :case 'right-up' :case 'north-east' :case 'ne' :direction = 'Ne';break;case 'right' :case 'east' :direction = 'E';break;case 'right-down' :case 'down-right' :case 'south-east' :case 'se' :direction = 'Se';break;case 'down' :case 'south' :direction = 'S';break;case 'down-left' :case 'left-down' :case 'south-west' :case 'sw' :direction = 'Sw';break;case 'left' :case 'west' :direction = 'W';break;case 'up-left' :case 'left-up' :case 'north-west' :case 'nw' :direction = 'Nw';break;}}if(typeof this.boxes[ref] != 'undefined'){var button = typeof this.buttons[ref] != 'undefined' ? this.buttons[ref] : this.boxes[ref];if(this.orientation != 'freeform'){direction = this.orientation == 'vertical'? direction == true ? 'S' : 'N': direction == true ? 'E' : 'W';}return this.moveBoxByKeyboard(null, button, this.boxes[ref], direction, false, false);}return false;};dbxGroup.prototype.swap = function(ref1, ref2){if(!dbx.supported || typeof ref1 == 'undefined' || typeof ref2 == 'undefined' || this.orientation != 'freeform') { return false; }if(typeof ref1 == 'object'){ref1 = this._getBoxIndex(ref1);if(!ref1) { return false; }}if(typeof ref2 == 'object'){ref2 = this._getBoxIndex(ref2);if(!ref2) { return false; }}if(typeof this.boxes[ref1] != 'undefined' && typeof this.boxes[ref2] != 'undefined'){var button = typeof this.buttons[ref1] != 'undefined' ? this.buttons[ref1] : this.boxes[ref1];if(ref1 != ref2){dbx.dbxobject = this;dbx.group = this.container;dbx.sourcebox = this.boxes[ref1];dbx.event = null;if(typeof dbx.onboxdrag == 'undefined' || dbx.onboxdrag()){this.swapTwoBoxes(this.boxes[ref1], this.boxes[ref2], button, false);return true;}}return false;}return false;};dbxGroup.prototype.insert = function(ref1, option, ref2){for(var args = [], i=0; i<arguments.length; i++) { args.push(arguments[i]); }if(!dbx.supported || typeof ref1 == 'undefined' || this.orientation != 'freeform') { return null; }if(typeof option == 'undefined') { var option = true; }var targets = {'ref1' : null,'ref2' : null,'group' : this};switch(option){case 'before' : option = true; break;case 'after' : option = false; break;}if(option != true && option != false) { option = true; }if(typeof ref2 == 'undefined' || ref2 == null){if(option == true){ref2 = dbx.getSiblingBox(this.container.firstChild, 'nextSibling');}else{ref2 = dbx.getSiblingBox(this.container.lastChild, 'previousSibling');}args[2] = this._getBoxIndex(ref2);}if(typeof ref1 == 'object'){ref1 = this._getBoxIndex(ref1);if(!ref1) { return null; }}if(typeof ref2 == 'object'){ref2 = this._getBoxIndex(ref2);if(!ref2) { return null; }}for(i=0; i<=2; i+=2){var ref = i == 0 ? 'ref1' : 'ref2';if(typeof this.boxes[args[i]] != 'undefined'){var tmp = this.boxes[args[i]];targets[ref] = option || ref == 'ref1' ? tmp : dbx.getSiblingBox(tmp, 'nextSibling');}}if(!targets.ref1 || !targets.ref2) { return null; }var add = false, pointer = 0, theboxes = [], visiboxes = [];for(i in this.boxes){if(dbx.unwanted(this.boxes, i)) { continue; }theboxes.push(this.boxes[i]);}for(i=0; i<theboxes.length; i++){if(theboxes[i] == targets.ref1) { continue; }visiboxes.push(theboxes[i]); }if(targets.ref2 != dbx.getSiblingBox(targets.ref1, 'nextSibling') && targets.ref2 != targets.ref1){dbx.dbxobject = targets.group;dbx.group = targets.group.container;dbx.sourcebox = targets.ref1;dbx.event = null;if(typeof dbx.onboxdrag == 'undefined' || dbx.onboxdrag()){if(targets.group.resolution > 0){targets.ref1.style.visibility = 'hidden';if(typeof visiboxes != 'undefined'){var visiposes = [];for(i=0; i<visiboxes.length; i++){visiposes.push({'x' : visiboxes[i].offsetLeft,'y' : visiboxes[i].offsetTop});}}var beforepos = { 'x' : targets.ref1.offsetLeft, 'y' : targets.ref1.offsetTop };}{targets.group.container.insertBefore(targets.ref1, targets.ref2);targets.group.regenerateBoxOrder();var clone = targets.ref1;}if(targets.group.resolution > 0){if(typeof visiboxes != 'undefined' && visiboxes.length > 0){for(i=0; i<visiboxes.length; i++){new dbxAnimator(targets.group, visiboxes[i], visiposes[i], targets.group.resolution, true, null, false);}}new dbxAnimator(targets.group, clone, beforepos, targets.group.resolution, true, null, false);}return targets.group;}return false;}return null;};