var i_starting_news_position;//this value will be passed into initAll() to set the initial position of the scrolling layer
//see glimmer_read.js for all comments on versions, licenses, etc.
loaded = false; //this variable is set when the script is sourced, and
				//then set to true when initAll is finished (after the body loads)
layer_refer = "";
browser_version = "";
layer_name = new Array();
layer_obj = new Array();
end = "";
pause = "pause";
jump = "jump";


current_draggable = "";

modules_names = new Array();
modules_values = new Array();

layers = new Array();
addMod("nothing",layer_report);

//these first functions are executive, they do control operations
//across the layer specific functions

//returns browser version (not type)
function checkVer() {
browser = navigator.appName;
    browser_version = parseInt(navigator.appVersion);
    return browser_version;
}

//do nothing - sometimes useful
function voidOut() {
	}

//scan through all tags for ids and fill out arrays
//for layer names and object names
function readAll() {
  if (document.getElementById) {
		j = 0;
		d = document.getElementsByTagName("div");
		for ( zz = 0; zz < d.length; zz++ )
		{    
		if (d[zz].id != "") {
			layer_name[j] = "layer_"+d[zz].id;
			layer_obj[j] = d[zz].id;
			j = j+1;
			}
		}
	}
	if (document.all) {
		j = 0;
		for ( zz = 0; zz < document.all.tags('DIV').length; zz++ )
		{    
		if (document.all.tags('DIV')[zz].id != "") {
			layer_name[j] = "layer_"+document.all.tags('DIV')[zz].id;
			layer_obj[j] = document.all.tags('DIV')[zz].id;
			j = j+1;
			}
		}
	}
	if (document.layers) {
		j = 0;
		for ( zz = 0; zz < document.layers.length; zz++ )
		{    
		if (document.layers[zz].name != "") {
			layer_name[j] = "layer_"+document.layers[zz].name;
			layer_obj[j] = document.layers[zz].name;
			j = j+1;
			}
		}
	}
}

//initialize all layer objects based on tags with ids.
function initAll(i_position) {
	var q;	i_starting_news_position = i_position;
	readAll();
	for ( q = 0; q < layer_obj.length; q++ ){
		eval(layer_name[q] +"= new layer('"+layer_obj[q]+"'\)");
        layers[q] = eval(layer_name[q]);
		}
	loaded = true;
	}	

//generate Arrays of new functions based on mods
function addMod(name,value) {
	var l = modules_names.length;
	modules_names[l]=name;
	modules_values[l]=value;
	}
	
//add the functions from the mods to the layer
function addNew(i) {
	var qq;
	for (qq = 0; qq < modules_names.length; qq++) {
		eval('i.'+modules_names[qq]+' = '+modules_values[qq]);
		}
	}
	
	
	
//runMe - passes in an Array, splits it into codette, evals it and then passes the rest on
function runMe(codette){
if(codette && codette != "undefined" && codette != "end"){
//	alert('1:'+codette);
			codette = codette.split("|")
			direction = codette[0];
           // if (direction == "family") {direction = this);
			distance = codette[1];
			speed = codette[2];
			if (direction == "jump") {
				setTimeout(distance,speed);				
				}
			if (direction == "pause") {
				codette_pause = codette.reverse();
				codette_pause.length = codette_pause.length - 3;
				codette_pause = codette_pause.reverse();
				codette_pause = codette_pause.join("|");
				setcodette = 'runMe("'+codette_pause+'")';
				setTimeout(setcodette,speed);
	//			alert(setcodette);
				}
			if (direction && direction != "jump" && direction != "pause") {
				codette.reverse();
				codette.length = codette.length - 3;
				codette_jump = codette.reverse();
				codette_jump = codette_jump.join('|');
		//		alert(codette_jump);
				setcodette = direction+'('+distance+','+speed+',"'+codette_jump+'")';
				setTimeout(setcodette,speed);
				}
			}
		}
		
function layer(name,father) {
	this.name = name;
    if(father){this.father = father};
	if(!father){this.layer = name_layer(name);}
    else{this.layer = layer_nest(name,father);}
	this.obj_name = 'layer_' + name;
    if(document.all){document.all[this.name].jsobj = this;}else{this.layer.jsobj = this;}
    if(document.getElementById){document.getElementById(this.name).jsobj = this;}
    if(document.layers){this.layer.document.jsobj = this};
	this.refresh = layer_refresh;
	this.refresh();
	this.speed = 2;
	this.extend = layer_extend;
    this.nest = layer_nest;
	this.runMe = runMe;
	this.report = layer_report;
	addNew(this);
	}  
    
