function DefaultEdgeView(graphView, edge, style, el1, el2)
{

this.id = edge.getId();

this.graphView = graphView;
this.style = style;
this.edgeData = edge;
this.el1 = el1;
this.el2 = el2;

this.hide = false;
this.ghosted = false;
this.currentColor = null;
this.crossfade = this.style.isCrossfade();
if ( this.edgeData.getWeight() < 100 ) this.thickness = parseInt( parseInt(this.edgeData.getWeight()) / 20 ) + 1;
else this.thickness = 5;

this.elements = new Array();
this.indexElements = new Array();
this.imgElements = new Array();
this.multicoloredImgElements = new Array();
this.crossfadeElements = new Array();
this.arrowHead = null;
this.rasterLine = null;
this.resizer = null;
this.m = null;
this.x = null;
this.y = null;
this.w = null;
this.h = null;
this.htmlElement = this.createHTMLElement(edge,style,el1,el2);
this.style.registerView(this);
this.edgeData.register(this);

this.toolTipShown = false;
this.toolTipShowed = false;
this.toolTipWidth;
this.createToolTip();
this.labelDiv = document.createElement("span");
this.labelDiv.appendChild(document.createTextNode(this.edgeData.getLabel()));
this.showLabel(this.edgeData.isLabelVisible());
return this;
}
DefaultEdgeView.prototype.type = "DefaultEdgeView";
DefaultEdgeView.prototype.createToolTip=function()
{
this.typeSpan = document.createElement("span");
this.typeSpan.appendChild(document.createTextNode("<<" + this.style.getName() + ">>"));
this.labelSpan = document.createElement("span");
this.labelSpan.appendChild(document.createTextNode("Label: " + this.edgeData.getLabel()));
this.directedSpan = document.createElement("span");
if ( this.edgeData.isDirected ) this.directedSpan.appendChild(document.createTextNode("directed"));
else this.directedSpan.appendChild(document.createTextNode("undirected"));
this.weightSpan = document.createElement("span");
this.weightSpan.appendChild(document.createTextNode("Weight: " + this.edgeData.getWeight()));
$(this.typeSpan).css({'position':'absolute','font-size':'small','-moz-border-radius-topleft': '7px','-moz-border-radius-topright':'7px','border-top':'2px solid silver', 'border-left':'2px solid silver', 'border-right':'2px solid silver'});
$(this.labelSpan).css({'position':'absolute','font-size':'small','border-left':'2px solid silver', 'border-right':'2px solid silver'});
$(this.weightSpan).css({'position':'absolute','font-size':'small','border-left':'2px solid silver', 'border-right':'2px solid silver'});
$(this.directedSpan).css({'position':'absolute','font-size':'small','-moz-border-radius-bottomleft': '7px', '-moz-border-radius-bottomright': '7px', 'border-bottom':'2px solid silver', 'border-left':'2px solid silver', 'border-right':'2px solid silver'});
this.toolTipShowed = false;
}
DefaultEdgeView.prototype.showToolTip=function(x,y)
{
if ( !this.toolTipShown ) {
this.graphView.canvas.appendChild(this.typeSpan);
this.graphView.canvas.appendChild(this.labelSpan);
this.graphView.canvas.appendChild(this.weightSpan);
this.graphView.canvas.appendChild(this.directedSpan);
this.toolTipShown = true;
if ( !this.toolTipShowed ) {
if ( this.typeSpan.offsetWidth >= this.labelSpan.offsetWidth) {
this.toolTipWidth = this.typeSpan.offsetWidth;
} else if ( this.labelSpan.offsetWidth >= this.weightSpan.offsetWidth  ) {
this.toolTipWidth = this.labelSpan.offsetWidth;
} else {
this.toolTipWidth = this.weightSpan.offsetWidth;
}
this.toolTipShowed = true;
}
}
$(this.typeSpan  ).css({'left':x+'px', 'top':y+20+'px', 'z-index':this.graphView.maxZ+1, 'width':this.toolTipWidth+'px', 'height':'20px', 'background-color':'white'});
$(this.labelSpan ).css({'left':x+'px', 'top':y+40+'px', 'z-index':this.graphView.maxZ+1, 'width':this.toolTipWidth+'px', 'height':'20px', 'background-color':'white'});
$(this.weightSpan).css({'left':x+'px', 'top':y+60+'px', 'z-index':this.graphView.maxZ+1, 'width':this.toolTipWidth+'px', 'height':'20px', 'background-color':'white'});
$(this.directedSpan).css({'left':x+'px', 'top':y+80+'px', 'z-index':this.graphView.maxZ+1, 'width':this.toolTipWidth+'px', 'height':'20px', 'background-color':'white'});
}
DefaultEdgeView.prototype.hideToolTip=function()
{
if ( this.toolTipShown ) {
this.graphView.canvas.removeChild(this.typeSpan);
this.graphView.canvas.removeChild(this.labelSpan);
this.graphView.canvas.removeChild(this.weightSpan);
this.graphView.canvas.removeChild(this.directedSpan);
this.toolTipShown = false;
}
}
DefaultEdgeView.prototype.createHTMLElement=function(edge,style,el1,el2)
{
var direction;
var aimElement;
var startElement;
if ( this.style.isMulticolored() ) {
this.thickness = this.style.getInactiveColorSet().length;
this.multicolored = true;
this.crossfade = false;
} else {
this.multicolored = false;
}
if ( el1.middlePoint.y <  el2.middlePoint.y ) {
if ( el1.nodeData.getId() == edge.getNodeId2() ) {
direction = "north";
aimElement = el1;
startElement = el2;
} else {
direction = "south";
aimElement = el2;
startElement = el1;
}
var x1 = el1.middlePoint.x; var x2 = el2.middlePoint.x;
var y1 = el1.middlePoint.y; var y2 = el2.middlePoint.y;
} else {
if ( el2.nodeData.getId() == edge.getNodeId2() ) {
direction = "north";
aimElement = el2;
startElement = el1;
} else {
direction = "south";
aimElement = el1;
startElement = el2;
}
var x1 = el2.middlePoint.x; var x2 = el1.middlePoint.x;
var y1 = el2.middlePoint.y; var y2 = el1.middlePoint.y;
}
var xDiff = x2 - x1;
var yDiff = y2 - y1;
if ( xDiff != 0 ) this.m = yDiff / xDiff;
else this.m = Number.MAX_VALUE;
if ( this.m == 0 && aimElement.middlePoint.x > startElement.middlePoint.x ) direction = "south";
if ( this.htmlElement == null ) {
var div = document.createElement("div");
div.id = edge.getId();
} else {
var children = this.htmlElement.childNodes;
for ( var i = children.length - 1; i >= 0; i-- ) 
this.htmlElement.removeChild(this.htmlElement.childNodes[i]);
var div = this.htmlElement;
}
if ( style.isCrossfade() ) this.crossfadeColor = this.graphView.edgePath + "/" + style.getCrossfadeColor()[0];
if ( edge.isActive() ){
var file = this.graphView.edgePath + "/" + style.getActiveColor()[0];
this.currentColor = style.getActiveColor();
} else {
var file = this.graphView.edgePath + "/" + style.getInactiveColor(0)[0];
this.currentColor = style.getInactiveColor(0);
}
if ( edge.isGhosted() ) {
var file = this.graphView.edgePath + "/" + style.getGhostColor()[0];
this.currentColor = style.getGhostColor();
}



this.elements = new Array();
if ( 0 < this.m && this.m <= 1 ) {
this.resizer = "width";
var width = xDiff;var height = yDiff;var xn = x1;var yn = y1;
if ( !this.crossfade )
for ( var i = 0; i < this.thickness; i++ ) {
if ( !this.multicolored ) div = this.create(xDiff, yDiff, this.resizer, this.m, i, file + "2", edge, div);
else {
if ( !edge.isActive() ) {
var file = this.graphView.edgePath + "/" + style.getInactiveColor(i)[0];
this.currentColor = style.getInactiveColor();
}
div = this.create(xDiff, yDiff, this.resizer, this.m, i, file + "2", edge, div);
}
}
else
for ( var i = 0; i < 2; i++ ) 
div = this.create(xDiff, yDiff, this.resizer, this.m, i, file + "2", edge, div);
this.arrowhead = this.addArrowhead(this.elements, div, this.m, width, height, direction, aimElement, startElement, this.rasterLine);
if ( edge.isDirected() ) div.appendChild(this.arrowhead);
} else if ( this.m > 1 ){
this.resizer = "height";
var width = xDiff;var height = yDiff;var xn = x1;var yn = y1;
if ( !this.crossfade ) 
for ( var i = 0; i < this.thickness; i++ ) {
if ( !this.multicolored ) div = this.create(yDiff, xDiff, this.resizer, this.m, i, file + "2", edge, div);
else {
if ( !edge.isActive() ) {
var file = this.graphView.edgePath + "/" + style.getInactiveColor(i)[0];
this.currentColor = style.getInactiveColor();
}
div = this.create(yDiff, xDiff, this.resizer, this.m, i, file + "2", edge, div);
}
}
else 
for ( var i = 0; i < 2; i++ ) 
div = this.create(yDiff, xDiff, this.resizer, this.m, i, file + "2", edge, div);
this.arrowhead = this.addArrowhead(this.elements, div, this.m, width, height, direction, aimElement, startElement, this.rasterLine);
if ( edge.isDirected() ) div.appendChild(this.arrowhead);
} else if ( this.m < -1 ) {
this.resizer = "height";
var width = -xDiff;var height = yDiff;var xn = x2;var yn = y1;
if ( !this.crossfade )
for ( var i = 0; i < this.thickness; i++ ) {
if ( !this.multicolored ) div = this.create(yDiff, -xDiff, this.resizer, this.m, i, file + "1", edge, div);
else {
if ( !edge.isActive() ) {
var file = this.graphView.edgePath + "/" + style.getInactiveColor(i)[0];
this.currentColor = style.getInactiveColor();
}
div = this.create(yDiff, -xDiff, this.resizer, this.m, i, file + "1", edge, div);
}
}
else
for ( var i = 0; i < 2; i++ ) 
div = this.create(yDiff, -xDiff, this.resizer, this.m, i, file + "1", edge, div);
this.arrowhead = this.addArrowhead(this.elements, div,this.m, width, height, direction, aimElement, startElement, this.rasterLine);
if ( edge.isDirected() ) div.appendChild(this.arrowhead);
} else if ( 0 > this.m && this.m >= -1 ) {
this.resizer = "width";
var width = -xDiff;var height = yDiff;
var xn = x2;var yn = y1;
if ( !this.crossfade )
for ( var i = 0; i < this.thickness; i++ ) {
if ( !this.multicolored ) div = this.create(-xDiff, yDiff, this.resizer, this.m, i, file + "1", edge, div);
else {
if ( !edge.isActive() ) {
var file = this.graphView.edgePath + "/" + style.getInactiveColor(i)[0];
this.currentColor = style.getInactiveColor();
}
div = this.create(-xDiff, yDiff, this.resizer, this.m, i, file + "1", edge, div);
}
}
else
for ( var i = 0; i < 2; i++ ) 
div = this.create(-xDiff, yDiff, this.resizer, this.m, i, file + "1", edge, div);
this.arrowhead = this.addArrowhead(this.elements, div,this.m, width, height, direction, aimElement, startElement, this.rasterLine);
if ( edge.isDirected() ) div.appendChild(this.arrowhead);
} else if ( this.m == 0) {
this.resizer = "width";
this.elements = this.getLineElements(0);
div = this.createHTMLElements(this.elements, edge, file + "1");
if ( x1 < x2 ) xDiff = x2 - x1;
else xDiff = x1 - x2;
this.resizeImageElements(this.elements, div, edge, "width", xDiff,  this.m, 0);
if ( x1 > x2 ) var xn = x2;
else var xn = x1;
var yn = y1;
var height = 0;
var width = xDiff;
this.arrowhead = this.addArrowhead(this.elements, div,this.m, xDiff, 1, direction, aimElement, startElement, this.rasterLine);
if ( edge.isDirected() ) div.appendChild(this.arrowhead);
} else if ( this.m == Number.MAX_VALUE ) {
this.resizer = "height";
this.elements = this.getLineElements(0);
div = this.createHTMLElements(this.elements, edge, file + "1");
this.resizeImageElements(this.elements, div, edge, "height", yDiff,  this.m, 0);
var width = 0; 
var height = yDiff;
this.arrowhead = this.addArrowhead(this.elements, div,this.m, xDiff, 1, direction, aimElement, startElement, this.rasterLine);
if ( edge.isDirected() ) div.appendChild(this.arrowhead);
}
$(div).css({'position': 'absolute', 'width': width + "px", 'height': height + 'px', 'left': xn+'px', 'top': yn+'px'});
this.x = xn;
this.y = yn;
this.w = width;
this.h = height;
return div;
}
DefaultEdgeView.prototype.create=function(xDiff, yDiff, resizer, m, i, path, edge, div)
{
if ( i == 0 ) var shift = 0;else if ( i == 1 ) var shift = 1;else if ( i == 2 ) var shift = -1;else if ( i == 3 ) var shift = 2;else if ( i == 4 ) var shift = -2;
if ( this.crossfade ) var shift = 0;
if ( this.crossfade && i == 1 ) path = this.crossfadeColor + path.charAt(path.length - 1);
var elements = this.getLineElements(yDiff);
div = this.createHTMLElements(elements, edge, path, div);
this.resizeImageElements(elements, div, edge, resizer, xDiff, m, shift);
this.elements.concat(elements);
if ( this.crossfade && i == 1 ) this.crossfadeElements = this.currentImgElements;
return div;
}
DefaultEdgeView.prototype.getLineElements=function(yDiff) 
{
var elements = new Array();
if ( yDiff <= 8 ) {
elements.push(0);
} else {
while ( yDiff > 0 ) {
var temp;
if ( (yDiff - 512 ) >= 0 ) { elements.push(9); temp = 512; }
else if ( (yDiff - 256 ) >= 0 ) { elements.push(8); temp = 256; }
else if ( (yDiff - 128 ) >= 0 ) { elements.push(7); temp = 128; }
else if ( (yDiff - 64 ) >= 0 )  { elements.push(6); temp = 64; }
else if ( (yDiff - 32 ) >= 0 )  { elements.push(5); temp = 32; }
else if ( (yDiff - 16 ) >= 0 )  { elements.push(4); temp = 16; }
else if ( (yDiff - 8 ) >= 0 )   { elements.push(3); temp = 8; }
else if ( (yDiff - 4 ) >= 0 )   { elements.push(2); temp = 4; }
else if ( (yDiff - 2 ) >= 0 )   { elements.push(1); temp = 2; }
else if ( (yDiff - 1 ) >= 0 )   { elements.push(0);temp = 1; }
yDiff = yDiff - temp;
}
}
this.indexElements = this.indexElements.concat(elements);
return elements;
}
DefaultEdgeView.prototype.createHTMLElements=function(elements, edge, style, div)
{
var htmlElements = new Array();
if(div == undefined || div == null)
var div = document.createElement("div");
div.id = edge.getId();
$(div).css('position', 'absolute');
this.currentImgElements = new Array();
for ( var i = 0 ; i < elements.length; i++ ) {
var node = document.createElement("img");
node.setAttribute("src", style + elements[i] + ".gif");
node.style.position = "absolute";
node.id = edge.getId() + "_" + i;
this.imgElements.push(node);
this.currentImgElements.push(node);
div.appendChild(node);
}
if ( this.multicolored ) this.multicoloredImgElements.push(this.currentImgElements);
return div;
}
DefaultEdgeView.prototype.rasterizeLine=function(elements, forcing, xStart, yStart, xEnd, yEnd, result)
{
var line = new Array();
var dx = xEnd - xStart;
var dy = yEnd - yStart;
var x = xStart;
var y = yStart;
line[x] = y;
var i = 0;
if ( forcing = "width" ) {
var fehler = parseInt(dx / 2);
while ( x < xEnd ) {
x++;
fehler = fehler - dy;
if ( fehler < 0 ) {
y++;
fehler += dx;
}
if (result) line[x] = y;
else if (!result) line[y] = x;
}
} else if ( forcing = "height" ) {
var fehler = parseInt(dy / 2);
while ( y < yEnd ) {
y++;
fehler = fehler - dx;
if ( fehler < 0 ) {
x++;
fehler += dy;
}
if (result) line[x] = y;
else if (!result) line[y] = x;
}
}
line[xEnd] = yEnd;
return line;
}
DefaultEdgeView.prototype.resizeImageElements=function(elements, div, edge, resizer, resizeValue, m, shift)
{
var originalLength = 0;
for (var i = 0; i < elements.length; i++) originalLength += (Math.pow(2, elements[i]));
var value = 0;
for ( var i = 0; i < elements.length; i++) value = value + (elements[i] + 1);
if ( m >= 0 ) {
var positionX = 0 + shift; var positionY = 0 - shift;
} else if (0 > m && m >= -1){
var positionX = resizeValue - shift; var positionY = 0 - shift;
} else if ( m < -1 ){
var positionX = originalLength - shift;var positionY = 0 - shift; 
}
var additionalResizeFaktor = 1;
if ( elements.length == 1 && elements[0] == 0 || m == 0 || m == Math.MAX_VALUE ) {
if (resizer == "width") {
this.rasterLine = this.rasterizeLine(elements, "width",0,0, resizeValue, originalLength, true);
var node = div.childNodes[0];
$(node).css({'height':this.thickness + 2 + 'px', 'width':resizeValue + 'px', 'top': '0px', 'left':'0px'});
} else if ( resizer == "height" ) {
this.rasterLine = this.rasterizeLine(elements, "height",0,0, resizeValue, originalLength, true);
var node = div.childNodes[0];
$(node).css({'height':resizeValue + "px", 'width':this.thickness + 2 + "px", 'top': '0px', 'left':'0px'});
}
} else {
if ( resizer == "width") {
var value = 0;
var widthValueInit = Math.round(resizeValue / originalLength) ;
this.rasterLine = this.rasterizeLine(elements, "width",0,0, resizeValue, originalLength, true);
this.inversLine = this.rasterizeLine(elements, "width",0,0, resizeValue, originalLength, false);
for ( var i = 0; i < elements.length; i++) {
if ( elements.length == 1 ) var widthValue = 0;
else var widthValue = widthValueInit;

var node = this.currentImgElements[i];
var w = this.inversLine[value + Math.pow(2, elements[i])] - this.inversLine[value];
node.style.height = (Math.pow(2, elements[i]) + 1) + "px";
if ( i != elements.length - 1 ) node.style.width = w + widthValue + "px";
else node.style.width = w + (widthValue / 2) + "px";
if ( m < 0 ) {
positionX = positionX - w;
if ( i == 0 ) positionX -= widthValue;
if ( i == elements.length - 1 ) positionX += (widthValue / 2);
node.style.left = positionX + "px";
node.style.top  = positionY + "px";
positionY += Math.pow(2, elements[i]);
}
if ( m >= 0 ) {
node.style.left = positionX + "px";
node.style.top  = positionY + "px";
positionX += w;
if ( i == elements.length - 1 ) positionX += (widthValue / 2);
positionY += Math.pow(2, elements[i]);
}
value += Math.pow(2, elements[i]);
}
} else  {
var value = 0;
this.rasterLine = this.rasterizeLine(elements, "height", 0,0, resizeValue, originalLength, true);
this.inversLine = this.rasterizeLine(elements, "width",0,0, resizeValue, originalLength, false);
var heightValueInit = Math.round((resizeValue / originalLength));
for ( var i = 0; i < elements.length; i++) {
if ( elements.length == 1 ) var heightValue = 0;
else var heightValue = heightValueInit;

var node = this.currentImgElements[i];
var h = this.inversLine[value + Math.pow(2, elements[i])] - this.inversLine[value];
node.style.width  = (Math.pow(2, elements[i]) + 1 ) + "px";
if ( i != 0 ) {
node.style.height = h + heightValue + "px" ;
} else node.style.height = h + "px";
if ( m < 0 ) {
positionX = positionX - Math.pow(2, elements[i]);
node.style.left= positionX + "px";
node.style.top = positionY + "px";
if ( i == 0 ) positionY += h - heightValue;
else positionY += h;
}
if ( m >= 0 ) {
node.style.left= positionX + "px";
node.style.top = positionY + "px";
positionX = positionX + Math.pow(2, elements[i]);
if ( i == 0 ) positionY += h - heightValue;
else positionY += h;
}
}
}
}
}
DefaultEdgeView.prototype.addArrowhead=function(elements, edgeDiv, m, width, height, direction, aimElement, startElement, rasterLine, resizer)
{
var widthEl = parseInt(aimElement.htmlElement.style.width.replace("px","")) / 2;
var heightEl = parseInt(aimElement.htmlElement.style.height.replace("px","")) / 2;
var xEl = aimElement.nodeData.getPosition().x + widthEl;
var yEl = aimElement.nodeData.getPosition().y + heightEl;
var div = document.createElement("div");
div.id = "arrowhead";
if ( m < 0 ) {
var st = -1;
if ( direction == "south") { var st1 = 1; var st2 = -1; }
else { var st1 = -1; var st2 = 1; }
} else {
var st = 1;
if ( direction == "south") { var st1 = -1; var st2 = -1;} 
else { var st1 = 1; var st2 = 1;}
}
var beta = Math.acos(Math.sqrt(1 / (1+ (st * m ))));
var alpha = Math.acos(0.9);
var factor = 20;
var xA, yA;
if ( direction == "north" ) {
var X = new Array(0, st1 * Math.cos(beta + alpha) * factor, st1 * Math.cos(beta - alpha) * factor);
var Y = new Array(0, st2 * Math.sin(beta + alpha) * factor, st2 * Math.sin(beta - alpha) * factor);
yA = heightEl;
xA = yA / m;

if ( xA > widthEl) {
xA = widthEl;
yA = xA * m;
} else if ( xA < -widthEl ) {
xA = - widthEl;
yA = (-xA) * (-m);
}
if ( m < 0 ) {
xA = width + xA;
}
} else {
var X = new Array(0, st1 * Math.cos(beta + alpha) * factor, st1 * Math.cos(beta - alpha) * factor);
var Y = new Array(0, st2 * Math.sin(beta + alpha) * factor, st2 * Math.sin(beta - alpha) * factor);
yA = height - heightEl;
xA = yA / m;
if ( xA < (width - widthEl) && m >= 0 ) {
xA = width - widthEl;
yA = (xA * m);
} 
if ( m == 0 ) {
xA = width - widthEl;
yA = 1;
}
if ( m < 0 ) {
xA = heightEl / m;
if ( -xA > widthEl ) {
xA = widthEl;
yA = height + xA * m;
} else {
xA = Math.round(heightEl / -m);
}
}
}
var g = new jsGraphics(div);
if ( this.edgeData.isActive() ) var color = this.style.getActiveColor()[1];
else var color = this.style.getInactiveColor(0)[1];
if (this.edgeData.isGhosted() ) var color = this.style.getGhostColor()[1];
g.setColor(color);
g.fillPolygon(X, Y);
g.paint();
$(div).css({'position':'absolute','left': xA + 'px', 'top' : yA + 'px'});
return div;

}
DefaultEdgeView.prototype.setZIndex=function(zIndex)
{
$(this.htmlElement).css({'z-index':zIndex});
return ++zIndex;
}
DefaultEdgeView.prototype.isPointOnEdge=function(x,y)
{
x = x + this.graphView.scrollOffsetX;
y = y + this.graphView.scrollOffsetY;
if ( this.m != 0 && this.m != Number.MAX_VALUE && !( this.elements.length == 1 && this.elements[0] == 0 )) {
if ( x > this.x && x < ( this.x + this.w ) && y > this.y && y < ( this.y + this.h ) ){
if ( this.m > 0 ) {

if ( this.resizer == "width" ) {
var ym = this.rasterLine[(x - this.x)];
ym += this.y;

if ( (ym - 8) <= y && y <= (ym + 8) ) {
return true;
} else {
return false
}
} else {
var ym = this.rasterLine[(y - this.y)];
ym += this.x;

if ( (ym - 8) <= x && x <= (ym + 8 ) ) {
return true;
} else {
return false
}
}
} else {

if ( this.resizer == "width" ) {
var ym = this.rasterLine[(x - this.x)];
ym = (this.y + this.h - ym);

if ( (ym - 8) <= y && y <= (ym + 8) ) {
return true;
} else {
return false;
}
} else {
var ym = this.rasterLine[(y - this.y)];
ym = this.x + this.w - ym;

if ( (ym - 8) <= x && x <= (ym + 8 ) ) {
return true;
} else {
return false
}
}
}
} else return false;
} else {
if (this.h <= 8) {

if ( (y >= (this.y - 8) && y <= (this.y + 8)) && (x >= this.x && x <= this.x + this.w) ) {
return true;
} else return false;
} else if ( this.w <= 8 ) {

if ( (x >= (this.x - 8) && x <= (this.x + 8)) && (y >= this.y && y <= this.y + this.h) ) {
return true;
} else return false;
} else {
return false;
}
}
}
DefaultEdgeView.prototype.repaint=function()
{
if ( !this.hide ) {
if ( this.htmlElement != null ) this.graphView.canvas.removeChild(this.htmlElement);
this.htmlElement = this.createHTMLElement(this.edgeData,this.style,this.el1,this.el2);
this.showLabel(true);
this.graphView.canvas.appendChild(this.htmlElement);
}
}
DefaultEdgeView.prototype.changeColor=function(color, imageSet)
{
if ( !this.ghosted ) {
this.currentColor = color;
for ( var i = 0; i < imageSet.length; i++ ) {
if ( this.m < 0 ) {
imageSet[i].getAttributeNode("src").value = this.graphView.edgePath + "/" + color[0] + "1" + this.indexElements[i] + ".gif";
} else {
imageSet[i].getAttributeNode("src").value = this.graphView.edgePath + "/" + color[0] + "2" + this.indexElements[i] + ".gif";
}
}
for ( var i = 0; i < this.arrowhead.childNodes[0].childNodes.length; i++ ) {
this.arrowhead.childNodes[0].childNodes[i].style.backgroundColor = color[1]; 
}
}
}
DefaultEdgeView.prototype.changeGhostStatus=function(ghost)
{
if ( ghost ) {
this.changeColor( this.style.getGhostColor(), this.imgElements );
this.ghosted = true;
} else {
this.ghosted = false;
if ( this.edgeData.isActive() ) this.changeColor( this.style.getActiveColor(), this.imgElements );
else {
if ( this.multicolored ) this.repaint();
else this.changeColor(this.style.getInactiveColor(0), this.imgElements );
}
}
}
DefaultEdgeView.prototype.changeDirectedStatus=function(directed)
{
if (directed) this.htmlElement.appendChild(this.arrowhead);
else this.htmlElement.removeChild(this.arrowhead);
}
DefaultEdgeView.prototype.changeActivityStatus=function(active)
{
if ( this.style.isCrossfade() ) {
if ( active ) this.changeColor(this.style.getActiveColor(), this.imgElements );
else {
this.changeColor( this.style.getInactiveColor(0), this.imgElements );
this.changeColor( this.style.getCrossfadeColor(), this.crossfadeElements );
}
} else {
if ( active ) this.changeColor(this.style.getActiveColor(), this.imgElements );
else {
if ( this.multicolored ) {
if ( !this.ghosted )this.repaint();
}
else this.changeColor(this.style.getInactiveColor(0), this.imgElements );
}
}
}
DefaultEdgeView.prototype.changeFocusedStatus=function(focus)
{
if ( focus ) this.changeColor(this.style.getFocusColor(), this.imgElements);
else {
if ( this.style.isCrossfade() ) {
if ( this.edgeData.isActive() ) this.changeColor(this.style.getActiveColor(), this.imgElements );
else {
this.changeColor( this.style.getInactiveColor(0), this.imgElements );
this.changeColor( this.style.getCrossfadeColor(), this.crossfadeElements );
}
} else {
if ( this.edgeData.isActive() ) this.changeColor(this.style.getActiveColor(), this.imgElements );
else {
if ( this.multicolored ) this.repaint();
else this.changeColor(this.style.getInactiveColor(0), this.imgElements );
}
}
}
}
DefaultEdgeView.prototype.changeWeight=function(weight)
{
if ( !this.style.isCrossfade() ) this.changeThickness(weight);
else this.changeCrossfade(weight);
}
DefaultEdgeView.prototype.changeType=function(type)
{
if ( type.length > 1 ) {
var colorset = new Array();
for ( var i = 0; i < type.length; i++ ) colorset.push(this.graphView.style.getEdgeStyle(type[i]).getInactiveColor(0));
this.style = new EdgeStyle("<<Multityped>>", colorset, this.graphView.style.getEdgeStyle(type[0]).getActiveColor(), this.graphView.style.getEdgeStyle(type[0]).getGhostColor());
this.style.setFocusColor(this.graphView.style.getEdgeStyle(type[0]).getFocusColor());
this.multicolored = true;
} else this.style = this.graphView.style.getEdgeStyle(type[0]);
if ( !this.ghosted ) this.repaint();
}
DefaultEdgeView.prototype.changeThickness=function(weight)
{
if ( weight < 100 ) var thickness = parseInt( weight / 20 ) + 1;
else var thickness = 5;
if ( thickness != this.thickness ) {
this.thickness = thickness;
this.htmlElement = this.createHTMLElement(this.edgeData,this.style,this.el1,this.el2);
}
}
DefaultEdgeView.prototype.changeCrossfade=function(weight)
{
for ( var i = 0; i < this.crossfadeElements.length; i++ )
this.crossfadeElements[i].style.opacity = weight / 100;
}
DefaultEdgeView.prototype.changeOpacity=function(op)
{
this.htmlElement.style.opacity = op;
}
DefaultEdgeView.prototype.hideEdge=function()
{
this.htmlElement.style.visibility = "hidden";
}
DefaultEdgeView.prototype.showEdge=function()
{
this.htmlElement.style.visibility = "visible";
}
DefaultEdgeView.prototype.showLabel=function(op)
{
if (op) {
this.htmlElement.appendChild(this.labelDiv);
var htmlE = this.htmlElement;
var x = (this.h / 2);
var y = (this.w / 2) + 5;
$(this.labelDiv).css({
'position': 'absolute',
'top': x + 'px',
'left': y
});
} else {
this.htmlElement.removeChild(this.labelDiv);
}
}
DefaultEdgeView.prototype.changeLabel=function(lab)
{
this.htmlElement.removeChild(this.labelDiv);
this.labelDiv = document.createElement('span');
this.labelDiv.appendChild(document.createTextNode(lab));
this.showLabel(this.edgeData.isLabelVisible());
this.createToolTip();
}
DefaultEdgeView.prototype.highlight=function()
{
$(this.htmlElement).fadeIn("normal");
}
function DefaultNodeView(graphView, node, style, width, height, add) 
{

this.id = node.getId();
this.graphView = graphView;
this.nodeData = node;
this.style = style;
this.canvas = graphView.canvas;
this.init = true;
this.moved = false;
this.flip = false;
this.mozilla = false;
this.label;

this.width = width;
this.initialWidth = width;
this.height = height;
this.initialHeight = height;
this.x;
this.y;
this.oldX; 
this.oldY; 
this.middlePoint;

this.nodeData.register(this);
this.style.register(this);

this.hide = false;
this.ghosted = false;
this.focused = false;
this.currentColor;
this.currentSaturation;
this.currentBorder;
this.initialFontSize = 13;
this.currentFontSize = this.initialFontSize + this.nodeData.getWeight();
this.cornerSize = 7;
this.borderOffset = 1;
this.frameWidth = 3;

this.mainElements = new Array();
this.cornerElements = new Array();

this.input = document.createElement("input");
this.input.value = this.nodeData.getLabel();
this.input.id = "input"+this.id;
this.dragElement;
this.htmlElement = this.createHTMLElement(node, style, width, height, add);
this.contextMenu = null;

}
DefaultNodeView.prototype.type = "DefaultNodeView";
DefaultNodeView.prototype.createHTMLElement=function(node, style, width, height, add)
{
if ( this.htmlElement == null ) {
if ( node.isActive() ) this.currentColor = style.getActiveColor();
else this.currentColor = style.getInactiveColor();
this.currentSaturation = 100;
this.currentBorder = style.getBorder();
this.htmlElement = this.createNode(node, this.currentColor, width, height, add);
if ( add ) this.canvas.appendChild(this.htmlElement);
}
this.setNodeDraggable(true);
return this.htmlElement;
}
DefaultNodeView.prototype.createNode=function(node, color, width, height, add) 
{
this.width = width;
this.height = height;
this.actionLayer = document.createElement("div");
this.actionLayer.id = "action" + node.getId();
var widthHeight = this.getTextWidthHeight(node.getLabel());
this.labelWidth = widthHeight[0];
this.labelHeight = widthHeight[1];
this.labelElement = widthHeight[2];
if ( (this.labelWidth + (this.cornerSize * 2)) > this.initialWidth ) this.width = width = this.labelWidth + (this.cornerSize * 2);
    else this.width = width = this.initialWidth;
if ( (this.labelHeight + 6) > this.initialHeight ) this.height = height = this.labelHeight + 6;
else this.height = height = this.initialHeight;
$(this.labelElement).css({'position':'absolute','top':( Math.round(this.height / 2)- Math.round(this.labelHeight / 2) ) + "px",'left':( Math.round(this.width / 2)- Math.round(this.labelWidth / 2) ) + "px"})
$(this.actionLayer).css({'position':'absolute', 'width':this.width + this.borderOffset + "px",'height':this.height + "px",'left':'0px','top':'0px'})

if ( !this.mozilla ) {
nodeV = this.getImageDiv(this.width, this.height, this.cornerSize, color, this.currentBorder, this.currentSaturation);
} else {
    nodeV = this.getMozillaDiv(this.width, this.height, this.cornerSize, color, this.currentBorder, this.currentSaturation);
}
nodeV.id = node.getId();

var t = this;
this.actionLayer.ondblclick = function() {
var opt = new OptionFrame(t.graphView, t.id + "option", t.x, t.y, 100, OptionFrame.prototype.showNodeProperties, t.nodeData);
opt.addToCanvas(t.graphView.canvas);}
this.actionLayer.onmouseover = function() {
if ( !t.graphView.dragging ) {
t.showFrame(true);
t.graphView.cleanGlassPane();
t.graphView.showHelpText("(CLICK) to activate, (DOUBLE_CLICK) to change properties");}}
this.actionLayer.onmouseout = function() {
t.graphView.deleteMessage();
if ( !t.focused ) t.showFrame(false);
}
this.actionLayer.onclick = function() {
t.graphView.setFocus(t.id);
t.graphView.deActivateElement(t.id);
t.graphView.addNodeToList(t.id);}
this.labelElement.ondblclick = function() {
var opt = new OptionFrame(t.graphView, t.id + "option", t.x, t.y, 100, OptionFrame.prototype.showNodeProperties, t.nodeData);
opt.addToCanvas(t.graphView.canvas);}
this.labelElement.onmouseover = function() {
if ( !t.graphView.dragging ) {
t.showFrame(true);
t.graphView.cleanGlassPane();
t.graphView.showHelpText("(CLICK) to activate, (DOUBLE_CLICK) to change properties");}}
this.labelElement.onmouseout = function() {
t.graphView.deleteMessage();
if ( !t.focused ) t.showFrame(false);}
this.labelElement.onclick = function() {
t.graphView.setFocus(t.id);
t.graphView.deActivateElement(t.id);
t.graphView.addNodeToList(t.id);}

this.middlePoint = new Point(this.x + Math.round(this.width/2), this.y + Math.round(this.height/2) );

nodeV.actionLayer = this.actionLayer;
nodeV.appendChild(this.labelElement);
nodeV.appendChild(this.actionLayer);
return nodeV;
}
DefaultNodeView.prototype.createLabel=function(lab)
{
this.label = document.createTextNode(lab);
var span = document.createElement("span");
span.style.fontSize = (this.currentFontSize /12) + "em";
span.appendChild(this.label);
return span;
}
DefaultNodeView.prototype.getImageDiv=function(width, height, cornerSize, color, border, saturation)
{
var colorIndex = (-1/20) * saturation + 6;
var div = document.createElement("div");
div.style.position = "absolute";
div.style.width = width + "px";
div.style.height = height + "px";
var horizontal = document.createElement("div");
$(horizontal).css({'position':'absolute','width':width - 1 + "px",'height':(height - (cornerSize*2)) + "px", 'left':'0px', 'top':cornerSize + 'px',
'background-color':color[colorIndex],'border-right':'1px ' + border + ' black','border-left':'1px ' + border + ' black'});
this.mainElements.push(horizontal);
var vertical = document.createElement("div");
$(vertical).css({'position':'absolute','width':(width - (cornerSize*2) ) + "px",'height':(height - 2) + "px", 'left':cornerSize + 'px', 'top':'0px',
'background-color':color[colorIndex],'border-bottom':'1px ' + border + ' black','border-top':'1px ' + border + ' black'});
this.mainElements.push(vertical);
var upperLeft = document.createElement("img");
$(upperLeft).css({'position':'absolute','width':2*cornerSize + 'px','height':2*cornerSize + 'px', 'left':'0px', 'top':'0px'});
upperLeft.src = this.graphView.nodePath + "/" + color[0] + "/" + saturation + ".gif";
this.cornerElements.push(upperLeft);
var upperRight = document.createElement("img");
$(upperRight).css({'position':'absolute','width':2*cornerSize + 'px','height':2*cornerSize + 'px', 'left':(width - 2*cornerSize + 1 )+'px', 'top':'0px'});
upperRight.src = this.graphView.nodePath + "/" + color[0] + "/" + saturation + ".gif";
this.cornerElements.push(upperRight);
var bottomLeft = document.createElement("img");
$(bottomLeft).css({'position':'absolute','width':2*cornerSize + 'px','height':2*cornerSize + 'px', 'left':'0px', 'top':(height - 2*cornerSize ) + 'px'});
bottomLeft.src = this.graphView.nodePath + "/" + color[0] + "/" + saturation + ".gif";
this.cornerElements.push(bottomLeft);
var bottomRight = document.createElement("img");
$(bottomRight).css({'position':'absolute','width':2*cornerSize + 'px','height':2*cornerSize + "px", 'left':(width - 2*cornerSize + 1 ) + 'px', 'top':(height - 2*cornerSize ) + 'px'});
bottomRight.src = this.graphView.nodePath + "/" + color[0] + "/" + saturation + ".gif";
this.cornerElements.push(bottomRight);
div.appendChild(upperLeft);
div.appendChild(upperRight);
div.appendChild(bottomLeft);
div.appendChild(bottomRight);
div.appendChild(vertical);
div.appendChild(horizontal);
return div;
}
DefaultNodeView.prototype.getMozillaDiv = function(width, height, cornerSize, color, border, saturation)
{
var colorIndex = (-1/20) * saturation + 6;
var div = document.createElement("div");
div.style.position = "absolute";
div.style.width = width + "px";
div.style.height = height + "px";
div.style.backgroundColor = color[colorIndex];
div.style.border = border + " black 1px";
$(div).css('-moz-border-radius-bottomleft', "8px");
$(div).css('-moz-border-radius-bottomright', "8px");
$(div).css('-moz-border-radius-topleft', "8px");
$(div).css('-moz-border-radius-topright', "8px");
return div;
}
DefaultNodeView.prototype.getTextWidthHeight=function(text) 
{
var labelTab = this.createLabel(text);
this.canvas.appendChild(labelTab);
var textWidth = labelTab.offsetWidth;
var textHeight = labelTab.offsetHeight;
this.canvas.removeChild(labelTab);
return new Array(textWidth, textHeight, labelTab);
}
DefaultNodeView.prototype.changeColor=function(color)
{
this.currentColor = color;
var colorIndex = (-1/20) * this.currentSaturation + 6;
if ( !this.mozilla ) {
for ( var i = 0; i < this.mainElements.length; i++ ) this.mainElements[i].style.backgroundColor = color[colorIndex];
for ( var i = 0; i < this.cornerElements.length; i++ ) this.cornerElements[i].src = this.graphView.nodePath + "/" + color[0] + "/" + this.currentSaturation + ".gif";
} else {
this.htmlElement.style.backgroundColor = color[colorIndex];
}
}
DefaultNodeView.prototype.activeColorChanged=function(actColor)
{
if ( this.nodeData.isActive() ) this.changeColor(actColor);
}
DefaultNodeView.prototype.inactiveColorChanged=function(inactColor)
{
if ( !this.nodeData.isActive() ) this.changeColor(inactColor);
}
DefaultNodeView.prototype.changeSaturation=function(saturation)
{
this.currentSaturation = saturation;
this.changeColor(this.currentColor);
}
DefaultNodeView.prototype.changeBorder=function(border)
{
if (! this.mozilla ) {
this.mainElements[0].style.borderLeft = border + " black 1px";
this.mainElements[0].style.borderRight = border + " black 1px";
this.mainElements[1].style.borderBottom = border + " black 1px";
this.mainElements[1].style.borderTop = border + " black 1px";
} else {
this.htmlElement.style.border = border + " black 1px";
}
}
DefaultNodeView.prototype.changeLabel=function(label)
{
if ( this.showInput ) {
label = this.input.value;
this.nodeData.setInputFieldAsLabel(false);
this.htmlElement.removeChild(this.input);
this.showInput = false;
} else {
this.htmlElement.removeChild(this.actionLayer);
this.htmlElement.removeChild(this.labelElement);
}
var widthHeight = this.getTextWidthHeight(label);
this.labelWidth = widthHeight[0];
this.labelHeight = widthHeight[1];
this.labelElement = widthHeight[2];
this.htmlElement.appendChild(this.labelElement);
this.htmlElement.appendChild(this.actionLayer);
this.width = this.labelWidth + (2 * this.cornerSize);
if ( this.labelHeight + 6 > this.initialHeight ) this.height = this.labelHeight + 6;
else this.height = this.initialHeight;
this.changeWidthHeight(this.width, this.height);
$(this.labelElement).css({'position':'absolute','top':( Math.round(this.height / 2)- Math.round(this.labelHeight / 2) ) + "px",'left':( Math.round(this.width / 2)- Math.round(this.labelWidth / 2) ) + "px"})
this.setNodeDraggable(true);
var t = this;
this.labelElement.ondblclick = function() {
var opt = new OptionFrame(t.graphView, t.id + "option", t.x, t.y, 100, OptionFrame.prototype.showNodeProperties, t.nodeData);
opt.addToCanvas(t.graphView.canvas);}
this.labelElement.onmouseover = function() {
if ( !t.graphView.dragging ) {
t.showFrame(true);
t.graphView.cleanGlassPane();
t.graphView.showHelpText("(CLICK) to activate, (DOUBLE_CLICK) to change properties");}}
this.labelElement.onmouseout = function() {
t.graphView.deleteMessage();
if ( !t.focused ) t.showFrame(false);}
this.labelElement.onclick = function() {
t.graphView.setFocus(t.id);
t.graphView.deActivateElement(t.id);
t.graphView.addNodeToList(t.id);}
}
DefaultNodeView.prototype.changeWeight=function(weight)
{
if ( weight > 100 ) weight = 100;
this.currentFontSize = this.initialFontSize + (weight / 2);
this.changeLabel(this.nodeData.getLabel());
}
DefaultNodeView.prototype.changeActivityStatus=function(active)
{
if ( active ) {
this.changeColor( this.style.getActiveColor() );
} else {
this.changeColor( this.style.getInactiveColor() );
}
}
DefaultNodeView.prototype.changeFocusStatus=function(focused)
{
this.showFrame(focused);
this.focused = focused;
}
DefaultNodeView.prototype.showFrame=function(show)
{
if ( show ) {
if (this.mozilla) var m = 0; 
else var m = 1;
$(this.actionLayer).css({'width':this.width - (this.frameWidth * 2) + m  + "px",'height':this.height - (this.frameWidth * 2) + "px"});
if ( this.graphView.graphFixed ) this.actionLayer.style.border = "solid " + this.frameWidth + "px red";
else this.actionLayer.style.border = "solid " + this.frameWidth + "px #0000ff";
} else {
if (this.mozilla) var m = 0; 
else var m = 1;
this.actionLayer.style.border = "0px solid #000";
$(this.actionLayer).css({'width':(this.width + (this.frameWidth * 2) - m) + "px",'height':(this.height + (this.frameWidth *2)) + "px"});
}
}
DefaultNodeView.prototype.changeType=function(type)
{
if ( this.graphView.style.getNodeStyle(type) != null ) {
this.style = this.graphView.style.getNodeStyle(type);
this.currentBorder = this.style.getBorder();
if ( this.nodeData.isActive() ) this.currentColor = this.style.getActiveColor();
else this.currentColor = this.style.getInactiveColor();
this.changeBorder(this.currentBorder);
this.changeColor(this.currentColor);
}
}
DefaultNodeView.prototype.changeWidthHeight=function(w,h)
{
this.width = w;
this.height = h;
if ( ! this.mozilla  ) {
$(this.mainElements[0]).css({'width':this.width - 1 + "px",'height':(this.height - (this.cornerSize*2)) + "px"});
$(this.mainElements[1]).css({'width':(this.width - (this.cornerSize*2) ) + "px",'height':(this.height - 2) + "px"});
$(this.cornerElements[1]).css({'left':(this.width - 2*this.cornerSize + 1 )+'px', 'top':'0px'});
$(this.cornerElements[2]).css({'left':'0px', 'top':(this.height - 2*this.cornerSize ) + 'px'});
$(this.cornerElements[3]).css({'left':(this.width - 2*this.cornerSize + 1 ) + "px", 'top':(this.height - 2*this.cornerSize ) + "px"});
}
$(this.htmlElement).css({'width':this.width + this.borderOffset + "px",'height':this.height + this.borderOffset + "px"});
$(this.actionLayer).css({'width':this.width + this.borderOffset + "px",'height':this.height + this.borderOffset + "px"});

var newX = this.middlePoint.x - Math.round(this.width / 2);
var newY = this.middlePoint.y - Math.round(this.height / 2);
this.nodeData.setPosition(new Point(newX, newY));
}
DefaultNodeView.prototype.showInputField=function()
{
this.showInput = true;
this.setNodeDraggable(false);
var t = this;
$(this.input).css({'position':'absolute','left':'2px','top':'5px','width':(this.width - 8) + "px",'height':'14px'});
this.input.onkeydown=function(e){
var code;
if (!e)e = window.event;
  if (e.which)  code = e.which;
  else if (e.keyCode) code = e.keyCode;
if ( code == 13 ) {
var label = t.input.value;
t.graphView.setLabel(t.id, label);
}}
this.input.onblur=function(e) {
var label = t.input.value;
t.graphView.setLabel(t.id, label);}
this.htmlElement.appendChild(this.input);
this.input.focus();
}
DefaultNodeView.prototype.setPosition=function(x,y)
{
this.x = x;
this.y = y;
this.htmlElement.style.left = this.x + "px";
this.htmlElement.style.top = this.y + "px";
this.middlePoint = new Point(this.x + Math.round(this.width/2), this.y + Math.round(this.height/2) );
this.graphView.moveNodeCallback(this.nodeData, x, y);
this.graphView.repaintEdges(this.id);
}
DefaultNodeView.prototype.setZIndex=function(z)
{
this.htmlElement.style.zIndex = z;
this.dragElement.zIndex = z;
return z+1;
}
DefaultNodeView.prototype.setNodeDraggable=function(flag)
{
if ( flag ) {
var t = this;
    this.dragElement = $(this.htmlElement).Draggable(
        {
            'ghosting': true,
'containment' : "parent",
            'opacity': 0.3,
            'onStop': function() { 

t.graphView.dragging = false;
t.nodeData.setPosition( new Point(parseInt(t.htmlElement.style.left.replace("px", "")), parseInt(t.htmlElement.style.top.replace("px", ""))) );
            
t.moved = true;
            },
'onStart' : function() {
t.graphView.dragging = true;
t.moved = true;
}
    });
} else {
if ( this.dragElement != null ) $(this.htmlElement).DraggableDestroy();
}
}
DefaultNodeView.prototype.showNode = function(){this.htmlElement.style.visibility = "visible";}
DefaultNodeView.prototype.hideNode=function(){this.htmlElement.style.visibility = "hidden";}
DefaultNodeView.prototype.changeGhostNodeStatus=function(status)
{
if ( status ) {
this.changeSaturation(20);
this.changeWeight(1);
this.ghosted = true;
} else {
this.changeSaturation(100);
this.changeWeight(this.nodeData.getWeight());
this.ghosted = false;
}
}
DefaultNodeView.prototype.flipNode = function(){}
DefaultNodeView.prototype.setNodeFlip=function(flip, parent, x, y, showCloseButton)
{
this.flip = flip;
if ( flip ) {
var html = this.htmlElement;
var graphView = this.graphView;
var id = this.id;
var t = this;


this.actionLayer.onmouseover = function() {
t.showFrame(true);

}
this.actionLayer.onmouseout = function() {
if ( !t.focused ) t.showFrame(false);

}
$(this.htmlElement).DraggableDestroy();
this.dragElement = $(this.htmlElement).Draggable(
        {
            'ghosting': true,
            'opacity': .5,

'revert' : 'true',
'onDrag' : function(x,y) {
t.oldX = x;
t.oldY = y;
},
            'onStop': function() { 
    graphView.menu.toolBar.createNewNode(id, t.oldX, t.oldY);
t.moved = true;
            },
'onStart' : function() {
t.moved = true;
}
    });
} else {
}
}
DefaultNodeView.prototype.wasMoved=function(){return this.moved;}
DefaultNodeView.prototype.highlight=function(){$(this.htmlElement).Highlight(1500,'#ffffff');}
function Edge(label, type, weight, directed, n1, n2, act) 
{
if ( type instanceof Array && type.length > 1 ) this.multityped = true;
else {
this.multityped = false;
type = new Array(type);
}
this.type = type;
this.node1 = n1;
this.node2 = n2;
this.directed = directed;
if ( weight > 100 ) weight = 100;
if ( weight < 0 ) weight = 0;
this.weight = weight;
this.ghosted = false;
this.focused = false;
this.id;
this.label = label;
this.labelVisible = true;
this.active = act;
this.idSettable = true;
this.views = new Array();
this.parentGraph = null;
}
Edge.prototype.getId=function(){return this.id;}
Edge.prototype.setId=function(ID, graph){
if ( this.idSettable ) {
this.id = ID;
this.parentGraph = graph;
this.idSettable = false;
return true;
} else {
return false;
}
}
Edge.prototype.getNodeId1=function(){return this.node1.getId();}
Edge.prototype.getNodeId2=function(){return this.node2.getId();}
Edge.prototype.isDirected=function(){return this.directed;}
Edge.prototype.setDirected=function(direct){
if ( this.directed != direct ) {
this.directed = direct;
for ( var i = 0; i < this.views.length; i++ ) this.views[i].changeDirectedStatus(this.directed);
this.parentGraph.edgePropertyChangeCallback(this);
}
}
Edge.prototype.getWeight=function(){return this.weight;}
Edge.prototype.setWeight=function(weight){
if ( this.weight != weight ) {
if ( weight > 100 ) weight = 100;
if ( weight < 0 ) weight = 0;
this.weight = weight;
for ( var i = 0; i < this.views.length; i++ ) this.views[i].changeWeight(this.weight);
this.parentGraph.edgePropertyChangeCallback(this);
}
}
Edge.prototype.getLabel=function(){return this.label;}
Edge.prototype.setLabel=function(label){if ( this.label != label ) {this.label = label;this.parentGraph.edgePropertyChangeCallback(this);
for ( var i = 0; i < this.views.length; i++ ) this.views[i].changeLabel(this.label);
this.parentGraph.edgePropertyChangeCallback(this);
}
}
Edge.prototype.setLabelVisible=function(vis){if( this.labelVisible != vis ){this.labelVisible = vis;
for ( var i = 0; i < this.views.length; i++ ) this.views[i].showLabel(this.labelVisible);
this.parentGraph.edgePropertyChangeCallback(this);
}
}
Edge.prototype.isLabelVisible=function(){return this.labelVisible;}
Edge.prototype.getType=function(index){if ( index == null ) return this.type[0];else return this.type[index];
}
Edge.prototype.getMultitype=function()
{
if ( this.multityped ) return type;
else return null;
}
Edge.prototype.setType=function(type)
{
if ( !(type instanceof Array) ) type = new Array(type);
if ( type.length > 1 ) this.multityped = true;
else this.multityped = false;
var equal = false;
if ( this.type.length == type.length ) {
equal = true;
for ( var i = 0; i < type.length; i++ ) if ( this.type[i] != type[i] ) equal = false;
}
if ( !equal ) {
this.type = type;
this.parentGraph.edgePropertyChangeCallback(this);
for ( var i = 0; i < this.views.length; i++ ) this.views[i].changeType(this.type);
}
}
Edge.prototype.isActive=function(){return this.active;}
Edge.prototype.setActive=function(act){
if ( this.active != act ) {
this.active = act;
this.parentGraph.edgePropertyChangeCallback(this);
if ( !this.ghosted ) for ( var i = 0; i < this.views.length; i++ ) this.views[i].changeActivityStatus(act);
}
}
Edge.prototype.isGhosted=function(){return this.ghosted;}
Edge.prototype.setGhosted=function(ghost)
{
if ( this.ghosted != ghost ) {
this.ghosted = ghost;
this.parentGraph.edgePropertyChangeCallback(this);
for ( var i = 0; i < this.views.length; i++ ) this.views[i].changeGhostStatus(ghost);
}
}
Edge.prototype.isFocused=function(){return this.focused;}
Edge.prototype.setFocused=function(focus)
{
if ( this.focused != focus ) {
this.focused = focus;
this.parentGraph.edgePropertyChangeCallback(this);
for ( var i = 0; i < this.views.length; i++ ) this.views[i].changeFocusedStatus(this.focused);
} 
}
Edge.prototype.isMultityped=function(){return this.multityped;}
Edge.prototype.highlight=function(){for ( var i = 0; i < this.views.length; i++ ) this.views[i].highlight();}
Edge.prototype.register=function(view){this.views.push(view);}
function EdgeSet(graphId, nodeSetId, id, name)
{
this.graphId = graphId;
this.id = id;
this.nodeSetId = nodeSetId;
if ( name == null ) this.name = graphId + "_edgeSet";
else this.name = name;
this.edgeCounter = 0;
this.nextEdgeId = this.graphId + "e" + this.edgeCounter;
this.edges = new Array();
this.edgesHash = new Array(new Object());
}
EdgeSet.prototype.type = "EdgeSet";
EdgeSet.prototype.addEdge=function(edge, graph)
{
if ( edge.setId(this.nextEdgeId, graph) ) {
this.edges.push(edge);
this.edgesHash[0][edge.getId()] = edge;
this.edgeCounter++;
this.nextEdgeId = this.graphId + "e" + this.edgeCounter;
return edge;
} else {
return null;
}
}
EdgeSet.prototype.removeEdge=function(edge)
{
this.edges = this.deleteItem(this.edges, edge);
this.edgesHash[0][edge.getId()] = null;
}
EdgeSet.prototype.removeEdgeSet=function(edgeSet)
{
for ( var i = 0; i < edgeSet.length; i++ ) {
this.removeEdge(edgeSet[i]);
}
}
EdgeSet.prototype.getEdgeById=function(edgeId){return this.edgesHash[0][edgeId];}
EdgeSet.prototype.getId=function(){return this.id;}
EdgeSet.prototype.getAsociatedNodeSetId=function(){return this.nodeSetId;}
EdgeSet.prototype.getName=function(){return this.name;}
EdgeSet.prototype.getEdges=function(){return this.edges;}
EdgeSet.prototype.getCopy=function(nodeSetId, id){var copy = new EdgeSet(this.graphId, nodeSetId, id, this.name);}
EdgeSet.prototype.setName=function(name){this.name = name;}
EdgeSet.prototype.deleteItem=function(array, item) 
{
var temp = new Array();
for ( var i = 0; i < array.length; i ++ ) 
if ( array[i].getId() != item.getId() ) temp.push(array[i]);
return temp;
}
function EdgeStyle(name, inactive, act, ghost, crossColor)
{
this.name = name;
this.active = act;
if ( inactive instanceof Array ) {
this.inactive = inactive;
if ( inactive.length > 1 ) this.multicolored = true;
else this.multicolored = false;
} else {
this.inactive = new Array(inactive);
this.multicolored = false;
}
this.ghost = ghost;
this.focus = EdgeStyle.prototype.blue;
if ( crossColor != null && crossColor instanceof Array ) this.crossfade = true;
else this.crossfade = false;
this.crossfadeColor = crossColor;
this.views = new Array();
}
EdgeStyle.prototype.type = "EdgeStyle";
EdgeStyle.prototype.black = ["black/", "#000000"];
EdgeStyle.prototype.red = ["red/", "#ff0000"];
EdgeStyle.prototype.blue = ["blue/", "#4141d8"];
EdgeStyle.prototype.lightGray = ["lightGray/", "#d8d8d8"];
EdgeStyle.prototype.orange = ["orange/","#ff5f00"];
EdgeStyle.prototype.yellow = ["yellow/","#ffff00"];
EdgeStyle.prototype.green = ["green/", "#0be11b"];
EdgeStyle.prototype.getActiveColor=function(){return this.active;}
EdgeStyle.prototype.getInactiveColor=function(i){return this.inactive[i];}
EdgeStyle.prototype.getInactiveColorSet=function(){return this.inactive;}
EdgeStyle.prototype.getFocusColor=function(){return this.focus;}
EdgeStyle.prototype.getGhostColor=function(){return this.ghost;}
EdgeStyle.prototype.getName=function(){return this.name;}
EdgeStyle.prototype.getCrossfadeColor=function(){return this.crossfadeColor;}
EdgeStyle.prototype.setActiveColor=function(active){this.active = active;}
EdgeStyle.prototype.setInactiveColor=function(inactive){this.inactive[0] = inactive;}
EdgeStyle.prototype.setFocusColor=function(focus){this.focus = focus;}
EdgeStyle.prototype.setGhostColor=function(ghost){this.ghost = ghost;}
EdgeStyle.prototype.setCrossfadeColor=function(crossfade){this.crossfadeColor = crossfade;if ( !this.crossfade ) this.crossfade = true;}
EdgeStyle.prototype.isCrossfade=function(){return this.crossfade;}
EdgeStyle.prototype.isMulticolored=function(){return this.multicolored;}
EdgeStyle.prototype.registerView=function(view){this.views.push(view);}
function Graph(name) {
this.id = null;
this.idIsSetable = true;
this.name = name;
this.nodeSetCounter = 1;
this.edgeSetCounter = 1;
this.nextNodeSetId = this.id + "_nodeSet_" + 1;
this.nextEdgeSetId = this.id + "_edgeSet_" + 1;
this.currentNodeSet = new NodeSet(this.id, this.id + "_nodeSet_" + 0, "initial");
this.currentEdgeSet = new EdgeSet(this.id, this.id + "_nodeSet_" + 0, this.id + "_edgeSet_" + 0, "initial");
this.subGraphCounter = 0;
this.nextSubGraphId = this.id + "_subGraph_" + 0;
this.subGraphs = new Array();
this.subGraphHash = new Array(new Object());
this.nodes = this.currentNodeSet.nodes;
this.edges = this.currentEdgeSet.edges;
this.nodeHash = this.currentNodeSet.nodesHash;
this.edgeHash = this.currentEdgeSet.edgesHash;
this.nodeSets = new Array(this.currentNodeSet);
this.edgeSets = new Array(this.currentEdgeSet);
this.nodeSetsHash = new Array(new Object());
this.edgeSetsHash = new Array(new Object());
this.nodeSetsHash[0][this.currentNodeSet.getId()] = this.currentNodeSet;
this.edgeSetsHash[0][this.currentEdgeSet.getId()] = this.currentEdgeSet;
this.views = new Array();
this.itemChangeListener = new Array();
this.isSubGraph = false;
this.selectedSubGraph = null;
this.layout = null;
return this;
}
Graph.prototype.type = "Graph";
Graph.prototype.addNode = function(node, x, y)
{
if ( ! this.isSubGraph ) {
var nodeI = this.currentNodeSet.addNode(node, this);
if ( nodeI != null ) {
for (var i = 0; i < this.views.length; i++ ) this.views[i].showNode(nodeI);
for (var i = 0; i < this.itemChangeListener.length; i++ ) this.itemChangeListener[i].addNodeEventPerformed(nodeI);
if ( x != null && y != null ) nodeI.setPosition(new Point(x,y));
else nodeI.setPosition(new Point(0,0));
if ( this.selectedSubGraph != null ) this.selectedSubGraph.addNode(nodeI);
return nodeI;
} else {
return null;
}
} else {
this.currentNodeSet.nodes.push(node);
this.currentNodeSet.nodesHash[0][node.getId()] = node;
}
}
Graph.prototype.removeNode = function(node)
{
if ( !this.isSubGraph && this.currentNodeSet.getNodeById(node.getId()) != null) {

for ( var i = 0; i < this.views.length; i++ ) this.views[i].removeNode(node.getId());
for ( var i = 0; i < this.itemChangeListener.length; i++ ) this.itemChangeListener[i].delNodeEventPerformed(node);
this.currentNodeSet.removeNode(node);

var delEdges = new Array();
for ( var i = 0; i < this.currentEdgeSet.edges.length; i++ ) {
if ( this.currentEdgeSet.edges[i].getNodeId1() == node.getId() || 
 this.currentEdgeSet.edges[i].getNodeId2() == node.getId() ) 
 delEdges.push(this.currentEdgeSet.edges[i]);
}
for ( var i = 0; i < delEdges.length; i ++ ) {
this.removeEdge(delEdges[i]);
}
if ( !this.isSubGraph && this.selectedSubGraph != null ) this.selectedSubGraph.removeNode(node);
} else if ( this.nodeHash[0][node.getId()] != null ) {
this.currentNodeSet.removeNode(node);
var delEdges = new Array();
for ( var i = 0; i < this.currentEdgeSet.edges.length; i++ ) {
if ( this.currentEdgeSet.edges[i].getNodeId1() == node.getId() || 
 this.currentEdgeSet.edges[i].getNodeId2() == node.getId() ) 
delEdges.push(this.currentEdgeSet.edges[i]);
}
for ( var i = 0; i < delEdges.length; i ++ ) {
this.removeEdge(delEdges[i]);
}
}
}
Graph.prototype.getNodeByLabel = function(label)
{
var nodes = this.currentNodeSet.getNodes();
var node = null;
for ( var i = 0; i < nodes.length; i++ ) if ( nodes[i].getLabel() == label ) node = nodes[i];
return node;
}
Graph.prototype.getNodes = function(){return this.currentNodeSet.getNodes();}
Graph.prototype.getNodeById=function(nodeId){return this.currentNodeSet.getNodeById(nodeId);}
Graph.prototype.getNodeByActivity=function(active)
{
var result = new Array()
for ( var i = 0; i < this.nodes.length; i++ ) if ( this.nodes[i].isActive() == active ) result.push(this.nodes[i]);
return result;
}
Graph.prototype.setActivityOfAllNodes=function(act)
{
for ( var i = 0; i < this.currentNodeSet.getNodes().length; i++ ) {
this.currentNodeSet.getNodes()[i].setActive(act);
}
for ( var i = 0; i < this.currentEdgeSet.getEdges().length; i++ ) {
this.currentEdgeSet.getEdges()[i].setActive(act);
}
if ( !this.isSubGraph && this.selectedSubGraph != null ) this.selectedSubGraph.setActivityOfAllNodes(act);
}
Graph.prototype.nodePropertyChangeCallback=function(node)
{
for( var i = 0; i < this.itemChangeListener.length; i++ )
this.itemChangeListener[i].nodePropertyChangedPerformed(node);
}
Graph.prototype.addEdge = function(edge)
{
if ( ! this.isSubGraph ) {
var edgeI = this.currentEdgeSet.addEdge(edge, this);
if (edgeI != null) {
for ( var i = 0; i < this.views.length; i++ ) this.views[i].showEdge(edgeI);
for ( var i = 0; i < this.itemChangeListener.length; i++ ) this.itemChangeListener[i].addEdgeEventPerformed(edgeI);
if ( this.selectedSubGraph != null ) this.selectedSubGraph.addEdge(edgeI);
}
} else if ( this.isSubGraph ){
this.currentEdgeSet.edges.push(edge);
this.currentEdgeSet.edgesHash[0][edge.getId()] = edge;
}
}
Graph.prototype.removeEdge = function(edge)
{
if ( !this.isSubGraph && this.currentEdgeSet.getEdgeById(edge.getId()) != null ) {
for ( var i = 0; i < this.views.length; i++ ) this.views[i].removeEdge(edge.getId());
for ( var i = 0; i < this.itemChangeListener.length; i++ ) this.itemChangeListener[i].delEdgeEventPerformed(edge);
this.currentEdgeSet.removeEdge(edge);
this.edges = this.currentEdgeSet.edges;
this.edgeHash[0][edge.getId()] = null;
if ( this.selectedSubGraph != null ) this.selectedSubGraph.removeEdge(edge);
} else if ( this.currentEdgeSet.getEdgeById(edge.getId()) != null ) {
this.currentEdgeSet.removeEdge(edge);
}
}
Graph.prototype.getEdges = function(){return this.currentEdgeSet.getEdges();}
Graph.prototype.getEdgeById=function(edgeId){return this.currentEdgeSet.getEdgeById(edgeId);}
Graph.prototype.getEdgeByLabel = function(label)
{
var edges = this.currentEdgeSet.getEdges();
var edge = null;
for ( var i = 0; i < edges.length; i++ ) if ( edges[i].getLabel() == label ) edge = edges[i];
return edge;
}
Graph.prototype.getEdgeByActivity=function(active)
{
var result = new Array()
for ( var i = 0; i < this.edges.length; i++ ) if ( this.edges[i].isActive() == active ) result.push(this.edges[i]);
return result;
}
Graph.prototype.replaceEdge=function(oldEdge, newEdge)
{
if ( newEdge.setId(oldEdge.getId()) ) {
this.edgeHash[0][oldEdge.getId()] = newEdge;
this.edges = this.replaceItem(this.edges, oldEdge, newEdge);
for ( var i = 0; i < this.itemChangeListener.length; i++ ) this.itemChangeListener[i].replaceEdgeEventPerformed(oldEdge, newEdge);
} else {
alert("Edge " + newEdge + " is not unique / used in another graph!");
} 
}
Graph.prototype.setNewEdgeSet = function(edges, edgeSetName) 
{
if ( !this.isSubGraph ) {

var temp = new EdgeSet(this.id, this.currentNodeSet.getId(), this.nextEdgeSetId,  edgeSetName);
this.edgeSetCounter++;
this.nextEdgeSetId = this.id + "edgeSet" + this.edgeSetCounter;
for ( var i = 0; i < edges.length; i++ ) {
if ( this.currentNodeSet.getNodeById(edges[i].getNodeId1()) != null && 
     this.currentNodeSet.getNodeById(edges[i].getNodeId2()) != null    ) 
var edge = temp.addEdge(edges[i], this);
}
this.edgeSets.push(temp);
this.edgeSetsHash[0][temp.getId()] = temp;
for ( var i = 0; i < this.itemChangeListener.length; i++ ) this.itemChangeListener[i].newEdgeSetPerformed(temp);
return temp.getId();
}
}
Graph.prototype.deleteEdgeSet = function(edgeSetId)
{
var edgeSet = this.edgeSetsHash[0][edgeSetId];
var temp = new Array();
for( var i = 0; i < this.edgeSets.length; i++ ) if ( this.edgeSets[i].getId() != edgeSet.getId() ) temp.push(this.edgeSets[i]);
this.edgeSets = temp;
this.edgeSetsHash[0][edgeSetId] = null;
}
Graph.prototype.setCurrentEdgeSet=function(edgeSetId)
{
if ( edgeSetId != this.currentEdgeSet.getId() ) {
var newEdgeSet = this.edgeSetsHash[0][edgeSetId];
if ( newEdgeSet != null ) {

for ( var i = 0; i < this.views.length; i++ ) 
for ( var j = 0; j < this.currentEdgeSet.getEdges().length; j++ ) 
this.views[i].removeEdge(this.currentEdgeSet.getEdges()[j].getId());
var difference = new Array();
for ( var i = 0; i < newEdgeSet.getEdges().length; i++ ) {
var tempEdge = newEdgeSet.getEdges()[i];
var isInSet = false;
for ( var j = 0; j < this.currentEdgeSet.getEdges().length; j++ ) {
if ( this.currentEdgeSet.getEdges()[j].getNodeId1() == tempEdge.getNodeId1() && 
 this.currentEdgeSet.getEdges()[j].getNodeId2() == tempEdge.getNodeId2() ) isInSet = true;
}
if ( !isInSet ) difference.push(tempEdge);
isInSet = false;
}
this.currentEdgeSet = newEdgeSet;
for ( var i = 0; i < this.views.length; i++ ) {
for ( var j = 0; j < this.currentEdgeSet.getEdges().length; j++ ) {
this.views[i].showEdge(this.currentEdgeSet.getEdges()[j]);
}
}
for ( var i = 0; i < this.itemChangeListener.length; i++ ) 
this.itemChangeListener[i].currentEdgeSetChangedPerformed(this.currentEdgeSet);
for ( var i = 0; i < difference.length; i++ ) 
difference[i].highlight();
}
}
}
Graph.prototype.edgePropertyChangeCallback=function(edge)
{
for( var i = 0; i < this.itemChangeListener.length; i++ ) 
this.itemChangeListener[i].edgePropertyChangedPerformed(edge);
}
Graph.prototype.setRandomLayout=function(width, height)
{
this.layout = Layout.prototype.defaultLayoutRandom(this, width, height);
for ( var i = 0; i < this.nodes.length; i++ ) this.nodes[i].setPosition(this.layout.getNodePosition(this.nodes[i].getId()));
}
Graph.prototype.setCircleLayout=function(bore)
{
this.layout = Layout.prototype.defaultLayoutCircle(this, bore);
for ( var i = 0; i < this.nodes.length; i++ ) this.nodes[i].setPosition(this.layout.getNodePosition(this.nodes[i].getId()));
}
Graph.prototype.setRectangleLayout=function(width, height)
{
this.layout = Layout.prototype.defaultLayoutRect(this, width, height);
for ( var i = 0; i < this.nodes.length; i++ ) this.nodes[i].setPosition(this.layout.getNodePosition(this.nodes[i].getId()));
}
Graph.prototype.getLayout=function()
{
var layout = new Layout();
for ( var i = 0; i < this.nodes.length; i++ ) layout.setNodePosition(this.nodes[i].getId(), this.nodes[i].getPosition().x, this.nodes[i].getPosition().y);
return layout;
}
Graph.prototype.getParents=function(node)
{
var parents = new Array();
for ( var i = 0; i < this.edges.length; i++ ) 
if ( this.edges[i].isDirected() && this.edges[i].getNodeId2() == node.getId() ) 
parents.push(this.getNodeById(this.edges[i].getNodeId1()));
return parents;
}
Graph.prototype.getChildren=function(node)
{
var children = new Array();
for ( var i = 0; i < this.edges.length; i++ ) 
if ( this.edges[i].isDirected() && this.edges[i].getNodeId1() == node.getId() ) 
children.push(this.getNodeById(this.edges[i].getNodeId2()));
return children;
}
Graph.prototype.getSiblings=function(node)
{
var siblings = new Array();
var parents = this.getParents(node);
for ( var i = 0; i < parents.length; i++ ) {
siblings = siblings.concat(this.getChildren(parents[i]));
}
}
Graph.prototype.addSubGraph=function(nodes)
{
var subid = this.nextSubGraphId;
this.subGraphCounter++; this.nextSubGraphId = this.id + "_subGraph_" + this.subGraphCounter;
var subGraph = new Graph();
subGraph.isSubGraph = true;
var subEdges = new Array();
var tempE = new Array();
for ( var i = 0; i < nodes.length; i++ ) {
subGraph.nodes[i] = nodes[i];
subGraph.nodeHash[0][nodes[i].getId()] = nodes[i];
}
for ( var i = 0; i<this.edges.length; i++ ) {
if ( subGraph.nodeHash[0][this.edges[i].getNodeId1()] != null ) {
tempE.push(this.edges[i]);
}
}
for ( var i = 0; i < tempE.length; i++ ) {
if ( subGraph.nodeHash[0][ tempE[i].getNodeId2() ] != null) {
subGraph.edges.push(tempE[i]);
subGraph.edgeHash[0][tempE[i].id] = tempE[i];
}
}
this.subGraphHash[0][subid] = subGraph;
this.subGraphs.push(subGraph);
return subid;
}
Graph.prototype.getSubGraph=function(subid){return this.subGraphHash[0][subid];}
Graph.prototype.registerView=function(graphView){this.views.push(graphView);}
Graph.prototype.registerItemChangeListener=function(listener){this.itemChangeListener.push(listener);}
Graph.prototype.replaceItem=function(array, oldItem, newItem)
{
var temp = new Array();
for ( var i = 0; i < array.length; i ++ ) {
if ( array[i] != oldItem ) temp.push(array[i]);
else temp.push( newItem );
}
return temp;
}
Graph.prototype.deleteItem=function(array, item) 
{
var temp = new Array();
for ( var i = 0; i < array.length; i ++ ) {
if ( array[i].getId() != item.getId() ) {
temp.push(array[i]);
} else {}
}
return temp;
}
Graph.prototype.setId=function(id)
{
if ( this.idIsSetable ) {
this.id = id;
this.idIsSetable = false; 
this.currentEdgeSet.graphId = this.id;
this.currentEdgeSet.id = this.id + "_edgeSet_" + 0;
this.edgeSetsHash[0][this.id + "_edgeSet_" + 0] = this.currentEdgeSet;
this.currentNodeSet.graphId = this.id;
this.currentNodeSet.id = this.id + "_nodeSet_" + 0;
this.nodeSetsHash[0][this.id + "_nodeSet_" + 0] = this.currentNodeSet;
this.nextNodeSetId = this.id + "_nodeSet_" + 1;
this.nextEdgeSetId = this.id + "_edgeSet_" + 1;
return this.id;
} else {
alert("Graph is not unique!");
return this.id;
}
}
Graph.prototype.getId=function(){return this.id;}
Graph.prototype.setName=function(name){this.name = name;}
Graph.prototype.getName=function(){return this.name;}
function GraphStyle(graphStyleObject)
{
this.edgeHighlighting = true;
this.nodeStylesHash = new Array();
this.nodeStylesHash[0] = new Object();
this.nodeStyles = new Array();
this.nodeTypes = new Array();
this.standardNodeStyle = null;
this.standardNodeType = null;
this.edgeStylesHash = new Array();
this.edgeStylesHash[0] = new Object();
this.edgeStyles = new Array();
this.edgeTypes = new Array();
this.standardEdgeStyle = null;
this.standardEdgeType = null;
if ( graphStyleObject != null ) this.parseInitObject(graphStyleObject);
}

