// shader.js

//////////////////////////////////

var shaderPtr = 0;

function shader_item() {
	this.div_name = "";
  this.type = "";
	this.mode = 0;
	this.caption = "";
  this.icon = "";
	}

//////////////////////////////////

var shader_orig_onload = window.onload;

window.onload = function() {
	var i, e;
  var hide_div = false;
	if (shader_orig_onload) shader_orig_onload();
	if (!shaderPtr) return;
	var y = 0;
	for (i=0 ; i<shaderPtr.num_divs ; i++) {
    e = document.getElementById(shaderPtr.divs[i].div_name);
		if (i==0) y = e.cbe.pageY();
		if (hide_div) {
      y -= e.cbe.height() - 10;
      }
    if (shaderPtr.divs[i].icon) {
      if (shaderPtr.divs[i].mode) eval ("document."+shaderPtr.divs[i].icon+".src = '"+shaderPtr.img_collapsed+"'");
      else eval ("document."+shaderPtr.divs[i].icon+".src = '"+shaderPtr.img_expanded+"'");
      }
    e.cbe.moveBy (0, y);
    if (!hide_div) e.cbe.show();
    hide_div = false;
		if (shaderPtr.divs[i].mode==true) hide_div = true;
    y += e.cbe.height();
		}
	}

//////////////////////////////////

function Shader_setIcon (img_expanded, img_collapsed) {
  this.img_expanded = img_expanded;
  this.img_collapsed = img_collapsed || img_expanded;
  }

//////////////////////////////////

function Shader_addShader (div_name, shade) {
	var i = this.num_divs;
	this.divs[i] = new shader_item();
	this.divs[i].type = "shader";
	this.divs[i].div_name = div_name;
	this.divs[i].caption = "";
	this.divs[i].mode = shade || false;
	this.num_divs++;
	return i;
	}

//////////////////////////////////

function Shader_addDiv (div_name) {
	var i = this.num_divs;
	this.divs[i] = new shader_item();
	this.divs[i].type = "div";
	this.divs[i].div_name = div_name;
	this.divs[i].caption = "";
	this.divs[i].mode = false;
	this.num_divs++;
	return i;
	}

//////////////////////////////////

function Shader_addIcon (id, div_name) {
	this.divs[id].icon = div_name;
	}

//////////////////////////////////

function Shader_toggle (id) {
	var e;
	var h;
	var mode = this.divs[id].mode;
	var s = this.divs[id+1].div_name;
	e = document.getElementById(s);
  var e2;
	if (!e) return;
	if (mode) {
    this.divs[id].mode = false;
    if (this.divs[id].icon) {
      eval ("document."+this.divs[id].icon+".src = '"+this.img_expanded+"'");
      }
    }
	else {
    e.cbe.hide();
		this.divs[id].mode = true;
    if (this.divs[id].icon) {
      eval ("document."+this.divs[id].icon+".src = '"+this.img_collapsed+"'");
      }
		}
	h = e.cbe.height() - 10;
	for (var i=id+1 ; i<this.num_divs ; i++) {
		e2 = document.getElementById(this.divs[i].div_name);
		if (mode) e2.cbe.moveBy (0, h);
		else e2.cbe.moveBy (0, -h);
		}
  if (mode) e.cbe.show();
	}

//////////////////////////////////

function Shader() {
	this.num_divs = 0;
	this.divs = new Array();
	this.isSpacerDrawn = false;
  this.img_expanded = "";
  this.img_collapsed = "";
	shaderPtr = this;
	//------------------------------
	this.setIcon = Shader_setIcon;
  this.addShader = Shader_addShader;
	this.addDiv = Shader_addDiv;
  this.addIcon = Shader_addIcon;
	this.toggle = Shader_toggle;
	}

//////////////////////////////////

