var divall, divcont, divmenu, divmenu2, divscroll;
var IE=(navigator.appName.indexOf("Microsoft")!=-1);
//var OP=(navigator.userAgent.indexOf("Opera")==-1);
var csize=771;
var msizen=215;
var msize=215;
var msizes=98;
var minHeight=450;
if (IE) csize=770;
var iscroll,bscroll=false;
var lastset=false;
var LH;
function resize()
{

if (window.innerWidth && window.innerWidth!=0) {
   smallMenu(window.innerHeight<minHeight);
   var w = Math.min(window.innerWidth, Math.floor((window.innerWidth + 773)/2));
}
else {
  smallMenu(document.body.clientHeight<minHeight);
  var w = Math.min(document.body.clientWidth, Math.floor((document.body.clientWidth + 773)/2));
}
  divall.style.width=w+"px";
  LH.setWidth(w);
  divcont.style.width=Math.min(w-2,csize)+"px";
  divmenu2.style.width=Math.min(w,771)+"px";
  if (!IE) {/*IE doesn't like that*/
     nudge(divmenu2);     /*let mozilla recheck if scrollbars are needed*/
  }
  var s=getScrollHeight(w,lastset);
  divmenu2.style.height=(msize+s)+"px";
  divmenu.style.height=(msize+s)+"px";
  if (msize-divmenu2.clientHeight!=0) {
	divmenu2.style.height=(msize+s+2)+"px";
  	divmenu.style.height=(msize+s+2)+"px";

  }
  return true;
}
function init()
{

  divall = document.getElementById("all");
  divcont = document.getElementById("content");
  divscroll = document.getElementById("scroll");
  divmenu2 = document.getElementById("menu2");
  divmenu = document.getElementById("menu");
  divall.style.left="auto";
  divall.style.right="0px";
  LH=new linkHolder();
  resize();

  window.onresize = resize;
  return;
}
function smallMenu(small) {
	if (lastset==small) return;
         lastset=small;
	if(small) {
         	divmenu.className="smallmenu";
                 divall.className="bigscroll";
                 divmenu2.style.height=msizes+"px";
                 msize=msizes;
                 LH.setClass("bigscroll");
         }
         else {
         	divmenu.className="menu";
                 divall.className="normal";
                 divmenu2.style.height=msizen+"px";
                 msize=msizen;
                 LH.setClass("normal");

         }
         return;
}

function getScrollHeight(width,lastset) {
	if (!bscroll) {
	        iscroll=msize-divmenu2.clientHeight;
                 if (iscroll!=0) bscroll=true;
                 return iscroll;
         }
         else {
                if(width<771) return iscroll;
                else return 0;
         }
}
function nudge(which) {/*hey gecko, have a closer look here!*/
         var p=which.parentNode;
         p.removeChild(which);
         p.appendChild(which);
         return;

}
function linkHolder() {
	var all=document.getElementsByTagName("a");
	this.links=new Array();
         if (!this.links.push) this.links.push=function(ele){this[this.length]=ele; return;}
         this.curWidth=0;//parseInt(document.getElementById("all").style.width)
         this.curClass=document.getElementById("all").className;
         var domGet=/http:\/\/[^\/]*/gi;
	var dom=domGet.exec(document.location.href);
         for (var i=0; i<all.length; i++) {
         	if(all[i].href && all[i].href.indexOf(dom[0])==0) {
         		this.links.push(new LinkObj(all[i],this.curWidth,this.curClass));
                         //break;
                 }
         }
	this.setWidth=function(width) {
                 if (width==this.curWidth) return;
                 this.curWidth=width;
                 for (var i=0; i<this.links.length; i++) {
			this.links[i].setWidth(width);
         	}
		return;
         }
         this.setClass=function(cln) {
                 if (cln==this.curClass) return;
                 this.curClass=cln;
                 for (var i=0; i<this.links.length; i++) {
			this.links[i].setClass(cln);
         	}
		return;
         }
	return;
}
function internal(ref) {
	return (ref.indexOf("://")!=-1 && ref.indexOf("mailto:")!=-1);
}
function LinkObj(ltag,width,cln) {
	this.obj=ltag;
	this.prestring;
         this.poststring;
         this.prefix;

	this.width=width;
         this.cln=cln;
         //var regAlt=/width=(\d*)&cl=(s|n)/i;
         //var isAlt=regAlt.test(ltag.href);
	var regSplit=/([^#]*)(.*)/i;
	var ar=regSplit.exec(ltag.href);
/*         for(var i=0; i<ar.length; i++) {
         	alert(i+" "+ar[i]);
         }
*/
  	this.prestring=ar[1];
         this.poststring=ar[2];
         if (this.prestring.indexOf("?")!=-1) this.prefix="&";
         else this.prefix="?";
         this.setWidth=function(width) {
         	this.width=width;
                 this.setLink();
         	return;
         }
         this.setClass=function(cln) {
         	this.cln=cln;
                 this.setLink();
         	return;
         }
         this.setLink=function() {
         	this.obj.href=this.prestring+this.prefix+"width="+this.width+"&menu="+this.cln+this.poststring;
		//alert(this.obj.href);
                 return;
         }

}