GraphStyle.prototype.type = "GraphStyle";

GraphStyle.prototype.addNodeStyle=function(nodeType, nodeStyle)
{
this.nodeStylesHash[0][nodeType] = nodeStyle;
this.nodeTypes.push(nodeType);
this.nodeStyles.push(nodeStyle);
if ( this.standardNodeStyle == null ) this.standardNodeStyle = nodeStyle;
if ( this.standardNodeType == null ) this.standardNodeType = nodeType;
}

GraphStyle.prototype.getNodeStyle=function(nodeType)
{
return this.nodeStylesHash[0][nodeType];
}

GraphStyle.prototype.getAllNodeStyles=function()
{
return this.nodeStyles;
}

GraphStyle.prototype.getAllNodeTypes=function()
{
return this.nodeTypes;
}

GraphStyle.prototype.addEdgeStyle=function(edgeType, edgeStyle) 
{
this.edgeStylesHash[0][edgeType] = edgeStyle;
this.edgeTypes.push(edgeType);
this.edgeStyles.push(edgeStyle);
if ( this.standardEdgeStyle == null ) this.standardEdgeStyle = edgeStyle;
if ( this.standardEdgeType == null ) this.standardEdgeType = edgeType;
}

GraphStyle.prototype.getEdgeStyle=function(edgeType)
{
return this.edgeStylesHash[0][edgeType];
}

