// greengecko design commonly used javascript functions
// mostly written by Jason Jaeger those functions or parts that are not, are credited.
// updated August 5th 2006


if(!opacityTimeOuts){ alert('there is no opacity timeouts!');}// var opacityTimeOuts = new Array();}
if(!fadeInIncrement){ alert('there is no fade in increment!');}// var fadeInIncrement = 1; }
if(!fadeInSpeed){ alert('there is no fadeinspeed!');}//var fadeInSpeed = Math.round(millisec / 100);}
function fadeIn(id, opacStart, opacEnd, millisec) {//######################################################################
	// I did not write this function, only modified + renamed it, the orginal can be found at:
	// http://brainerror.net/scripts_js_blendtrans.php
  	opacEnd = subMenuOptions[0];
  if(subMenuOptions[7] == '1'){
	  var timer = 0;
		var obj = getObject(id);
		//---------------------------------
		if(subMenuOptions[8] != '1'){showShadow(id);}//end if
		//---------------------------------
		if(opacityTimeOuts[id]){ clearTimeout(opacityTimeOuts[id])	}//end if
			if(obj.style.visibility == 'hidden'  ||!obj.style.visibility ){
				changeOpac(0, id);
				clearTimeout(opacityTimeOuts[id]);
				for(i = opacStart; i <= opacEnd; i= i+fadeInIncrement){
					obj.style.visibility = 'visible';
					opacityTimeOuts[id] = setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * fadeInSpeed));
					if(i >= opacEnd){
						visibility = setTimeout("changeOpac(" + opacEnd + ",'" + id + "')",(timer * fadeInSpeed));
					}//end if
					timer++;
				}//end for
			}//end if 
  }else{
	//---------------------------------
	if(subMenuOptions[8] != '1'){showShadow(id);}//end if
	//---------------------------------
	showMe(id);
  }//end if else
}//end function

if(!opacityTimeOuts){ alert('there is no opacity timeouts!');}// var opacityTimeOuts = new Array();}
if(!fadeOutIncrement){ alert('there is no fadeout increments!');}//var fadeOutIncrement = 1; }
if(!fadeOutSpeed){ alert('there is no fadeout speed!');} //var fadeOutSpeed = Math.round(millisec / 100);}
function fadeOut(id, opacEnd, millisec) {//######################################################################
	// I did not write this function, only modified + renamed it, the orginal can be found at:
	// http://brainerror.net/scripts_js_blendtrans.php
    //var speed = Math.round(millisec / 100);
	if(subMenuOptions[7] == '1'){
		var timer = 0;
		var obj = getObject(id);
		//---------------------------------
		if(subMenuOptions[8] != '1'){hideShadow(id);}//end if
		//---------------------------------
		if(opacityTimeOuts[id]){ clearTimeout(opacityTimeOuts[id])	}//end if
			if(obj.style.visibility == 'visible' ){
				clearTimeout(opacityTimeOuts[id]);
				opacStart = obj.style.opacity*100;//<---removes fadeOut flicker
				for(i = opacStart; i >= opacEnd; i= i-fadeOutIncrement) {
					opacityTimeOuts[id] = setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * fadeOutSpeed));
					timer++;
					if(i <=opacEnd){
						invisiblity = setTimeout("makeMeInvisible('"+id+"')", (timer * fadeOutSpeed));
					}//end if
				}//end for
		}//end if 
	}else{
		//---------------------------------
		if(subMenuOptions[8] != '1'){hideShadow(id);}//end if
		//---------------------------------
		hideMe(id);
  }//end if else
}//end function

function changeOpac(opacity, id) {//##########################################################
	// I did not write this function it can be found at:
	// http://brainerror.net/scripts_js_blendtrans.php
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}//end function

function makeMeInvisible(id){//###############################################################
	var obj = getObject(id);
	obj.style.visibility = 'hidden';
}//end function