function layer_refresh() {
	if(document.all) {
	this.top = parseInt(this.layer.pixelTop);
	this.left = parseInt(this.layer.pixelLeft);
	this.height = document.all[this.name].offsetHeight;
	this.width = document.all[this.name].offsetWidth;
	myclip =  this.layer.clip;
	clip = getClipping(myclip);
	this.clipTop = clip[0];
	this.clipRight = clip[1];
	this.clipBottom = clip[2];
	this.clipLeft = clip[3];
	this.zIndex = this.layer.zIndex;
	this.visibility = this.layer.visibility;
    this.bgColor = this.layer.backgroundColor;
	}
	else if (document.layers) {
	this.top = this.layer.top;
	this.left = this.layer.left;
	this.height = this.layer.clip.height;
	this.width = this.layer.clip.width;
	this.clipTop = this.layer.clip.top;
	this.clipLeft = this.layer.clip.left;
	this.clipBottom = this.layer.clip.bottom;
	this.clipRight = this.layer.clip.right;
	this.zIndex = this.layer.zIndex;
	this.visibility = this.layer.visibility;
    this.bgColor = this.layer.bgColor;
	}
    else if (document.getElementById) {
	this.top = parseInt(this.layer.top);
	this.left = parseInt(this.layer.left);
	this.height = this.layer.height;
	this.width = this.layer.width;
	myclip = this.layer.clip;
	clip = getClipping(myclip);
	this.clipTop = parseInt(clip[0]);
	this.clipRight = parseInt(clip[1]);
	this.clipBottom = parseInt(clip[2]);
	this.clipLeft = parseInt(clip[3]);
	this.zIndex = this.layer.zIndex;
	this.visibility = this.layer.visibility;
    this.bgColor = this.layer.bgColor;
	}
	else {
	this.top = 0;
	this.left = 0;
	this.height = 0;
	this.width = 0;
	this.clipTop = 0;
	this.clipRight = 0;
	this.clipLeft = 0;
	this.zIndex = 0;
	this.visibility = null;
	} 
}

function layer_extend(layer_element) {
//alert(layer_element);
    if (document.getElementById) {
		layer_element_place = 'document.'+layer_element;
		}
	else if (document.all) {
		layer_element_place = 'document.all["'+layer_element+'"]';
		}
	else if (document.layers) {
		layer_element_place = 'document.layers["'+this.name+'"].document.'+layer_element;
		}
	else {layer_element_place = layer_element;}
	eval(this.obj_name +'.'+layer_element +'='+ layer_element_place);
	//alert(this.obj_name +'.'+layer_element +'='+ layer_element_place);
	}

    
 function layer_nest(layer_element,father) {
     if (document.getElementById) {
    	return(eval('document.getElementById("'+layer_element+'").style'));
	    }
    else if (document.layers) {
	    return(father.layer.document.layers[layer_element]);
 	    }
    else if (document.all) {
	    return(eval('document.all["' + layer_element + '"].style'));
	}
  else{return("empty");}
}
    
function name_layer(name) {
  if (document.getElementById) {
  	return(eval('document.getElementById("'+name+'").style'));
	}
  else if (document.layers) {
	return(eval('document.layers["'+name+'"]'));
 	}
  else if (document.all) {
	return(eval('document.all["' + name + '"].style'));
	}
  else{return("empty");}
}

	
function screenReload() {
var agt=navigator.userAgent.toLowerCase(); 
var is_major = parseInt(navigator.appVersion); 
var is_minor = parseFloat(navigator.appVersion); 
var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) 
                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) 
                && (agt.indexOf('webtv')==-1)); 
var is_nav4 = (is_nav && (is_major == 4));  
if(is_nav4 && (is_minor > 4.1)) {
if(document.layers){
	 if (document.body) {
           eval("browserWidth = " + document.body.clientWidth);
           eval("browserHeight = " + document.body.clientHeight);     
		   }
    else {
           eval("browserWidth = " + innerWidth);
           eval("browserHeight = " + innerHeight);
           }
//	alert(browserWidth);
	if(browserWidth > 597) {
		this.location.reload();
 		}
	}
}
}
	
window.onresize = screenReload;
	
//support function - not really for external use.  returns the IE css clip values.
//someone ask MS why they combined four variables into one, please?
//modified from cbdhtml.js
function getClipping(ieclipstr) {
  ieclip = new Array();
  i = ieclipstr.indexOf("(");
  ieclip[0] = parseInt(ieclipstr.substring(i + 1, ieclipstr.length), 10);
  i = ieclipstr.indexOf(" ", i + 1);
  ieclip[1] = parseInt(ieclipstr.substring(i + 1, ieclipstr.length), 10);
  i = ieclipstr.indexOf(" ", i + 1);
  ieclip[2] = parseInt(ieclipstr.substring(i + 1, ieclipstr.length), 10);
  i = ieclipstr.indexOf(" ", i + 1);
  ieclip[3] = parseInt(ieclipstr.substring(i + 1, ieclipstr.length), 10);
  return(ieclip);
}

//support function for debugging purposes.  will send an alert of current layer state
function layer_report() {
	alert("-REPORT-\nname:"+this.name+"\nobject name:"+this.obj_name+"\nlayer name:"+this.layer+"\ntop:"+this.top+"\nleft:"+this.left);
	alert("height:"+this.height+"\nwidth:"+this.width+"\nvisibility:"+this.visibility+"\nzindex:"+this.zIndex);
	}

	



//end glimmer

//the above is not the sole property of anyone.