GraphStyle.prototype.getAllEdgeStyles=function()
{
return this.edgeStyles;
}

GraphStyle.prototype.getAllEdgeTypes=function()
{
return this.edgeTypes;
}
GraphStyle.prototype.isEdgeHighlighting = function()
{
return this.edgeHighlighting;
}

GraphStyle.prototype.parseInitObject=function(obj)
{
for ( var i = 0; i < obj.nodeStyles.length; i++ ) this.addNodeStyle(obj.nodeStyles[i].type,
new NodeStyle(obj.nodeStyles[i].name, obj.nodeStyles[i].inactiveColor, obj.nodeStyles[i].activeColor, obj.nodeStyles[i].border )); 
for ( var i = 0; i < obj.edgeStyles.length; i++ ) {
if ( obj.edgeStyles[i] != null ) this.addEdgeStyle(obj.edgeStyles[i].type,
new EdgeStyle(obj.edgeStyles[i].name, obj.edgeStyles[i].inactiveColor, obj.edgeStyles[i].activeColor, obj.edgeStyles[i].ghostedColor, obj.edgeStyles[i].crossfadeColor ));
else this.addEdgeStyle(obj.edgeStyles[i].type,
new EdgeStyle(obj.edgeStyles[i].name, obj.edgeStyles[i].inactiveColor, obj.edgeStyles[i].activeColor, obj.edgeStyles[i].ghostedColor));
}
if ( obj.edgeHighlighting != null ) this.edgeHighlighting = obj.edgeHighlighting;
}