function getObject(id,silent){//###############################################################
	if (document.all) {	obj = document.all[id];	}
		else if (document.getElementById && !document.all) {	obj = document.getElementById(id);	} 
	if(silent != "silent"){
		if (!obj) {	alert(id+" is an unrecognized ID");
					return false;	}
	}//end silent if
	return obj;
}//end function

function idOrObj(thing){//#####################################################################
	if(getObject(thing,'silent')){
		var whatItIs = 'id';
	}else if(thing.attributes.length >0){
	   var whatItIs = 'object';
	} else{ return false;	}//end if elseif else statement
	return whatItIs;
}//end function

function getThingObj(thing){//##################################################################
	if (idOrObj(thing) == 'id'){
		var obj = getObject(thing);
		return obj;
	} else if (idOrObj(thing) == 'object'){
		var obj = thing;
		return obj;
	} else {
		alert('Sorry, but '+thing+' is neither an id nor an object.');
		return false;
	}//end if else if
}//end function

function getThingId(thing){//##################################################################
	if (idOrObj(thing) == 'id'){
		var id = thing;
		return id;
	} else if (idOrObj(thing) == 'object'){
		if(thing.id){
			var id = thing.id;
			return id;
		}else{ 
			alert('Sorry, but while '+thing+' is indeed an oject, it currently has no id');
			return false;
		}//end if else
	} else {
		alert('Sorry, but '+thing+' is neither an id nor an object.');
		return false;
	}//end if else if
}//end function

function findObjHeight(thing){//###############################################################
	if(thing.offsetHeight){
		thing_height = thing.offsetHeight;
	}
	else if(thing.style.pixelHeight){
		thing_height = thing.pixelHeight;
	} 
	return thing_height;
}//end function
	
function findObjWidth(thing){//################################################################
	if(thing.offsetWidth){
		thing_width = thing.offsetWidth;
	}
	else if(thing.style.pixelWidth){
		thing_width = thing.pixelWidth;
	} 
	return thing_width;
}//end function
	
function findPosY(obj)  {//####################################################################
	// by Peter-Paul Koch & Alex Tingle
	// http://blog.firetree.net/2005/07/04/javascript-find-position/
	// http://www.quirksmode.org/js/findpos.html
	var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }//end function
  
function findPosX(obj){//######################################################################
	// by Peter-Paul Koch & Alex Tingle
	// http://blog.firetree.net/2005/07/04/javascript-find-position/
	// http://www.quirksmode.org/js/findpos.html
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }//end function

//###V--[ Browser Window Size and Scroll Position functions ]##################################
	// copyright Stephen Chapman, 3rd Jan 2005, 8th Dec 2005
	// these functions can be found at http://javascript.about.com/library/blscreen2.htm
function pageWidth() {return window.innerWidth != null? window.innerWidth: document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth:document.body != null? document.body.clientWidth:null;}
function pageHeight() {return window.innerHeight != null? window.innerHeight: document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight:document.body != null? document.body.clientHeight:null;}
function posLeft() {return typeof window.pageXOffset != 'undefined' ? window.pageXOffset:document.documentElement && document.documentElement.scrollLeft? document.documentElement.scrollLeft:document.body.scrollLeft? document.body.scrollLeft:0;}
function posTop() {return typeof window.pageYOffset != 'undefined' ? window.pageYOffset:document.documentElement && document.documentElement.scrollTop? document.documentElement.scrollTop: document.body.scrollTop?document.body.scrollTop:0;}
function posRight() {return posLeft()+pageWidth();}
function posBottom() {return posTop()+pageHeight();}

function getWinWidth() {//#####################################################################
	// this function is a slightly modified version of Mark Wilton-Jones's alertSize() function
	// the original can be found at http://www.howtocreate.co.uk/tutorials/javascript/browserwindow
  var myWidth = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
  } else if( document.documentElement && document.documentElement.clientWidth ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  } else if( document.body && document.body.clientWidth ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
  return myWidth;
}

