







































Module('ca.carleton.gcrc.atlas.volumeBar','$Revision',function(mod){

var domUtil=imprt('ca.carleton.gcrc.dom.util');
var xmlRequest=imprt('ca.carleton.gcrc.xml.request');


var ELEMENT_NODE=1;










mod.VolumeBar=Class(function(publ,priv){



publ.__init__=function(){
this.volumeBarPainter=new mod.VolBarButtonPainter();
this.subVolumeBarPainter=new mod.SubVolBarButtonPainter();
this.atlasTitlePainter=new mod.AtlasTitlePainter();

this.tocDoc=null;
}




publ.RootPath=function(rootPath_){
this.rootPath=rootPath_;
}




publ.LoadToc=function(){
var modTocLoader=imprt('ca.carleton.gcrc.atlas.tocLoader');
var tocLoader=modTocLoader.GlobalLoader();

var receiver=this;
tocLoader.GetTOC(function(doc_){
receiver.tocDoc=doc_;
receiver.Repaint();
});
}




publ.ConfigureVolumeBar=function(
svgParentElement_,
buttonX_,
buttonY_,
buttonWidth_,
buttonHeight_,
mouseHandlerTemplate_,
baseTemplate_,
normalTemplate_,
selectedTemplate_,
mouseOverTemplate_,
mouseDownTemplate_
){

this.volumeBarPainter.Configure(
svgParentElement_,
buttonX_,
buttonY_,
buttonWidth_,
buttonHeight_,
mouseHandlerTemplate_,
baseTemplate_,
normalTemplate_,
selectedTemplate_,
mouseOverTemplate_,
mouseDownTemplate_
);
}




publ.ConfigureSubVolumeBar=function(
svgParentElement_,
areaX_,
areaY_,
areaWidth_,
areaHeight_
){

this.subVolumeBarPainter.Configure(
svgParentElement_,
areaX_,
areaY_,
areaWidth_,
areaHeight_
);
}




publ.ConfigureAtlasTitle=function(
svgParentElement_,
atlasTitle_,
nameAreaX_,
nameAreaY_
){

this.atlasTitlePainter.Configure(
svgParentElement_,
atlasTitle_,
nameAreaX_,
nameAreaY_
);
}




publ.ModulePath=function(modulePath_){

this.modulePath=modulePath_;
}




publ.Paint=function(){
this.atlasTitlePainter.Paint();
this.volumeBarPainter.Paint();
}




publ.Repaint=function(){

this.volumeBarPainter.Reset();

for(var child=this.tocDoc.documentElement.firstChild;child!=null;child=child.nextSibling)
{

if(ELEMENT_NODE==child.nodeType)
{
if('level'==child.tagName)
{
var nameAttrNode=child.getAttributeNode('name');
if(null!=nameAttrNode)
{
var name=nameAttrNode.value;
this.AddVolumeBarTopic(name,child);
}
}
}
}


this.Paint();
}




publ.AddVolumeBarTopic=function(label_,tocNode_){
var receiver=this;
var current=mod.IsCurrentTopic(tocNode_,this.modulePath);
this.volumeBarPainter.AddTopic(label_,current,function(){

var moduleLocation=tocNode_.getAttributeNode('location')
if(null!=moduleLocation)
{
var destination=receiver.rootPath+moduleLocation.value;
window.location=destination;
}
receiver.PaintSubVolumeBarTopic(current,tocNode_);
});
if(current)
{
this.PaintSubVolumeBarTopic(current,tocNode_);
}
}




publ.PaintSubVolumeBarTopic=function(parentCurrent_,tocNode_){

this.subVolumeBarPainter.Reset();

for(var child=tocNode_.firstChild;child!=null;child=child.nextSibling)
{

if(ELEMENT_NODE==child.nodeType)
{
if('level'==child.tagName)
{
var nameAttrNode=child.getAttributeNode('name');
if(null!=nameAttrNode)
{
var name=nameAttrNode.value;
var current=parentCurrent_&&mod.IsCurrentTopic(child,this.modulePath);
this.AddSubVolumeBarTopic(name,current,child);
}
}
}
}


this.subVolumeBarPainter.Paint();
}




publ.AddSubVolumeBarTopic=function(label_,currentFlag_,tocNode_){
var receiver=this;
this.subVolumeBarPainter.AddTopic(label_,currentFlag_,function(){

var modLocation=tocNode_.getAttributeNode('location')
if(null!=modLocation)
{
var destination=receiver.rootPath+modLocation.value;
window.location=destination;
}
});
}
});










mod.VolBarButtonPainter=Class(function(publ,priv){



publ.__init__=function(){
this.topics=new Array();
this.topElement=null;
}




publ.Configure=function(
svgParentElement_,
buttonX_,
buttonY_,
buttonWidth_,
buttonHeight_,
mouseHandlerTemplate_,
baseTemplate_,
normalTemplate_,
selectedTemplate_,
mouseOverTemplate_,
mouseDownTemplate_
){
this.svgParentElement=svgParentElement_;
this.buttonX=buttonX_;
this.buttonY=buttonY_;
this.buttonWidth=buttonWidth_;
this.buttonHeight=buttonHeight_;
this.mouseHandlerTemplate=mouseHandlerTemplate_;
this.baseTemplate=baseTemplate_;
this.normalTemplate=normalTemplate_;
this.selectedTemplate=selectedTemplate_;
this.mouseOverTemplate=mouseOverTemplate_;
this.mouseDownTemplate=mouseDownTemplate_;

this.doc=svgParentElement_.ownerDocument;
this.ns=this.doc.documentElement.namespaceURI;
}





publ.Reset=function(){

var loop;
for(loop=0;loop<this.topics.length;++loop){
var entry=this.topics[loop];


entry.mhElement.removeEventListener('click',this,false);
entry.mhElement.removeEventListener('mouseover',this,false);
entry.mhElement.removeEventListener('mouseout',this,false);
}


if(null!=this.topElement){
this.svgParentElement.removeChild(this.topElement);
}
this.topElement=null;


this.topics=new Array();
}




publ.AddTopic=function(label_,currentFlag_,func_){
var entry={};
entry.label=label_;
entry.func=func_;
entry.currentFlag=currentFlag_;
this.topics.push(entry);
}




publ.Paint=function(){
if(null!=this.topElement){
this.svgParentElement.removeChild(this.topElement);
}
this.topElement=this.doc.createElementNS(this.ns,'g');


var loop;
for(loop=0;loop<this.topics.length;++loop){
var entry=this.topics[loop];

entry.selected=false;
entry.over=false;

var buttonElement=this.doc.createElementNS(this.ns,'g');
buttonElement.setAttributeNS(null,'transform','translate('+(loop*this.buttonWidth)+',0)');
this.topElement.appendChild(buttonElement);
entry.topElement=buttonElement;

this.DrawButton(entry,loop);
}


this.svgParentElement.appendChild(this.topElement);
}




publ.DrawButton=function(entry_,index_){


for(var child=this.baseTemplate.firstChild;child!=null;child=child.nextSibling){
if(ELEMENT_NODE==child.nodeType){
entry_.topElement.appendChild(child.cloneNode(true));
}
}


entry_.topVariable=this.doc.createElementNS(this.ns,'g');
entry_.topElement.appendChild(entry_.topVariable);


var text=this.doc.createElementNS(this.ns,'text');
text.setAttributeNS(null,'x',(this.buttonX+(this.buttonWidth/2)));
text.setAttributeNS(null,'y',(this.buttonY+(this.buttonHeight/2)+4));
text.setAttributeNS(null,'text-anchor','middle');
text.setAttributeNS(null,'font-family','Arial');
text.setAttributeNS(null,'font-size','12');
if(entry_.currentFlag)
{
text.setAttributeNS(null,'font-weight','bold');
}
text.setAttributeNS(null,'fill','#000000');
entry_.topElement.appendChild(text);
text.appendChild(this.doc.createTextNode(entry_.label));


var mhElement=this.doc.createElementNS(this.ns,'g');
entry_.topElement.appendChild(mhElement);
entry_.mhElement=mhElement;


mhElement.addEventListener('click',this,false);
mhElement.addEventListener('mouseover',this,false);
mhElement.addEventListener('mouseout',this,false);
mhElement.setAttributeNS(null,'cursor','pointer');
mhElement.setAttributeNS('http://gcrc.carleton.ca','index',index_);


for(var child=this.mouseHandlerTemplate.firstChild;child!=null;child=child.nextSibling){
if(ELEMENT_NODE==child.nodeType){
mhElement.appendChild(child.cloneNode(true));
}
}

this.RefreshButton(entry_);
}




publ.handleEvent=function(event_){

var type=event_.type


var eventTarget=event_.target;


var index=0;
var attNode=eventTarget.getAttributeNodeNS('http://gcrc.carleton.ca','index');
while(null==attNode&&null!=eventTarget.parentNode){
eventTarget=eventTarget.parentNode;
attNode=eventTarget.getAttributeNodeNS('http://gcrc.carleton.ca','index');
}
if(null!=attNode){
index=attNode.nodeValue;
}

var entry=this.topics[index];
if('click'==type)
{
this.OnClick(entry);
}
else if('mouseover'==type)
{
this.OnOver(entry);
}
else if('mouseout'==type)
{
this.OnOut(entry);
}
}




publ.OnClick=function(entry_){
if(true!=entry_.selected){
this.UnselectAll();
entry_.selected=true;
this.RefreshButton(entry_);
if(null!=entry_.func){
entry_.func();
}
}
}




publ.OnOver=function(entry_){
if(true!=entry_.over){
entry_.over=true;
this.RefreshButton(entry_);
}
}




publ.OnOut=function(entry_){
if(true==entry_.over){
entry_.over=false;
this.RefreshButton(entry_);
}
}




publ.UnselectAll=function(){
var loop;
for(loop=0;loop<this.topics.length;++loop){
var entry=this.topics[loop];

if(true==entry.selected){
entry.selected=false;
this.RefreshButton(entry);
}
}
}




publ.RefreshButton=function(entry_){

domUtil.RemoveChildren(entry_.topVariable);


var template;
if(true==entry_.selected){
template=this.selectedTemplate;
}else if(true==entry_.over){
template=this.mouseOverTemplate;
}else{
template=this.normalTemplate;
}


for(var child=template.firstChild;child!=null;child=child.nextSibling){
if(ELEMENT_NODE==child.nodeType){
entry_.topVariable.appendChild(child.cloneNode(true));
}
}
}
});




mod.SubVolBarButtonPainter=Class(function(publ,priv){



publ.__init__=function(){
this.topics=new Array();
this.topElement=null;
}




publ.Configure=function(
svgParentElement_,
areaX_,
areaY_,
areaWidth_,
areaHeight_
){
this.svgParentElement=svgParentElement_;
this.areaX=areaX_;
this.areaY=areaY_;
this.areaWidth=areaWidth_;
this.areaHeight=areaHeight_;

this.doc=svgParentElement_.ownerDocument;
this.ns=this.doc.documentElement.namespaceURI;
}




publ.Reset=function(){

var loop;
for(loop=0;loop<this.topics.length;++loop){
var entry=this.topics[loop];


entry.mhElement.removeEventListener('click',this,false);
entry.mhElement.removeEventListener('mouseover',this,false);
entry.mhElement.removeEventListener('mouseout',this,false);
}


if(null!=this.topElement){
this.svgParentElement.removeChild(this.topElement);
}
this.topElement=null;


this.topics=new Array();
}





publ.AddTopic=function(label_,currentFlag_,func_){
var entry={};
entry.label=label_;
entry.func=func_;
entry.currentFlag=currentFlag_;
this.topics.push(entry);
}




publ.Paint=function(){
if(null!=this.topElement){
this.svgParentElement.removeChild(this.topElement);
}
this.topElement=this.doc.createElementNS(this.ns,'g');


var width=this.areaWidth/this.topics.length;


var loop;
for(loop=0;loop<this.topics.length;++loop){
var entry=this.topics[loop];

entry.selected=false;
entry.over=false;

entry.x=this.areaX+(loop*width);
entry.width=width;

this.DrawButton(entry,loop);
}



this.svgParentElement.appendChild(this.topElement);
}




publ.DrawButton=function(entry_,index_){

entry_.topElement=this.doc.createElementNS(this.ns,'g');
this.topElement.appendChild(entry_.topElement);


entry_.textElement=this.doc.createElementNS(this.ns,'g');
entry_.topElement.appendChild(entry_.textElement);


var mhElement=this.doc.createElementNS(this.ns,'g');
entry_.topElement.appendChild(mhElement);
entry_.mhElement=mhElement;


mhElement.addEventListener('click',this,false);
mhElement.addEventListener('mouseover',this,false);
mhElement.addEventListener('mouseout',this,false);
mhElement.setAttributeNS(null,'cursor','pointer');
mhElement.setAttributeNS('http://gcrc.carleton.ca','index',index_);


var mhRect=this.doc.createElementNS(this.ns,'rect');
mhRect.setAttributeNS(null,'x',entry_.x);
mhRect.setAttributeNS(null,'y',this.areaY);
mhRect.setAttributeNS(null,'width',entry_.width);
mhRect.setAttributeNS(null,'height',this.areaHeight);
mhRect.setAttributeNS(null,'fill','#000000');
mhRect.setAttributeNS(null,'opacity',0);
mhElement.appendChild(mhRect);

this.RefreshButton(entry_);
}




publ.RefreshButton=function(entry_){

domUtil.RemoveChildren(entry_.textElement);


var fontSize;
var fill;
if(true==entry_.selected){
fontSize='14';
fill='#ffffff';
}else if(true==entry_.over){
fontSize='12';
fill='#ffffff';
}else{
fontSize='12';
fill='#000000';
}

var text=this.doc.createElementNS(this.ns,'text');
text.setAttributeNS(null,'x',(entry_.x+(entry_.width/2)));
text.setAttributeNS(null,'y',(this.areaY+(this.areaHeight/2)+4));
text.setAttributeNS(null,'text-anchor','middle');
text.setAttributeNS(null,'font-family','Arial');
text.setAttributeNS(null,'font-size',fontSize);
if(entry_.currentFlag)
{
text.setAttributeNS(null,'font-weight','bold');
}
text.setAttributeNS(null,'fill',fill);
entry_.textElement.appendChild(text);
text.appendChild(this.doc.createTextNode(entry_.label));
}




publ.handleEvent=function(event_){

var type=event_.type


var eventTarget=event_.target;


var index=0;
var attNode=eventTarget.getAttributeNodeNS('http://gcrc.carleton.ca','index');
while(null==attNode&&null!=eventTarget.parentNode){
eventTarget=eventTarget.parentNode;
attNode=eventTarget.getAttributeNodeNS('http://gcrc.carleton.ca','index');
}
if(null!=attNode){
index=attNode.nodeValue;
}

var entry=this.topics[index];
if('click'==type)
{
this.OnClick(entry);
}
else if('mouseover'==type)
{
this.OnOver(entry);
}
else if('mouseout'==type)
{
this.OnOut(entry);
}
}




publ.OnClick=function(entry_){
if(true!=entry_.selected){
this.UnselectAll();
entry_.selected=true;
this.RefreshButton(entry_);
if(null!=entry_.func){
entry_.func();
}
}
}




publ.OnOver=function(entry_){
if(true!=entry_.over){
entry_.over=true;
this.RefreshButton(entry_);
}
}




publ.OnOut=function(entry_){
if(true==entry_.over){
entry_.over=false;
this.RefreshButton(entry_);
}
}




publ.UnselectAll=function(){
var loop;
for(loop=0;loop<this.topics.length;++loop){
var entry=this.topics[loop];

if(true==entry.selected){
entry.selected=false;
this.RefreshButton(entry);
}
}
}
});




mod.AtlasTitlePainter=Class(function(publ,priv){



publ.__init__=function(){
this.topics=new Array();
this.topElement=null;
}




publ.Configure=function(
svgParentElement_,
atlasTitle_,
nameAreaX_,
nameAreaY_
){
this.svgParentElement=svgParentElement_;
this.atlasTitle=atlasTitle_;
this.nameAreaX=nameAreaX_;
this.nameAreaY=nameAreaY_;

this.doc=svgParentElement_.ownerDocument;
this.ns=this.doc.documentElement.namespaceURI;
}




publ.Reset=function(){

if(null!=this.topElement){
this.svgParentElement.removeChild(this.topElement);
}
this.topElement=null;
}




publ.Paint=function(){
this.Reset();

if(null!=this.svgParentElement){
var text=this.doc.createElementNS(this.ns,'text');
text.setAttributeNS(null,'x',this.nameAreaX);
text.setAttributeNS(null,'y',this.nameAreaY);
text.setAttributeNS(null,'text-anchor','middle');
text.setAttributeNS(null,'font-family','Arial');
text.setAttributeNS(null,'font-size','15');
text.setAttributeNS(null,'font-weight','bold');

text.appendChild(this.doc.createTextNode(this.atlasTitle));

this.topElement=text;
this.svgParentElement.appendChild(this.topElement);
}
}

});

mod.IsCurrentTopic=function(tocNode_,modulePath_){

var moduleAttrNode=tocNode_.getAttributeNode('module');
if(null!=moduleAttrNode)
{
var moduleValue=moduleAttrNode.value;
if(moduleValue==modulePath_){
return true;
}
}


for(var child=tocNode_.firstChild;child!=null;child=child.nextSibling)
{

if(ELEMENT_NODE==child.nodeType)
{
if('level'==child.tagName)
{
if(true==mod.IsCurrentTopic(child,modulePath_)){
return true;
}
}
}
}

return false;
}

});