function GraphView(config) 
{
if ( navigator.appName == "Microsoft Internet Explorer" ) this.browser = "IE";
else this.browser = "FireFox";
this.config = config;
this.id = this.config.parentDivId;
this.nodePath = this.config.imagePath + "/node";
this.edgePath = this.config.imagePath + "/edge";
this.iconPath = this.config.imagePath + "/icon";
var posX = this.config.posX;
var posY = this.config.posY;
this.callbackPanelHeight = 40;

this.container = document.getElementById(this.config.parentDivId);
this.container.id = "container_" + this.config.parentDivId; 
this.container.width = this.config.width;
this.container.height = this.config.height;
var cont = this.container;
$(this.container).css({'font-size':'small', 'overflow':'hidden', 'position':config.position,
'left':config.posX, 'top':config.posY, 'width':config.width,'height':config.height });
var con = document.getElementById("container_" + this.config.parentDivId);
if ( this.config.position = "relative" ) {
posX = con.offsetLeft;
posY = con.offsetTop;
}

var height = this.config.height - this.config.pluginPaneHeight - this.callbackPanelHeight;
this.scrollPane = document.createElement("div");
this.scrollPane.id = "scrollPane_" + this.config.parentDivId; 
var scroll = this.scrollPane;
$(this.scrollPane).css({'font-size':'small', 'overflow':'scroll', 'position':'absolute',
'left':0+'px', 'top':this.callbackPanelHeight+'px', 'width':this.config.width+'px','height':height+'px' });
this.scrollPane.width = this.config.width;
this.scrollPane.height = height;
var t = this;
this.scrollPane.onscroll = function(){
for ( var i = 0; i < t.changeListener.length; i++ )
t.changeListener[i].canvasScrolledPerformed(scroll.scrollLeft, scroll.scrollTop);
t.scrollOffsetX = scroll.scrollLeft;
t.scrollOffsetY = scroll.scrollTop;
}
this.container.appendChild(this.scrollPane);
var scr = document.getElementById("scrollPane_" + this.config.parentDivId);
this.scrollPane.posx = scr.offsetLeft;
this.scrollPane.posy = scr.offsetTop;
this.posX = posX;
this.posY = posY + this.callbackPanelHeight;
this.canvas = document.createElement("div");
this.canvas.id = this.config.parentDivId;
$(this.canvas).css( {'font-size':'small','position':'absolute','left':0+'px',
 'top':0+'px','width':this.config.width+'px','height':height+'px'} );
this.canvas.width = this.config.width;
this.canvas.height = height;
this.pluginPane = document.createElement("div");
this.pluginPane = document.createElement("div");
this.pluginPane.id = "pluginPane_" + this.config.parentDivId;
$(this.pluginPane).css( {'font-size':'small','position':'absolute','left':0+'px','overflow':'auto',
 'top':height + this.callbackPanelHeight +'px','width':this.config.width+'px','height':this.config.pluginPaneHeight+'px'} );
this.pluginPane.width = this.config.width;
this.pluginPane.height = height;
this.container.appendChild(this.pluginPane);
this.style = new GraphStyle(this.config.graphStyle);
this.edgeMode = null;
this.dragMode = null;
this.helpText = null;
this.createCallbackPanel();
this.setUpGlassPane();


this.scrollPane.appendChild(this.canvas);
this.initialWidth = this.config.width;
this.initialHeight = height;
this.dragging = false;
this.graphFixed = false;
this.frameOpen = false;
this.maxZ = 1;
this.styleOfNewEdges;
this.nodeFocus = null;
this.currentGraph = null;
this.currentGraphId;
this.layout = null;
this.subGraphCounter = 0;
this.scrollOffsetX = scr.scrollLeft;
this.scrollOffsetY = scr.scrollTop;
this.nextGraphId = 0;
this.modeToggeled = false;
this.nodeActivity = this.config.nodeActivity || 'multi';
this.pluginsInitialized = false;
this.pluginHash = new Array(new Object());

this.addedNodeViews = new Array();
this.addedNodeViewsHash = new Array(new Object());
this.addedEdgeViews = new Array();
this.addedEdgeViewsHash = new Array(new Object());
this.connectedEdgesToNodeHash = new Array(new Object());
this.activeNodeData = new Array();
this.activeEdgeData = new Array();
this.graphArray = new Array();
this.graphHash = new Array(new Object());
this.changeListener = new Array();
this.itemChangeListener = new Array();
this.plugins = new Array();
this.toolTips = new Array();
this.readInPlugins(this.config.plugins);
return this;
}

