var subheadheight;

function getsubheadheight() {
subheadheight=document.getElementById("subhead").offsetHeight;
}

function $() {
        var elements = new Array();
        for (var i = 0; i < arguments.length; i++) {
                var element = arguments[i];
                if (typeof element == 'string')
                        element = document.getElementById(element);
                if (arguments.length == 1)
                        return element;
                elements.push(element);
        }
        return elements;
}

function findPos(obj) {			/* finds the x,y location of obj */
var curleft = curtop = 0;
  if (obj.offsetParent) {
      do {
         curleft += obj.offsetLeft;
         curtop += obj.offsetTop;
      } while (obj = obj.offsetParent);
return [curleft,curtop];
  }
}

function makeId() {			/* creates a unique number string */
	return parseInt(new Date().getTime().toString().substring(0, 10))
}

function addFrame(thediv,loc) {		/* clones both the dummy div and the inset and inserts them into the dom at the location of the link */
var myid = "id_"+makeId();		/* to use, make inset as div with class = "inset" and a unique id (e.g. "myinset", */
var container = $('insetframe').cloneNode(true);	/* then a link like this: onclick="addFrame('myinset',this);return false" */
container.setAttribute('id',myid);			/* might need to pass an inset size at some point, we'll see. */
document.body.appendChild(container);
var newDiv = $(thediv).cloneNode(true);
var theloc = findPos(loc);

container.appendChild(newDiv);

container.style.left = theloc[0]+"px";
container.style.top = theloc[1]-12+"px";
container.style.display = "block";
newDiv.style.display = "block";
container.style.width = newDiv.offsetWidth+"px";
container.style.height = newDiv.offsetHeight+"px";

}

function fadeInset(obj) {			/* removes the cloned inset from the dom */
	document.body.removeChild($(obj.id));
}



function showLogin(e) {
var login = document.getElementById('login');
if (e) {
   login.style.opacity = "0";
   login.style.display = "block";
   doFade(login,0,100,6,1,1);
   } else {
   doFade(login,100,0,6,1,1);
   login.style.display = "none";
   }
}


function heightChange(targeth) {
getsubheadheight();
var thediv = document.getElementById("subhead");
var themenu = document.getElementById("leftmenu");
var content = document.getElementById("content_p");
//alert(subheadheight);
if (targeth=='top') {
	targeth = "423"
	} else if (targeth=='middle') {
		targeth = "353"
		} else {
			targeth = "62"
	}
if (subheadheight!=targeth) {
doFade(themenu,100,0,20,4,0.5);
doFade(content,100,0,20,4,0.5);
doHeightChangeMem(thediv,subheadheight,targeth,10,10,2);
	} else {
doFade(themenu,100,0,20,4,0.5);
doFade(content,100,0,20,4,0.5);
	}
}


function doFade(elem,startTrans,endTrans,steps,intervals,powr) {
if(elem) {
   if (elem.fadeTransInt)
	window.clearInterval(elem.fadeTransInt);
   var actStep = 0;
   elem.fadeTransInt = window.setInterval(
	function() {
	  elem.currentTrans = easeInOut(startTrans,endTrans,steps,actStep,powr);
	  elem.style.opacity = elem.currentTrans * .01;
	  elem.style.filter  = "alpha(opacity=" + elem.currentTrans + ")";
 	  actStep++;
	  if (actStep > steps) window.clearInterval(elem.fadeTransInt);
	}
	,intervals)
    }
}


function doHeightChangeMem(elem,startHeight,endHeight,steps,intervals,powr) { 
//Height changer with Memory by www.hesido.com
    if (elem.heightChangeMemInt)
	window.clearInterval(elem.heightChangeMemInt);
    var actStep = 0;
    elem.heightChangeMemInt = window.setInterval(
	function() { 
	  elem.currentHeight = easeInOut(startHeight,endHeight,steps,actStep,powr);
	  elem.style.height = elem.currentHeight + "px"; 
	  actStep++;
	  if (actStep > steps) window.clearInterval(elem.heightChangeMemInt);
	} 
	,intervals)
}

function doWidthChangeMem(elem,startWidth,endWidth,steps,intervals,powr) {
//Width changer with Memory by www.hesido.com
    if (elem.widthChangeMemInt)
        window.clearInterval(elem.widthChangeMemInt);
    var actStep = 0;
    elem.widthChangeMemInt = window.setInterval(
        function() {
          elem.currentWidth = easeInOut(startWidth,endWidth,steps,actStep,powr);
          elem.style.width = elem.currentWidth + "px";
          actStep++;
          if (actStep > steps) window.clearInterval(elem.widthChangeMemInt);
        }
        ,intervals)
}

function easeInOut(minValue,maxValue,totalSteps,actualStep,powr) { 
//Generic Animation Step Value Generator By www.hesido.com 
    var delta = maxValue - minValue; 
    var stepp = minValue+(Math.pow(((1 / totalSteps) * actualStep), powr) * delta); 
    return Math.ceil(stepp) 
    }