function getWinHeight() {//#####################################################################
	// this function is a slightly modified version of Mark Wilton-Jones's alertSize() function
	// the original can be found at http://www.howtocreate.co.uk/tutorials/javascript/browserwindow
  var myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement && document.documentElement.clientHeight ) {
    //IE 6+ in 'standards compliant mode'
   myHeight = document.documentElement.clientHeight;
  } else if( document.body && document.body.clientHeight ) {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
 return myHeight;
}//end function

function getElementsByClassName(oElm, strTagName, strClassName){//###############################
	/* this awesome getElementsByClassName function was written by:
	Jonathan Snook, http://www.snook.ca/jonathan
	with add-ons by:
	Robert Nyman, http://www.robertnyman.com
	and be found at http://www.robertnyman.com/2005/11/07/the-ultimate-getelementsbyclassname/
	*/
    var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i<arrElements.length; i++){
        oElement = arrElements[i];      
        if(oRegExp.test(oElement.className)){arrReturnElements.push(oElement);}//end if 
    }//end for
    return (arrReturnElements)
}//end function

function setClass(thing, className){//###########################################################
	// I made this function from David F. Miller's code (at A List apart) which can be found at:
	// http://www.alistapart.com/articles/jslogging
	// if the node's class already exists then replace its value
	var obj = getThingObj(thing);
	if (obj.getAttributeNode("class")) {
	  for (var i = 0; i < obj.attributes.length; i++) {
		var attrName = obj.attributes[i].name.toUpperCase();
		if (attrName == 'CLASS') {
		  obj.attributes[i].value = className;
		}//end if
	  }//end for
	// otherwise create a new attribute
	} else {
	  obj.setAttribute("class", className);
	}//end if else
}//end function

function getStyle(el,styleProp){//###############################################################
	// this was function made by Peter-Paul Koch of quirksmode.org, and can be found at:
	// http://www.quirksmode.org/dom/getstyles.html
	var x = document.getElementById(el);
	if (x.currentStyle)
		var y = x.currentStyle[styleProp];
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	return y;
}//end function

function getBRW(thing){//########################################################################
	var id = getThingId(thing);
	if(getStyle(id,'borderRightWidth') ){
		var brw = getStyle(id,'borderRightWidth');
		var brw = brw.substring(0,brw.length-2);
	}else if(getStyle(id,'border-right-width')) {
		var brw = getStyle(id,'border-right-width');
		var brw = brw.substring(0,brw.length-2);
	} else{ var brw = 0; }//end if
	brw = (1*brw/1);//<-- this is so that it is recognized as a number not a string
	if(!brw){brw = 0;}//<-- if the size is not a number (like 'medium' or something) return 0 
	return brw;
}// end function

function getBLW(thing){//#########################################################################
	var id = getThingId(thing);
	if(getStyle(id,'borderLeftWidth')){
		var blw = getStyle(id,'borderLeftWidth');
		var blw = blw.substring(0,blw.length-2);
	}else if(getStyle(id,'border-left-width')) {
		var blw = getStyle(id,'border-left-width');
		var blw = blw.substring(0,blw.length-2);
	}else{ var blw = 0; }//end if
	blw = (1*blw/1);//<-- this is so that it is recognized as a number not a string
	if(!blw){blw = 0;}//<-- if the size is not a number (like 'medium' or something) return 0 
	return blw;
}//end function

function getBTW(thing){//########################################################################
	var id = getThingId(thing);
	if(getStyle(id,'borderTopWidth')){
		var btw = getStyle(id,'borderTopWidth');
		var btw = btw.substring(0,btw.length-2);
	}else if(getStyle(id,'border-top-width')) {
		var btw = getStyle(id,'border-top-width');
		var btw = btw.substring(0,btw.length-2);
	}else{ var btw = 0; }//end if
	btw = (1*btw/1);//<-- this is so that it is recognized as a number not a string
	if(!btw){btw = 0;}//<-- if the size is not a number (like 'medium' or something) return 0 
	return btw;
}//end function