GraphView.prototype.type = "GraphView";




GraphView.prototype.visualizeGraphById=function(graphId, info)
{
var graph = this.graphHash[0][graphId];
if ( graph != null && this.currentGraphId != graphId) {
this.clearCanvas();
this.visualizeGraph(graph, info);
}
}

GraphView.prototype.addGraph=function(graph)
{
if ( graph.id == null ) {
var id = graph.setId(this.id + "_Graph_" + this.nextGraphId );

this.currentGraph = graph;
this.currentGraphId = graph.getId();
this.graphArray.push(graph);
this.graphHash[0][graph.getId()] = graph;
++this.nextGraphId;
this.addItemListenerToGraph();
this.currentGraph.registerView(this);
for ( var i = 0; i < this.changeListener.length; i++ ) 
this.changeListener[i].newGraphAddedPerformed(this.currentGraph);
}
}

GraphView.prototype.visualizeGraph=function(graph, info)
{

if ( graph.id == null ) {
if ( this.currentGraph != null ) this.clearCanvas();
this.addGraph(graph);

} else {
this.currentGraph = graph;
this.currentGraphId = graph.getId();
}
var nodes = this.currentGraph.getNodes();
var edges = this.currentGraph.getEdges();
var width = 0;
var height = 30;
var date1 = new Date();


for (var i = 0; i < nodes.length; i++) this.showNode(nodes[i]);


this.layoutGraph(this.currentGraph.getLayout());

var date2 = new Date();
if ( info ) document.write("Nodes(" + ((date2.getTime() - date1.getTime()) / 1000) + ") | ");


for ( var i = 0; i < edges.length; i++) this.showEdge(edges[i]);
var date3 = new Date();
if ( info ) document.write("Edges(" + ((date3.getTime() - date2.getTime()) / 1000) + ") | ");
if ( info ) document.write("Total: " + ((date3.getTime() - date1.getTime()) / 1000));


for ( var i = 0; i < this.addedEdgeViews.length; i++) this.maxZ = this.addedEdgeViews[i].setZIndex(this.maxZ);
this.glassPane.style.zIndex = this.maxZ; this.maxZ++;
for ( var i = 0; i < this.addedNodeViews.length; i++) this.maxZ = this.addedNodeViews[i].setZIndex(this.maxZ);

}

GraphView.prototype.clearCanvas=function()
{
for ( var i = 0; i < this.currentGraph.getNodes().length; i++ ) 
this.canvas.removeChild(this.addedNodeViews[i].htmlElement);
for ( var i = 0; i < this.currentGraph.getEdges().length; i++ ) 
this.canvas.removeChild(document.getElementById(this.addedEdgeViewsHash[0][this.currentGraph.getEdges()[i].getId()].htmlElement.id));
this.graphFixed = false;
this.maxZ = 1;
this.styleOfNewEdges = null;
this.nodeFocus = null;
this.currentGraph = new Object();
this.layout = null;

this.addedNodeViews = new Array();
this.addedNodeViewsHash = new Array(new Object());
this.addedEdgeViews = new Array();
this.addedEdgeViewsHash = new Array(new Object());
this.connectedEdgesToNodeHash = new Array(new Object());
}




