var Project = new Object();
window.addListener(Project);
Project.activeItem = null;
Project.image = null;
Project.images = [];
Project.activeStep = null;
Project.lastStep = null;
Project.steps = [];
Project.onload = function()
{
 if (document.getElementById)
 {
  this.data = new InfoItem(this, document.getElementById('data'));
  this.activeItem = this.data;
  this.description = new InfoItem(this, document.getElementById('projectdesc'));
/*
  this.image = document.getElementById('projectView');
  var src = this.image.src;
  var imgs = document.getElementsByClassName('stepNavi')[0].getElementsByTagName('li');
  var i = imgs.length - 1;
  
  var button = new Button(this, imgs[i].getElementsByTagName('a')[0], 1);
  this.steps[i] = button;
  this.lastStep = i;
  
  while (1 < i--)
  {
   var img = new Image();
   img.src = src.replace(/\d(\.(gif|jpg))/, i + '$1');
   this.images[i] = img;
   
   var button = new Button(this, imgs[i].getElementsByTagName('a')[0]);
   this.steps[i] = button;
  }
  
  button._link.onclick();
  
  var button = new Button(this, imgs[i].getElementsByTagName('a')[0], -1);
  this.steps[i] = button;
*/
 }
};
var InfoItem = function(project, element)
{
 this._project = project;
 this._element = element;
 this._headline = this._element.getElementsByTagName('h2')[0];
 this._headline._obj = this;
 
 this._headline.style.cursor = 'hand';
 if (!this._headline.style.cursor)
 {
  this._headline.style.cursor = 'pointer';
 }
 
 this._headline.onmouseover = this._hilite;
 this._headline.onmouseout = this._clear;
 this._headline.onclick = this._activate;
};
InfoItem.prototype._hilite = function()
{
 this.className = 'over';
};
InfoItem.prototype._clear = function()
{
 this.className = '';
};
InfoItem.prototype._activate = function()
{
 var activeItem = this._obj._project.activeItem;
 
 if (activeItem)
 {
  activeItem._deactivate();
 }
 
 this._obj._project.activeItem = this._obj;
 this._obj._element.className = 'active';
 
 this.onclick = null;
};
InfoItem.prototype._deactivate = function()
{
 this._project.activeItem = null;
 this._element.className = '';
 this._headline.onclick = this._activate;
};
var Button = function(project, link, step)
{
 this._project = project;
 this._link = link;
 this._link._obj = this;
 this._step = step || 0;
 this._id = this._step || parseInt(this._link.childNodes[0].nodeValue);
 
 this._link.onclick = (this._step) ? this._stepBy : this._stepTo;
};
Button.prototype._stepTo = function()
{
 var obj = this._obj;
 var project = obj._project;
 
 if (project.activeStep)
 {
  project.activeStep._link.className = '';
  project.activeStep = null;
 }
 
 project.image.src = project.images[obj._id].src;
 project.activeStep = obj;
 
 obj._link.className = 'active';
};
Button.prototype._stepBy = function()
{
 var obj = this._obj;
 var project = obj._project;
 var step = project.activeStep._id + obj._step;
 
 if (!step)
 {
  step = project.lastStep - 1;
 }
 else if (project.lastStep <= step)
 {
  step = 1;
 }
 
 project.steps[step]._link.onclick();
};
Button.prototype._setClassName = function(className)
{
 this.className = (this.className.length) ? className : this.className + ' ' + className;
};
Button.prototype._unsetClassName = function(className)
{
 var idx = this.className.indexOf(' ' + className);
 this.className = this.className.substring(0, idx);
};