function getBBW(thing){//#######################################################################
	var id = getThingId(thing);
	if(getStyle(id,'borderBottomWidth')){//<--ie
		var bbw = getStyle(id,'borderBottomWidth');
		var bbw = bbw.substring(0,bbw.length-2);
	}else if(getStyle(id,'border-bottom-width')) {
		var bbw = getStyle(id,'border-bottom-width');
		var bbw = bbw.substring(0,bbw.length-2);
	}else{ var bbw = 0; }//end if
	bbw = (1*bbw/1);//<-- this is so that it is recognized as a number not a string
	if(!bbw){bbw = 0;}//<-- if the size is not a number (like 'medium' or something) return 0 
	return bbw;
}//end function

function getBorderHeight(thing){ return getBTW(thing) + getBBW(thing); }//end function
function getBorderWidth(thing){	return getBLW(thing) + getBRW(thing); }//end function

function getPaddingTop(thing){//#######################################################################
	var id = getThingId(thing);
	if(getStyle(id,'PaddingTop')){
		var pt = getStyle(id,'PaddingTop');
		var pt = pt.substring(0,pt.length-2);
	}else if(getStyle(id,'padding-top')) {
		var pt = getStyle(id,'padding-top');
		var pt = pt.substring(0,pt.length-2);
	}else{var pt = 0; }//end if
	pt = (1*pt/1);//<-- this is so that it is recognized as a number not a string
	if(!pt){pt = 0;}//end if
	return pt;
}//end function

function getPaddingBottom(thing){//#######################################################################
	var id = getThingId(thing);
	if(getStyle(id,'PaddingBottom')){
		var pb = getStyle(id,'PaddingBottom');
		var pb = pb.substring(0,pb.length-2);
	}else if(getStyle(id,'padding-bottom')) {
		var pb = getStyle(id,'padding-bottom');
		var pb = pb.substring(0,pb.length-2);
	}else{ var pb=0; }//end if
	pb = (1*pb/1);//<-- this is so that it is recognized as a number not a string
	if(!pb){pb = 0;}//end if
	return pb;
}//end function

function getPaddingLeft(thing){//#######################################################################
	var id = getThingId(thing);
	if(getStyle(id,'PaddingLeft')){
		var pl = getStyle(id,'PaddingLeft');
		var pl = pl.substring(0,pl.length-2);
	}else if(getStyle(id,'padding-left')) {
		var pl = getStyle(id,'padding-left');
		var pl = pl.substring(0,pl.length-2);
	}else{var pt = 0; }//end if
	pl = (1*pl/1);//<-- this is so that it is recognized as a number not a string
	if(!pl){pl = 0;}//end if
	return pl;
}//end function

function getPaddingRight(thing){//#######################################################################
	var id = getThingId(thing);
	if(getStyle(id,'PaddingRight')){
		var pr = getStyle(id,'PaddingRight');
		var pr = pr.substring(0,pr.length-2);
	}else if(getStyle(id,'padding-right')) {
		var pr = getStyle(id,'padding-right');
		var pr = pr.substring(0,pr.length-2);
	}else{var pr = 0; }//end if
	pr = (1*pr/1);//<-- this is so that it is recognized as a number not a string
	if(!pr){pr = 0;}//end if
	return pr;
}//end function

function getPaddingHeight(thing){ return getPaddingTop(thing) + getPaddingBottom(thing); }//end function
function getPaddingWidth(thing){ return getPaddingLeft(thing) + getPaddingRight(thing); }//end function

function centerObj(id){//#######################################################################
	var obj = getObject(id);
	var objWidth = findObjWidth(obj);
	var objHeight = findObjHeight(obj);
	var winWidth = pageWidth();
	var winHeight = pageHeight();
	var scrollX = posLeft();
	var scrollY = posTop();
	var newX = ((winWidth/2)+scrollX)-(objWidth/2);
	var newY = ((winHeight/2)+scrollY)-(objHeight/2);
	//alert("WinWidth = "+winWidth+" | WinHeight = "+winHeight+" | objWidth = "+objWidth+" | objHeight = "+objHeight);
	obj.style.top = newY+'px';
	obj.style.left = newX+'px';
}//end function