GraphView.prototype.setUpGlassPane=function()
{

this.glassPaneMenu = null;

this.glassPane = document.createElement("div");
$(this.glassPane).css({'position':'absolute', 'width':this.canvas.style.width, 'height':this.canvas.style.height, 'top':'0px', 'left':'0px'});
this.glassPane.edgeFocused = false;
var t = this;
var getMousePosition = function(e) {
var posx = 0;
var posy = 0;
if (!e) var e = window.event;
if (e.pageX || e.pageY) {
posx = e.pageX;
posy = e.pageY;
}
else if (e.clientX || e.clientY) {
posx = e.clientX + document.body.scrollLeft+ document.documentElement.scrollLeft;
posy = e.clientY + document.body.scrollTop  + document.documentElement.scrollTop;
}
return new Point(posx - t.posX, posy - t.posY);
}
this.glassPane.onclick = function(e) {
if ( t.graphFixed && !t.modeToggeled ) t.fixGraphView();
else if ( t.modeToggeled ) t.modeToggeled = false;
if ( t.nodeFocus != null ) {
t.currentGraph.getNodeById(t.nodeFocus).setFocused(false);
t.nodeFocus = null;
}
var mousePos = getMousePosition(e);
t.handleGlassPaneEvent(mousePos.x, mousePos.y);
}
document.onkeydown = function(e) {
var code;
if (!e)e = window.event;
  if (e.which)  code = e.which;
  else if (e.keyCode) code = e.keyCode;
if ( code == 46 && !t.frameOpen) {
var nodes = t.currentGraph.getNodes();
for ( var i = 0; i < nodes.length; i ++ ) {
if ( nodes[i].isActive() ) t.currentGraph.removeNode(nodes[i]);
}
}
}
this.glassPane.onmousemove = function(e) {
if ( !t.dragging ) {
var mousePos = getMousePosition(e);
var edgeD = t.currentGraph.getEdges();
var showToolTip = false;
for ( var i = 0; i < edgeD.length; i++ ) {
if ( t.addedEdgeViewsHash[0][edgeD[i].getId()].isPointOnEdge(mousePos.x, mousePos.y) ) {
if ( !this.edgeFocused ) {
if ( !edgeD[i].isGhosted() && t.style.isEdgeHighlighting() ) edgeD[i].setFocused(true);
t.addedEdgeViewsHash[0][edgeD[i].getId()].showToolTip(mousePos.x + t.scrollOffsetX, mousePos.y + t.scrollOffsetY);
t.toolTips.push(t.addedEdgeViewsHash[0][edgeD[i].getId()]);
t.showHelpText("(CLICK) to activate, (DOUBLE_CLICK) to change properties");
showToolTip = true;
this.edgeFocused = true;
}
} else {
if ( !edgeD[i].isGhosted() && t.style.isEdgeHighlighting() ) edgeD[i].setFocused(false);
t.addedEdgeViewsHash[0][edgeD[i].getId()].hideToolTip();
if ( !showToolTip ) t.deleteMessage();
}
}
this.edgeFocused = false;
}
}
this.glassPane.ondblclick = function(e) {
var mousePos = getMousePosition(e);
var edgeD = t.currentGraph.getEdges();
for ( var i = 0; i < edgeD.length; i++ ) {
if ( t.addedEdgeViewsHash[0][edgeD[i].getId()].isPointOnEdge(mousePos.x, mousePos.y) ) {
var opt = new OptionFrame(t, t.id + "option", mousePos.x + t.scrollOffsetX, mousePos.y + t.scrollOffsetY, 100, OptionFrame.prototype.showEdgeProperties, edgeD[i]);
opt.addToCanvas(t.canvas);
}
}
}
if (this.browser == "IE") {
document.onmousemove = function(e){
if (!t.dragging) {
var mousePos = getMousePosition(e);
var edgeD = t.currentGraph.getEdges();
var showToolTip = false;
for (var i = 0; i < edgeD.length; i++) {
if (t.addedEdgeViewsHash[0][edgeD[i].getId()].isPointOnEdge(mousePos.x, mousePos.y)) {
if (!this.edgeFocused) {
if (!edgeD[i].isGhosted() && t.style.isEdgeHighlighting()) 
edgeD[i].setFocused(true);
t.addedEdgeViewsHash[0][edgeD[i].getId()].showToolTip(mousePos.x + t.scrollOffsetX, mousePos.y + t.scrollOffsetY);
t.toolTips.push(t.addedEdgeViewsHash[0][edgeD[i].getId()]);
t.showHelpText("(CLICK) to activate, (DOUBLE_CLICK) to change properties");
showToolTip = true;
this.edgeFocused = true;
}
}
else {
if (!edgeD[i].isGhosted() && t.style.isEdgeHighlighting()) 
edgeD[i].setFocused(false);
t.addedEdgeViewsHash[0][edgeD[i].getId()].hideToolTip();
if (!showToolTip) 
t.deleteMessage();
}
}
this.edgeFocused = false;
}
}
document.ondblclick = function(e){
var mousePos = getMousePosition(e);
var edgeD = t.currentGraph.getEdges();
for (var i = 0; i < edgeD.length; i++) {
if (t.addedEdgeViewsHash[0][edgeD[i].getId()].isPointOnEdge(mousePos.x, mousePos.y)) {
var opt = new OptionFrame(t, t.id + "option", mousePos.x + t.scrollOffsetX, mousePos.y + t.scrollOffsetY, 100, OptionFrame.prototype.showEdgeProperties, edgeD[i]);
opt.addToCanvas(t.canvas);
}
}
}
}
this.createGlassPaneContextMenu(true);
this.canvas.appendChild(this.glassPane);
}

GraphView.prototype.cleanGlassPane=function()
{
if(this.toolTips.length > 0) {
for ( var j = 0; j < this.toolTips.length; j++ ) {
this.toolTips[j].hideToolTip();
}
this.toolTips = new Array();
}
}

GraphView.prototype.createGlassPaneContextMenu=function(show)
{
var menu = document.createElement("div")
menu.id = this.id + "contextMenuGlassPane";
menu.style.display = "none";
var list = document.createElement("ul");
list.style.fontSize = "medium";
var entry0 = document.createElement("li");
entry0.appendChild(document.createTextNode("Create Node"))
entry0.id = "entry0";
var entry1 = document.createElement("li");
entry1.appendChild(document.createTextNode("Select All Nodes"))
entry1.id = "entry1";
var entry2 = document.createElement("li");
entry2.appendChild(document.createTextNode("Deselect All Nodes"));
entry2.id = "entry2";
var entry3 = document.createElement("li");
entry3.appendChild(document.createTextNode("Delete All Active Nodes"));
entry3.id = "entry3";
var entry4 = document.createElement("li");
entry4.appendChild(document.createTextNode("(De)Actviate Edge Mode"));
entry4.id = "entry4";
list.appendChild(entry0);
list.appendChild(entry1);
list.appendChild(entry2);
list.appendChild(entry3);
list.appendChild(entry4);
menu.appendChild(list);
this.canvas.appendChild(menu);
this.glassPaneMenu = menu;
var t = this;
var nodeId = this.id;
if (this.browser == "IE" ) 
$(document).contextMenu("#" + menu.id, {
bindings : { 
"#entry0" : function(e) {
var div = document.getElementById("jqContextMenu");
var posx = parseInt($(div).css('left').replace("px", "")) - t.posX;
var posy = parseInt($(div).css('top').replace("px", "")) - t.posY;
var node = t.currentGraph.addNode(new Node("",1,t.style.standardNodeType,false, t.config.standardNodeData, t.config.standardNodeLabel), posx , posy);
node.setInputFieldAsLabel(true);
},
"#entry1" : function(e) {
t.currentGraph.setActivityOfAllNodes(true);
},
"#entry2" : function(e) {
t.currentGraph.setActivityOfAllNodes(false); 
},
"#entry3" : function(e) {
var nodes = t.currentGraph.getNodes();
for ( var i = 0; i < nodes.length; i ++ ) {
if ( nodes[i].isActive() ) t.currentGraph.removeNode(nodes[i]);
}
},
"#entry4" : function(e) {
if ( t.graphFixed ) {
t.fixGraphView();
} else {
t.fixGraphView(t.style.standardEdgeType);
}
} }
});
else 
$(this.glassPane).contextMenu("#" + menu.id, {
bindings : { 
"#entry0" : function(e) {
var div = document.getElementById("jqContextMenu");
var posx = parseInt($(div).css('left').replace("px", "")) - t.posX;
var posy = parseInt($(div).css('top').replace("px", "")) - t.posY;
var node = t.currentGraph.addNode(new Node("",1,t.style.standardNodeType,false, t.config.standardNodeData, t.config.standardNodeLabel), posx , posy);
node.setInputFieldAsLabel(true);
},
"#entry1" : function(e) {
t.currentGraph.setActivityOfAllNodes(true);
},
"#entry2" : function(e) {
t.currentGraph.setActivityOfAllNodes(false); 
},
"#entry3" : function(e) {
var nodes = t.currentGraph.getNodes();
for ( var i = 0; i < nodes.length; i ++ ) {
if ( nodes[i].isActive() ) t.currentGraph.removeNode(nodes[i]);
}
},
"#entry4" : function(e) {
if ( t.graphFixed ) {
t.fixGraphView();
} else {
t.fixGraphView(t.style.standardEdgeType);
}
} }
});
}

GraphView.prototype.handleGlassPaneEvent=function(posx, posy)
{
var edgeD = this.currentGraph.getEdges();
for ( var i = 0; i < edgeD.length; i++ ) {
this.addedEdgeViewsHash[0][edgeD[i].getId()].hideToolTip();
if ( this.addedEdgeViewsHash[0][edgeD[i].getId()].isPointOnEdge(posx, posy) ) 
edgeD[i].setActive(!edgeD[i].isActive()); 
}
}

GraphView.prototype.resizeCanvas=function(width, height)
{
if ( width < this.initialWidth ) width = this.scrollPane.width;
if ( height < this.initialHeight ) height = this.scrollPane.height;
this.canvas.style.width = width + "px";
this.canvas.style.height = height + "px";
this.canvas.width = width;
this.canvas.height = height;
if ( this.glassPane != null ) {
this.glassPane.style.width = width + "px";
this.glassPane.style.height = height + "px";
this.glassPane.width = width;
this.glassPane.height = height;
}
for ( var i = 0; i < this.changeListener.length; i++ ) 
this.changeListener[i].canvasResizedPerformed(width, height);
}




GraphView.prototype.showNode= function(node)
{
var width = 50;
var height = 30;

var nodeView = new DefaultNodeView(this, node, this.style.getNodeStyle(node.getType()), width, height, true);
this.maxZ = nodeView.setZIndex(this.maxZ);

this.addedNodeViews.push(nodeView);
this.addedNodeViewsHash[0][node.getId()] = nodeView;
if ( node.isActive() ) this.activeNodeData.push(node);
this.connectedEdgesToNodeHash[0][node.getId()] = new Array();
return nodeView;
}

GraphView.prototype.removeNode=function(nodeId)
{
var nodeView = this.addedNodeViewsHash[0][nodeId]
this.canvas.removeChild(nodeView.htmlElement);
this.addedNodeViews = this.deleteItem(this.addedNodeViews, nodeView);
this.addedNodeViewsHash[0][nodeView.id] = null;
this.connectedEdgesToNodeHash[0][nodeId] = null;
if ( nodeView.nodeData.isActive() ) this.activeNodeData = this.deleteDataItem(this.activeNodeData, nodeView.nodeData);
}

GraphView.prototype.removeAllNodes=function()
{

this.clearCanvas();
}

GraphView.prototype.moveNodeCallback=function(nodeData, x, y)
{
for ( var i = 0 ; i < this.changeListener.length; i++ ) this.changeListener[i].moveNodeEventPerformed(nodeData, x, y);
}




GraphView.prototype.showEdge=function(edge)
{
this.connectedEdgesToNodeHash[0][edge.getNodeId1()].push(edge);
this.connectedEdgesToNodeHash[0][edge.getNodeId2()].push(edge);
var edgeStyle = this.style.getEdgeStyle(edge.getType());
var edgeView = new DefaultEdgeView(this, edge, edgeStyle, this.addedNodeViewsHash[0][edge.getNodeId1()], this.addedNodeViewsHash[0][edge.getNodeId2()] );
this.canvas.appendChild(edgeView.htmlElement);
this.addedEdgeViews.push(edgeView);
this.addedEdgeViewsHash[0][edge.getId()] = edgeView;
if ( edge.isActive() ) this.activeEdgeData.push(edge);
return edgeView;
}

GraphView.prototype.removeEdge=function(edgeId)
{
var edgeView = this.addedEdgeViewsHash[0][edgeId];
var edgeData = this.currentGraph.getEdgeById(edgeId);
this.canvas.removeChild(edgeView.htmlElement);
this.addedEdgeViews = this.deleteItem(this.addedEdgeViews, edgeView);
this.addedEdgeViewsHash[0][edgeId] = null;
if ( edgeData.isActive() ) this.activeEdgeData = this.deleteItem(this.activeEdgeData, edgeView.edgeData);
if ( this.addedNodeViewsHash[0][edgeData.getNodeId1()] != null ) {
this.connectedEdgesToNodeHash[0][edgeData.getNodeId1()] = this.deleteDataItem(this.connectedEdgesToNodeHash[0][edgeData.getNodeId1()], edgeData);
}
if ( this.addedNodeViewsHash[0][edgeData.getNodeId2()] != null ) {
    this.connectedEdgesToNodeHash[0][edgeData.getNodeId2()] = this.deleteDataItem(this.connectedEdgesToNodeHash[0][edgeData.getNodeId2()], edgeData);
}
}

GraphView.prototype.repaintEdges=function(nodeId)
{
if ( nodeId != null ) {
var edges = this.connectedEdgesToNodeHash[0][nodeId];
if ( edges != null && edges.length > 0) {
for ( var i = 0; i < edges.length; i++) this.addedEdgeViewsHash[0][edges[i].getId()].repaint();
}
}
}






GraphView.prototype.layoutGraph=function(layout)
{
var nodes = this.currentGraph.getNodes();
if ( nodes != null && nodes.length > 0 ) {
for ( var i = 0; i < nodes.length; i++ ) {
var position = new Point(layout.getNodePosition(nodes[i].getId()).x, layout.getNodePosition(nodes[i].getId()).y);
nodes[i].setPosition(position);
}
this.resizeCanvas(layout.maxX + parseInt(this.addedNodeViewsHash[0][layout.maxXID].htmlElement.style.width.replace("px","")), 
  layout.maxY + parseInt(this.addedNodeViewsHash[0][layout.maxYID].htmlElement.style.height.replace("px","")));
}
}

GraphView.prototype.setFocus=function(nodeId)
{
if ( this.graphFixed && this.nodeFocus == null ) {
this.nodeFocus=nodeId;
this.currentGraph.getNodeById(nodeId).setFocused(true);
} else if ( this.graphFixed && this.nodeFocus != null ) {

if ( this.nodeFocus != nodeId ) {
if ( this.currentGraph.getNodeById(this.nodeFocus).isActive() || this.currentGraph.getNodeById(nodeId).isActive()) var active = true;
else active = false;

var add = true;
var addEdge = this.connectedEdgesToNodeHash[0][this.nodeFocus];
for ( var i = 0; i < addEdge.length; i++ ) {
if ( addEdge[i].getNodeId2() == this.currentGraph.getNodeById(nodeId).getId() ) {
add = false;
var eId = addEdge[i].id;
}
}
if ( add ) {
this.currentGraph.addEdge(new Edge("Default", this.typeOfNewEdges, 1, true, this.currentGraph.getNodeById(this.nodeFocus), this.currentGraph.getNodeById(nodeId), active));
} else if ( !add ) {
this.currentGraph.removeEdge(this.currentGraph.getEdgeById(eId));
}
this.releaseFocus();
} else {
this.releaseFocus();
}
}
}

GraphView.prototype.releaseFocus=function()
{
this.currentGraph.getNodeById(this.nodeFocus).setFocused(false);
this.nodeFocus = null;
}

GraphView.prototype.deActivateElement=function(elementId)
{
if ( !this.graphFixed ) {
var nodeData = this.currentGraph.getNodeById(elementId);
var nodeView = this.addedNodeViewsHash[0][elementId];
var node = nodeView.htmlElement;
var corners;
var color;
var border;
var style = this.style.getNodeStyle(nodeData.getType());
var status = nodeData.isActive();
var t = this;
var setInactive = function(nodeData){
nodeData.setActive(false);

var edges = t.connectedEdgesToNodeHash[0][elementId]
for ( var i = 0; i < edges.length; i++ ) {
var edge = edges[i];
if ( !(edge.getNodeId1() == elementId) ) edge.setActive(t.currentGraph.getNodeById(edge.getNodeId1()).isActive());
else if ( !(edge.getNodeId2() == elementId) ) edge.setActive(t.currentGraph.getNodeById(edge.getNodeId2()).isActive());
}
var temp = new Array();
for ( var i = 0; i < t.activeNodeData.length; i++ ) if ( t.activeNodeData[i] != nodeData ) temp.push(t.activeNodeData[i]);
t.activeNodeData = temp;
}
var setActive = function(nodeData){
nodeData.setActive(true);
t.activeNodeData.push(nodeData);

var edges = t.connectedEdgesToNodeHash[0][nodeData.getId()];
for ( var i = 0; i < edges.length; i++ ) edges[i].setActive(true);
}
if ( nodeData.isActive() ) {
if ( this.nodeActivity == "multi" ||  this.nodeActivity == "single" ) setInactive(nodeData); 
} else {
if ( this.nodeActivity == "multi" ) setActive(nodeData);
else if ( this.nodeActivity == "single" ) {
if ( this.activeNodeData.length > 0 ) {
var edges = this.connectedEdgesToNodeHash[0][this.activeNodeData[0].getId()];
setInactive(this.activeNodeData[0]);
for ( var i = 0; i < edges.length; i++ ) {
edges[i].setActive(false);
this.repaintEdge(edges[i].getId());
}
setActive(nodeData);
} else setActive(nodeData);
}
}

this.repaintEdges(elementId);
}
}

GraphView.prototype.addNodeToList=function(elementId)
{
var nodeData = this.currentGraph.getNodeById(elementId);
}

GraphView.prototype.setLabel=function(nodeId, label)
{
this.currentGraph.getNodeById(nodeId).setLabel(label);
}

GraphView.prototype.fixGraphView=function(edgeType)
{
if ( edgeType != null ) {
this.typeOfNewEdges = edgeType;
this.graphFixed = true;

this.edgeMode.style.backgroundColor = "red";
this.dragMode.style.backgroundColor = "silver";
} else {
this.graphFixed = false;
if ( this.nodeFocus != null ) {
this.currentGraph.getNodeById(this.nodeFocus).setFocused(false);
this.nodeFocus = null;
}

this.edgeMode.style.backgroundColor = "silver";
this.dragMode.style.backgroundColor = "lime";
}
}

GraphView.prototype.showHelpText=function(helpText)
{
if ( this.helpText.childNodes[0].nodeValue != helpText ) {
this.helpText.style.color = "blue";
this.helpText.childNodes[0].nodeValue = helpText;
}
}

GraphView.prototype.showAlertText=function(alertText)
{
if ( this.helpText.childNodes[0].nodeValue != alertText ) {
this.helpText.style.color = "red";
this.helpText.childNodes[0].nodeValue = alertText;
}
}

GraphView.prototype.deleteMessage=function()
{
if ( this.helpText.childNodes[0].nodeValue != "" ) this.helpText.childNodes[0].nodeValue = "";
}

GraphView.prototype.createCallbackPanel=function()
{
var panel = document.createElement("div");
this.edgeMode = document.createElement("div");
var edgeModeLabel = document.createElement("span");
edgeModeLabel.appendChild(document.createTextNode("Edge Mode"));
this.dragMode = document.createElement("div");
var dragModeLabel = document.createElement("span");
dragModeLabel.appendChild(document.createTextNode("Drag Mode"));
this.helpText = document.createElement("span");
this.helpText.appendChild(document.createTextNode(""));
$(this.edgeMode).css({'position':'absolute', 'left':'20px', 'top': '2px', 'width':'15px', 'height':'15px', 'background-color':'silver'});
$(edgeModeLabel).css({'position':'absolute', 'left':'40px', 'top': '2px', 'font-size':'small'});
$(this.dragMode).css({'position':'absolute', 'left':'120px', 'top': '2px', 'width':'15px', 'height':'15px', 'background-color':'lime'});
$(dragModeLabel).css({'position':'absolute', 'left':'140px', 'top': '2px', 'font-size':'small'});
$(this.helpText).css({'position':'absolute', 'left':'210px', 'top': '2px', 'font-size':'small', 'color':'#ff0000'});
var t = this;
this.edgeMode.onclick = function(e) {
if ( !t.graphFixed ) t.fixGraphView(t.style.standardEdgeType);
t.modeToggeled = true;
}
this.dragMode.onclick = function(e) {
if ( t.graphFixed ) t.fixGraphView();
}
this.container.appendChild(this.edgeMode);
this.container.appendChild(this.dragMode);
this.container.appendChild(edgeModeLabel);
this.container.appendChild(dragModeLabel);
this.container.appendChild(this.helpText);
}




GraphView.prototype.isElementOfArray=function(element, array) {var result = false;for ( var i = 0; i < array.length; i++) if ( element == array[i] ) result = true; return result;}

GraphView.prototype.replaceItem=function(array, oldItem, newItem) {var temp = new Array();for ( var i = 0; i < array.length; i ++ ) { if ( array[i] != oldItem ) temp.push(array[i]); else temp.push( newItem );}return temp;}

GraphView.prototype.deleteItem=function(array, item){var temp = new Array();for ( var i = 0; i < array.length; i++ ) if ( array[i].id != item.id ) temp.push(array[i]);return temp;}

GraphView.prototype.deleteDataItem=function(array, item){var temp = new Array();for ( var i = 0; i < array.length; i++ ) if ( array[i].getId() != item.getId() ) temp.push(array[i]);return temp;}




GraphView.prototype.readInPlugins = function(pluginObject)
{
var y = this.config.posY - this.config.pluginPaneHeight;
var x = 0;
for ( var i = 0; i < pluginObject.length; i++ ) {
pluginObject[i].plugin.init(this, pluginObject[i].initData);
this.pluginHash[0][pluginObject[i].name] = pluginObject[i].plugin;
if ( pluginObject[i].classes == null ) pluginObject[i].plugin.htmlElement.className = pluginObject[i].classes;
if ( pluginObject[i].plugin.htmlElement != null ) {
pluginObject[i].plugin.htmlElement.id = this.id + "_plugin_" + i;
if ( pluginObject[i].location == "canvas" ) { 
$(pluginObject[i].plugin.htmlElement).css({'position':'absolute','left':x+'px','top':'0px'});
this.pluginPane.appendChild(pluginObject[i].plugin.htmlElement);
x += parseInt(document.getElementById(this.id + "_plugin_" + i).offsetWidth) + 10;
} else if ( pluginObject[i].location == "none" ){
pluginObject[i].plugin.htmlElement.style.position = "relative";
} else if ( pluginObject[i].location instanceof Object ) {
pluginObject[i].location.appendChild(pluginObject[i].plugin.htmlElement);
} else if ( pluginObject[i].location instanceof String ) {
var element = document.getElementById(pluginObject[i].location);
element.appendChild(pluginObject[i].plugin.htmlElement);
}
}
}
this.pluginsInitialized = true;
}

GraphView.prototype.getPluginByName=function(name)
{
return this.pluginHash[0][name];
}

GraphView.prototype.addItemListenerToGraph=function()
{
for ( var i = 0; i < this.itemChangeListener.length; i++ )
this.currentGraph.registerItemChangeListener(this.itemChangeListener[i]);
}




GraphView.prototype.getCurrentGraph=function(){return this.currentGraph;}

GraphView.prototype.getCurrentLayout=function(){return this.currentGraph.getLayout();}

GraphView.prototype.registerViewChangeListener=function(listener){this.changeListener.push(listener);}

GraphView.prototype.registerItemChangeListener=function(listener)
{
this.itemChangeListener.push(listener);
for ( var i = 0; i < this.graphArray.length; i++ ) 
this.graphArray[i].registerItemChangeListener(listener);
}



function Layout()
{
this.position = new Array(new Object());
this.elements = new Array();
this.maxX = 0;
this.minX = Number.MAX_VALUE;
this.maxY = 0;
this.minY = Number.MAX_VALUE;
this.maxXID;
this.maxYID;
this.minXID;
this.minYID;
this.center = new Point(0,0);
return this;
}

Layout.prototype.type = "Layout";

Layout.prototype.setNodePosition=function(nodeId, x, y, init)
{
if ( this.position[0][nodeId] == null ) {
this.position[0][nodeId] = new Point(x,y);
} else {
this.position[0][nodeId].x = x;
this.position[0][nodeId].y = y;
}
this.elements.push(nodeId);
this.setMinMax(nodeId, x, y);
if ( init == undefined || !init ) {
this.checkMinMax();
}
this.center = new Point( this.minX + parseInt((this.maxX - this.minX) / 2), 
                         this.minY + parseInt((this.maxY - this.minY) / 2) );
}

Layout.prototype.setRandomNodePosition=function(nodeId, init)
{
var pos = this.getRandomPoint(this.maxX - this.minX, this.maxY - this.minY);
this.setNodePosition(nodeId, pos.x, pos.y, init);
}

Layout.prototype.checkMinMax=function()
{
this.maxX = 0;
this.maxY = 0;
this.minX = Number.MAX_VALUE;
this.minY = Number.MAX_VALUE;
for ( var i = 0; i < this.elements.length; i++ ) {
var nodeId = this.elements[i];
var x = this.position[0][nodeId].x;
var y = this.position[0][nodeId].y;
this.setMinMax(nodeId, x, y);
}
this.center = new Point( this.minX + parseInt((this.maxX - this.minX) / 2), 
                         this.minY + parseInt((this.maxY - this.minY) / 2) );
}

Layout.prototype.setMinMax=function(nodeId, x, y)
{
if ( this.maxX < parseInt(x) ) {
this.maxX = parseInt(x);
this.maxXID = nodeId;
}
if ( this.minX > parseInt(x) ) {
this.minX = parseInt(x);
this.minXID = nodeId;
}
if ( this.maxY < parseInt(y) ) {
this.maxY = parseInt(y);
this.maxYID = nodeId;
}
if ( this.minY > parseInt(y) ) {
this.minY = parseInt(y);
this.minYID = nodeId;
}
}

Layout.prototype.getNodePosition=function(nodeId)
{
return this.position[0][nodeId];
}

Layout.prototype.getCenter=function()
{
return this.center;
}

Layout.prototype.getCopy=function(id)
{
var copy = new Layout();
for ( var i = 0; i < this.elements.length; i++ ) {
copy.position[0][id + this.elements[i]] = this.position[0][this.elements[i]];
copy.elements[i] = id + this.elements[i];
}
copy.center = this.center;
copy.maxX = this.maxX;
copy.minX = this.minX;
copy.maxY = this.maxY;
copy.minY = this.minY;
return copy;
}




Layout.prototype.defaultLayoutRandom=function(graph, width, height)
{
var layout = new Layout();
var nodes = graph.getNodes();
for ( var i = 0; i < nodes.length; i++ ) {
layout.setNodePosition(nodes[i].getId(), parseInt(width*Math.random()), parseInt(height*Math.random()), true);
}
return layout;
}

Layout.prototype.defaultLayoutCircle=function(graph, bore)
{
var layout = new Layout();
var nodes = graph.getNodes();
var alpha = (2 * Math.PI) / nodes.length;
var width2 = bore / 2;
var temp = 0;
for ( var i = 0 ; i < nodes.length; i++ ) {
layout.setNodePosition(nodes[i].getId(), width2 + (Math.cos(temp) * width2) ,  width2 + (Math.sin(temp)*width2) , true);
temp += alpha;
}
return layout;
}

Layout.prototype.defaultLayoutRect=function(graph, width, height)
{
var layout = new Layout();
var nodes = graph.getNodes();
var quadrat = parseInt(Math.sqrt(nodes.length));
var xStep = parseInt(width / quadrat);
var yStep = parseInt(height / (quadrat + 1));
var xTemp = 0;
var yTemp = 0;
for ( var i = 1; i <= nodes.length ; i++ ) {
layout.setNodePosition(nodes[i-1].getId(), xTemp, yTemp, true);
if ( (i % quadrat) == 0 ) {
xTemp = 0; yTemp += yStep;
} else {
xTemp += xStep;
}
}
return layout;
}

Layout.prototype.getRandomPoint=function(width, height)
{
return new Point( parseInt(width*Math.random()), parseInt(height*Math.random()) );
}

function Point(x,y)
{
this.x = x;
this.y = y;
}

Point.prototype.type = "Point";



function Node(lab, wei, typ, act, data, dataLabel) 
{
this.label = lab;
this.id;
this.weight = wei;
this.active = act;
this.type = typ;
this.ghosted = false;
this.focused = false;
this.idSettable = true;
this.inputField = false;
this.position = new Point(0,0);
this.data = data || null;
this.dataLabel = dataLabel || "Data:";
this.views = new Array();
this.parrentGraph = null;
return this;
}

Node.prototype.type = "Node";

Node.prototype.getId=function()
{
return this.id;
}

Node.prototype.setId=function(ID, graph)
{
if ( this.idSettable ) {
this.id = ID;
this.parentGraph = graph;
this.idSettable = false;
return true;
} else {
return false;
}
}

Node.prototype.getLabel=function() 
{
return this.label;
}

Node.prototype.setLabel=function(la)
{
if ( this.label != la ) {
this.label = la;
this.parentGraph.nodePropertyChangeCallback(this);
for ( var i = 0; i < this.views.length; i ++ ) this.views[i].changeLabel(this.label);
}
}

Node.prototype.getWeight=function()
{
return this.weight;
}

Node.prototype.setWeight=function(weight)
{
if ( this.weight != weight ) {
if ( weight > 100 ) this.weight = 100;
else this.weight = weight;
this.parentGraph.nodePropertyChangeCallback(this);
for ( var i = 0; i < this.views.length; i ++ ) this.views[i].changeWeight(this.weight);
}
}

Node.prototype.getType=function()
{
return this.type;
}

Node.prototype.setType=function(type)
{
if ( this.type != type ) {
this.type = type;
this.parentGraph.nodePropertyChangeCallback(this);
for ( var i = 0; i < this.views.length; i ++ ) this.views[i].changeType(this.type);
}
}

Node.prototype.isActive=function() 
{
return this.active;
}

Node.prototype.setActive=function(active) 
{
if ( this.active != active ) {
this.active = active;
this.parentGraph.nodePropertyChangeCallback(this);
for ( var i = 0; i < this.views.length; i ++ ) this.views[i].changeActivityStatus(this.active);
}
}

Node.prototype.isGhosted=function()
{
return this.ghosted;
}

Node.prototype.setGhosted=function(ghost)
{
if ( this.ghosted != ghost ) {
this.ghosted = ghost;
this.parentGraph.nodePropertyChangeCallback(this);
for ( var i = 0; i < this.views.length; i ++ ) this.views[i].changeGhostNodeStatus(this.ghosted);
}
}

Node.prototype.isFocused=function()
{
return this.focused;
}

Node.prototype.setFocused=function(foc)
{
if ( this.focused != foc ) {
this.focused = foc;
this.parentGraph.nodePropertyChangeCallback(this);
for ( var i = 0; i < this.views.length; i ++ ) this.views[i].changeFocusStatus(this.focused);
}
}

Node.prototype.isLabelInputField=function()
{
return this.inputField;
}

Node.prototype.setInputFieldAsLabel=function(input)
{
this.inputField = input;
if ( this.inputField ) {
for ( var i = 0; i < this.views.length; i ++ ) this.views[i].showInputField();
}
}

Node.prototype.getPosition = function()
{
return this.position;
}

Node.prototype.setPosition = function(pos)
{
this.position = pos;
for ( var i = 0; i < this.views.length; i ++ ) this.views[i].setPosition(this.position.x, this.position.y);
}

Node.prototype.getData = function()
{
return this.data;
}

Node.prototype.setData = function(data)
{
this.data = data;
this.parentGraph.nodePropertyChangeCallback(this);
}

Node.prototype.getDataLabel = function()
{
return this.dataLabel;
}

Node.prototype.setDataLabel = function(dataLabel)
{
this.dataLabel = dataLabel;
this.parentGraph.nodePropertyChangeCallback(this);
}

Node.prototype.highlight = function()
{
for ( var i = 0; i < this.views.length; i ++ ) this.views[i].highlight();
}

Node.prototype.register=function(view)
{
this.views.push(view);
}



function NodeSet(graphId, id, name)
{
this.graphId = graphId;
this.id = id;
if ( name == null ) this.name = graphId + "_nodeSet";
else this.name = name;
this.nodeCounter = 0;
this.nextNodeId = this.graphId + "n" + this.nodeCounter;
this.nodes = new Array();
this.nodesHash = new Array(new Object());
}

NodeSet.prototype.type = "NodeSet";

NodeSet.prototype.addNode=function(node, graph)
{
if ( node.setId(this.nextNodeId, graph) ) {
this.nodes.push(node);
this.nodesHash[0][node.getId()] = node;
this.nodeCounter++;
this.nextNodeId = this.graphId + "n" + this.nodeCounter;
return node;
} else {
return null;
}
}

NodeSet.prototype.removeNode=function(node)
{
this.nodes = this.deleteItem(this.nodes, node);
this.nodesHash[0][node.getId()] = null;
}

NodeSet.prototype.removeNodeSet=function(nodeSet)
{
for ( var i = 0; i < nodeSet.length; i++ ) {
this.removeNode(nodeSet[i]);
}
}




NodeSet.prototype.getNodeById=function(nodeId)
{
return this.nodesHash[0][nodeId];
}

NodeSet.prototype.getName=function()
{
return this.name;
}

NodeSet.prototype.getId=function()
{
return this.id;
}

NodeSet.prototype.getNodes=function()
{
return this.nodes;
}




NodeSet.prototype.setName=function(name)
{
this.name = name;
}

NodeSet.prototype.deleteItem=function(array, item) 
{
var temp = new Array();
for ( var i = 0; i < array.length; i ++ ) {
if ( array[i].getId() != item.getId() ) {
temp.push(array[i]);
} else {

}
}
return temp;
}



function NodeStyle(name, inactiveColor, activeColor, border)
{
this.n = name;
this.activeColor = activeColor;
this.inactiveColor = inactiveColor;
this.border = border;
this.views = new Array();
}

NodeStyle.prototype.type = "NodeStyle";
NodeStyle.prototype.red =     ["red",       "#c81010", "#c83636", "#c85a5a", "#c88080", "#c8a6a6"];
NodeStyle.prototype.blue =    ["blue",      "#435eb5", "#5b70b5", "#72824d", "#889265", "#9da3b5"];
NodeStyle.prototype.green =   ["green",     "#308a24", "#498a39", "#598a4d", "#6a8a62", "#7b8a77"];
NodeStyle.prototype.yellow = ["yellow",    "#fecf19", "#fed847", "#fee275", "#feeba3", "#fef4d0"];
NodeStyle.prototype.orange =  ["orange",    "#da2b92", "#f0a143", "#f0b56e", "#f0c99a", "#f0dcc5"];
NodeStyle.prototype.violet =  ["violet",    "#6f167c", "#722b7c", "#743f7c", "#77547c", "#79677c"];
NodeStyle.prototype.torquoise =  ["torquoise", "#42d2a4", "#5ed2ad", "#7cd2b6", "#99d2c0", "#b7d2c9"];
NodeStyle.prototype.brown =  ["brown",     "#7c4d1a", "#7c572e", "#7c6042", "#7c6a56", "#7c7369"];
NodeStyle.prototype.pink =   ["pink",      "#da2b92", "#da4ea1", "#da71af", "#da94bd", "#dab7cc"];
NodeStyle.prototype.gray =  ["gray",      "#7d7d7d", "#969696", "#b0b0b0", "#c9c9c9", "#e3e3e3"];
NodeStyle.prototype.white =  ["white",     "#ffffff", "#ffffff", "#ffffff", "#ffffff", "#ffffff"];
NodeStyle.prototype.lightBlue =  ["lightBlue", "#b1c5ff", "#bfcfff", "#ccd9ff", "#d9e2ff", "#ebecff"];
NodeStyle.prototype.lightRed =  ["lightRed",  "#ff3f3d", "#ff6866", "#ff908f", "#ffb8b8", "#ffe1e0"];
NodeStyle.prototype.lightGreen = ["lightGreen","#4eff57", "#70ff78", "#94ff99", "#b8ffbb", "#dbffdd"];
NodeStyle.prototype.lightYellow=["lightYellow","#fdff4e", "#fdff70", "#feff94", "#feffb8", "#ffffdb"];
NodeStyle.prototype.signalRed =  ["signalRed", "#ff0000", "#ff3333", "#ff6666", "#ff9999", "#ffcccc"];
NodeStyle.prototype.signalGreen=["signalGreen","#00ff00", "#33ff33", "#66ff66", "#99ff99", "#ccffcc"];
NodeStyle.prototype.signalYellow=["signalYellow","#ffff00", "#ffff33", "#ffff66", "#ffff99", "#ffffcc"];
NodeStyle.prototype.signalOrange=["signalOrange","#ff8a0a", "#ffa747", "#ffbd75", "#ffd19e", "#ffe4c7"];
NodeStyle.prototype.signalBlue=  ["signalBlue","#0000ff", "#3333ff", "#6666ff", "#9999ff", "#ccccff"];

NodeStyle.prototype.getActiveColor=function()
{
return this.activeColor;
}

NodeStyle.prototype.setActiveColor=function(color)
{
this.activeColor = color;
for ( var i = 0; this.views.length; i++) this.views[i].activeColorChanged(this.activeColor);
}

NodeStyle.prototype.getInactiveColor=function()
{
return this.inactiveColor;
}

NodeStyle.prototype.setInactiveColor=function(color)
{
this.inactiveColor = color;
for ( var i = 0; this.views.length; i++) this.views[i].inactiveColorChanged(this.inactiveColor);
}

NodeStyle.prototype.getBorder=function()
{
return this.border;
}

NodeStyle.prototype.setBorder=function(border)
{
this.border = border;
for ( var i = 0; this.views.length; i++) this.views[i].changeBorder(this.border);
}

NodeStyle.prototype.getName=function()
{
return this.n;
}

NodeStyle.prototype.register=function(view)
{
this.views.push()
}



function OptionFrame(graphView, id, x, y, width, type, data)
{
this.stringLimit = 10;
this.type = type;
this.data = data;
this.label = document.createTextNode(this.data.getLabel());
if (this.data.getLabel().length > this.stringLimit ) this.shortLabel = document.createTextNode(this.data.getLabel().substring(0,this.stringLimit) + "...");
else this.shortLabel = this.label;
this.id = id;
this.graphView = graphView;
this.isMinimized = false;
this.elements = new Array();
this.width = width;
this.minimizedWidth = 150;
this.height = 25;
this.x = x;
this.y = y;
this.relX = x;
this.relY = y;
this.htmlElement = this.getHTMLElement(this.x, this.y, this.width, this.height);
this.addChildren();
$(this.htmlElement).css('font-size', 'small');
$(this.htmlElement).css('-moz-border-radius-bottomleft', "8px");
$(this.htmlElement).css('-moz-border-radius-bottomright', "8px");
$(this.htmlElement).css('-moz-border-radius-topleft', "8px");
$(this.htmlElement).css('-moz-border-radius-topright', "8px");
this.graphView.frameOpen = true;
}

OptionFrame.prototype.type = "OptionFrame";
OptionFrame.prototype.showNodeProperties = 0;
OptionFrame.prototype.showEdgeProperties = 1;
OptionFrame.prototype.getHTMLElement=function(x, y, width, height)
{
var div = document.createElement("div");
div.id = this.id;
this.container = document.createElement("div");
this.labelNode = document.createElement("span");
this.labelNode.appendChild(this.shortLabel);
this.labelNode.style.maxWidth = "80px";
this.closeButton = document.createElement("button");
var closeIcon = document.createElement("img");
var t = this;
var id = this.id;
this.closeButton.onclick = function(){
t.closeFrame();
}
$(this.closeButton).css('-moz-border-radius-bottomleft', "8px");
$(this.closeButton).css('-moz-border-radius-bottomright', "8px");
$(this.closeButton).css('-moz-border-radius-topleft', "8px");
$(this.closeButton).css('-moz-border-radius-topright', "8px");
this.iconSrc = document.createAttribute("src");
this.iconSrc.nodeValue = this.graphView.iconPath + "/cross.gif";
closeIcon.setAttributeNode(this.iconSrc);
$(closeIcon).css({'position':'absolute', 'top':'0px', 'left':'0px'});
this.closeButton.appendChild(closeIcon);
$(this.closeButton).css({'position':'absolute','width':'20px','height':'20px','top':'2px',
'left':this.width - 22 + "px",'border':'1px solid silver','background-color':'silver'});
$(this.labelNode).css({'position':'absolute','left':'4px','top':'3px'});
this.container.appendChild(this.closeButton);
this.container.appendChild(this.labelNode);
$(div).css({'position':'absolute','top':y + "px", 'left':x + "px",'height':height + "px",
'width':width + 'px','border':'2px solid silver', 'background-color':'#fff'});
div.appendChild(this.container);
var t = this;
return div;
}

OptionFrame.prototype.addChildren=function()
{
var elementHeight = 22;
var initialHeight = 10;
var width = 80;
var left = 5;
var left2 = 65;
if ( this.type == 0 || this.type == 1 ) {
this.typeToIndex = new Array(new Object());
this.indexToType = new Array(new Object());

var labelLabel = document.createTextNode("Label:");
var labelSpan = document.createElement("span");
labelSpan.appendChild(labelLabel);
var labelVisible = document.createElement("input");
labelVisible.type = "checkbox";
var label = document.createElement("input");
label.value = this.data.getLabel();
var weightLabel = document.createTextNode("Weight:");
var weightSpan = document.createElement("span");
weightSpan.appendChild(weightLabel);
var weight = document.createElement("input");
weight.style.width = "30px";
weight.value = this.data.getWeight();
var typeLabel = document.createTextNode("Type:");
var typeSpan = document.createElement("span");
typeSpan.appendChild(typeLabel);
var typeSelect = document.createElement("select");
if ( this.type == OptionFrame.prototype.showNodeProperties ) {
var dataLabel = document.createTextNode(this.data.getDataLabel());
var dataSpan = document.createElement("span");
dataSpan.appendChild(dataLabel);
var data = document.createElement("input");
data.value = this.data.getData();
for ( var i = 0; i < this.graphView.style.nodeStyles.length; i++ ) {
var option = document.createElement("option");
option.appendChild(document.createTextNode(this.graphView.style.nodeStyles[i].getName()));
this.typeToIndex[0][this.graphView.style.nodeTypes[i]] = i;
this.indexToType[0][i] = this.graphView.style.nodeTypes[i];
typeSelect.appendChild(option);
}
typeSelect.selectedIndex = this.typeToIndex[0][this.data.getType()];
}else if ( this.type == OptionFrame.prototype.showEdgeProperties ) {
for ( var i = 0; i < this.graphView.style.edgeStyles.length; i++ ) {
var option = document.createElement("option");
option.appendChild(document.createTextNode(this.graphView.style.edgeStyles[i].getName()));
this.typeToIndex[0][this.graphView.style.edgeTypes[i]] = i;
this.indexToType[0][i] = this.graphView.style.edgeTypes[i];
typeSelect.appendChild(option);
}
typeSelect.selectedIndex = this.typeToIndex[0][this.data.getType()];
var directedSelect = document.createElement("select");
var opt1 = document.createElement("option");
opt1.appendChild(document.createTextNode("directed"));
var opt2 = document.createElement("option");
opt2.appendChild(document.createTextNode("undirected"));
directedSelect.appendChild(opt1);
directedSelect.appendChild(opt2);
if ( this.data.isDirected() ) directedSelect.selectedIndex = 0;
else directedSelect.selectedIndex = 1;
labelVisible.checked = this.data.isLabelVisible();
$(directedSelect).css({'position':'absolute', 'top':initialHeight + 4 * elementHeight + 'px', 'left': left2 + 'px', 'width': width + 5 + 'px'});
}
var okButton = document.createElement("button");
okButton.appendChild(document.createTextNode("Ok"));
var cancelButton = document.createElement("button");
cancelButton.appendChild(document.createTextNode("Cancel"));

$(labelSpan).css({'position':'absolute', 'top': initialHeight + elementHeight + 'px', 'left':left + 'px'});
$(label).css({'position':'absolute', 'top': initialHeight + elementHeight + 'px', 'left': left2 + 'px', 'width' : width + 'px'});
$(labelVisible).css({'position':'absolute', 'top': initialHeight + elementHeight + 'px', 'left':(left2+width - 5)  + 'px'});
$(weightSpan).css({'position':'absolute', 'top': initialHeight + 2 * elementHeight + 'px', 'left':left + 'px'});
$(weight).css({'position':'absolute', 'top': initialHeight + 2 * elementHeight + 'px', 'left': left2 + 'px', 'width' : width + 'px'});
$(typeSpan).css({'position':'absolute', 'top':initialHeight + 3 * elementHeight + 'px', 'left':left + 'px'});
$(typeSelect).css({'position':'absolute', 'top':initialHeight + 3 * elementHeight + 'px', 'left': left2 + 'px', 'width': width + 5 + 'px'});
if ( this.type == OptionFrame.prototype.showNodeProperties ) $(dataSpan).css({'position':'absolute', 'top':initialHeight + 4 * elementHeight + 'px', 'left':left + 'px'});
if ( this.type == OptionFrame.prototype.showNodeProperties ) $(data).css({'position':'absolute', 'top':initialHeight + 4 * elementHeight + 'px', 'left': left2 + 'px', 'width': width + 'px'});
var t = this;
if ( this.type == OptionFrame.prototype.showNodeProperties ) {
this.okEvent = function() {
var wei = parseInt(weight.value);
var lab = label.value;
var typ = t.indexToType[0][typeSelect.selectedIndex];
var dat = data.value;
t.data.setWeight(wei);
t.data.setLabel(lab);
t.data.setType(typ);





t.closeFrame();
}
data.onkeydown=function(e){ 
var code;
if (!e)e = window.event;
  if (e.which)  code = e.which;
  else if (e.keyCode) code = e.keyCode;
if ( code == 13 ) t.okEvent();
}
} else if ( this.type == OptionFrame.prototype.showEdgeProperties ) {
this.okEvent = function() {
var wei = parseInt(weight.value);
var lab = label.value;
var typ = t.indexToType[0][typeSelect.selectedIndex];
var labVis = labelVisible.checked;
if ( directedSelect.selectedIndex == 0 ) var dir = true;
else var dir = false;
t.data.setWeight(wei);
t.data.setLabel(lab);
t.data.setType(typ);
t.data.setDirected(dir);
t.data.setLabelVisible(labVis);
t.closeFrame();

}
}
okButton.onclick = this.okEvent;
label.onkeydown=function(e){
var code;
if (!e)e = window.event;
  if (e.which)  code = e.which;
  else if (e.keyCode) code = e.keyCode;
if ( code == 13 ) t.okEvent();
}
weight.onkeydown=function(e){
var code;
if (!e)e = window.event;
  if (e.which)  code = e.which;
  else if (e.keyCode) code = e.keyCode;
if ( code == 13 ) t.okEvent()}
cancelButton.onclick = function() {
t.closeFrame();
}

this.htmlElement.appendChild(labelSpan);
this.htmlElement.appendChild(label);
this.htmlElement.appendChild(weightSpan);
this.htmlElement.appendChild(weight);
this.htmlElement.appendChild(typeSpan);
this.htmlElement.appendChild(typeSelect);
if ( this.type == OptionFrame.prototype.showNodeProperties ) {
this.htmlElement.appendChild(dataSpan);
this.htmlElement.appendChild(data);
}
this.htmlElement.appendChild(okButton);
this.htmlElement.appendChild(cancelButton);
if (this.type == OptionFrame.prototype.showEdgeProperties) {
$(label).css({'position':'absolute', 'top': initialHeight + elementHeight + 'px', 'left': left2 + 'px', 'width' : ( width-8 ) + 'px'});
this.htmlElement.appendChild(labelVisible);
this.htmlElement.appendChild(directedSelect);
}
var t = this;
this.htmlElement.onmouseover = function() {
t.graphView.cleanGlassPane();
}
this.width = 160;
if ( this.type == OptionFrame.prototype.showNodeProperties ) this.height = initialHeight + 5 * elementHeight + 30;
else this.height = initialHeight + 5 * elementHeight + 30;
this.htmlElement.style.height = this.height + "px";
this.htmlElement.style.width = this.width + "px";
this.closeButton.style.left = this.width - 22 + "px";
if ( this.type == OptionFrame.prototype.showNodeProperties ) {
$(okButton).css({'position':'absolute', 'top':initialHeight + 5 * elementHeight + 'px', 'left': this.width - 132 + 'px', 'width':60 + 'px'});
$(cancelButton).css({'position':'absolute', 'top':initialHeight + 5 * elementHeight + 'px', 'left': this.width - 77 + left + 'px', 'width': 60 + 'px'});
} else if ( this.type == OptionFrame.prototype.showEdgeProperties ) {
$(okButton).css({'position':'absolute', 'top':initialHeight + 5 * elementHeight + 'px', 'left': this.width - 132 + 'px', 'width':60 + 'px'});
$(cancelButton).css({'position':'absolute', 'top':initialHeight + 5 * elementHeight + 'px', 'left': this.width - 77 + left + 'px', 'width': 60 + 'px'});
}
}
}

OptionFrame.prototype.addToCanvas=function(canvas)
{
this.canvas = canvas;
canvas.appendChild(this.htmlElement);

this.setZIndex(this.graphView.maxZ);
}

OptionFrame.prototype.rearangeChildren=function()
{
var height = 30;
var x = parseInt(this.htmlElement.style.left.replace("px", ""));
var y = parseInt(this.htmlElement.style.top.replace("px", ""));
for ( var i = 0; i < this.elements.length; i++ ) {
if ( this.elements[i] instanceof DefaultNodeView ) {
this.elements[i].setPosition(x + 15, y + height);
} 
height += this.elements[i].height + 10;
}
}

OptionFrame.prototype.addChild=function(htmlNode)
{

if ( this.width < (htmlNode.width + 20) ) this.width = htmlNode.width;
if ( htmlNode instanceof DefaultNodeView ) {
htmlNode.setPosition(this.x + 15, this.y + this.height +  5);
htmlNode.setNodeFlip(true, this, 15, this.height + 5);
this.elements.push(htmlNode);
this.height += htmlNode.height + 10;
} else {

htmlNode.style.left = 5 + "px";
htmlNode.style.top = (this.height + 5) + "px";
if ( !(htmlNode instanceof HTMLDivElement) ) {
htmlNode.style.width = (this.width - 10) + "px";
} else {
if ( (parseInt(htmlNode.style.width.replace("px", ""))+15) > this.width ) {
this.htmlElement.style.width = htmlNode.style.width;
this.width = parseInt(htmlNode.style.width.replace("px", "")) + 15;
}
}
this.htmlElement.appendChild(htmlNode);
this.height += parseInt(htmlNode.style.height.replace("px","")) + 10;
this.elements.push(htmlNode);
}
this.htmlElement.style.height = this.height + "px";
this.htmlElement.style.width = this.width + "px";
}

OptionFrame.prototype.clearFrame= function()
{
for ( var i = 0; i < this.elements.length; i++ ) {
if ( this.elements[i] instanceof DefaultNodeView ) {
this.elements[i].hideNode();
} else {
this.htmlElement.removeChild(this.elements[i]);
}
}
this.htmlElement.style.height = "25px";
this.height = 25;
}

OptionFrame.prototype.setHeight=function(height) 
{
this.height = ( height + 35 );
if ( !this.isMinimized ) this.htmlElement.style.height = this.height + "px"; 
}

OptionFrame.prototype.closeFrame=function()
{
if ( this.canvas != null ) {
this.canvas.removeChild(this.htmlElement);
}
this.graphView.frameOpen=false;
}

OptionFrame.prototype.setZIndex=function(zIndex)
{
this.htmlElement.style.zIndex = zIndex;
for ( var i = 0; i < this.elements.length; i ++ ) {
if ( this.elements[i] instanceof DefaultNodeView ) {
this.elements[i].htmlElement.style.zIndex = zIndex + 1;
}
}
return zIndex + 2;
}

OptionFrame.prototype.setPosition=function(x,y)
{
this.htmlElement.style.left = (x + this.relX) + "px";
this.htmlElement.style.top = (y + this.relY) + "px";
this.x = (x + this.relX);
this.y = (y + this.relY);
this.rearangeChildren();
}
