var tabFullSize=10;
var tabCloseSize=0;
var tabState=new Array();

var slideShow=new Array('photo1.jpg', 'photo2.jpg', 'photo3.jpg');
var slideShowIndex=0;
var slideShowFadeInc=5;
var slideShowFadeSpeed=40;
var slideShowStayOnPic=7000;

function tabOpen(tabNum) { tabState[tabNum]=1;}
function tabClose(tabNum) {tabState[tabNum]=0;}

function zenStart() {
	tabSizer();
	xAddEventListener(window, 'resize', zenResize, false);
	zenResize();
	slideShowIn();
}

function zenResize() {
	var slideImg=document.getElementById('slideshow');
	var sidemenu=document.getElementById('sidemenu');
	slideImg.className='';
	slideImg.style.top=docjslib_getRealTop(sidemenu);
	slideImg.style.left=docjslib_getRealLeft(sidemenu);
}

function slideShowOut() { 
	slideShowIndex++;
	if (slideShowIndex>=slideShow.length)
		slideShowIndex=0;
	document.getElementById('slideshow').src='images/'+slideShow[slideShowIndex];
	window.setTimeout("fadeIn('slideshow',0)", 200);
}

function slideShowIn() { 
	window.setTimeout("fadeOut('slideshow',100)", slideShowStayOnPic);
}

function tabSizer() {
	for (var t in tabState) {
		var targetWidth=tabFullSize;
		if (tabState[t]==0)
			targetWidth=tabCloseSize;
		
		var tabObj=document.getElementById('tabFill'+t);
		var currentWidth=parseInt(tabObj.style.width);
				
		if (currentWidth<targetWidth)
			currentWidth++;
		else if(currentWidth>targetWidth)
			currentWidth--;
		
		tabObj.style.width=currentWidth;
	}
	
	setTimeout('tabSizer()',30);
}

function js_debug_print(out_str) {
	if (!document.getElementById('debug_output_box')) {
		var new_box = document.createElement('textarea');
		new_box.id='debug_output_box';
		document.getElementsByTagName('body')[0].appendChild(new_box);
	}
	
	document.getElementById('debug_output_box').innerHTML += out_str + '\r\n';
}

function setOpacity(obj, opacity) {
  opacity = (opacity == 100)?99.999:opacity;
  
  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";
  
  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;
  
  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;
  
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}

function fadeIn(objId,opacity) {
  if (document.getElementById) {
    obj = document.getElementById(objId);
    if (opacity <= 100) {
      setOpacity(obj, opacity);
      opacity += slideShowFadeInc;
      window.setTimeout("fadeIn('"+objId+"',"+opacity+")", slideShowFadeSpeed);
    }
    else
	    slideShowIn();
  }
}

function fadeOut(objId,opacity) {
  if (document.getElementById) {
    obj = document.getElementById(objId);
    if (opacity >= 0) {
      setOpacity(obj, opacity);
      opacity -= slideShowFadeInc;
      window.setTimeout("fadeOut('"+objId+"',"+opacity+")", slideShowFadeSpeed);
    }
    else
	    slideShowOut();
  }
}


function docjslib_getRealLeft(imgElem) {
	xPos = eval(imgElem).offsetLeft;
	tempEl = eval(imgElem).offsetParent;
  	while (tempEl != null) {
  		xPos += tempEl.offsetLeft;
  		tempEl = tempEl.offsetParent;
  	}
	return xPos;
}

function docjslib_getRealTop(imgElem) {
	yPos = eval(imgElem).offsetTop;
	tempEl = eval(imgElem).offsetParent;
	while (tempEl != null) {
  		yPos += tempEl.offsetTop;
  		tempEl = tempEl.offsetParent;
  	}
	return yPos;
}

function centerPopNav(url,name,size_w,size_h) {
	var win_w=size_w;
	var win_h=size_h;
	
	if (win_w>=screen.width)
		win_w=screen.width/2;
	
	if (win_h>=screen.height)
		win_h=screen.height/2;
	
	var features='scrollbars=yes,resizable=yes,width='+win_w+',height='+win_h
	+',left='+((screen.width/2)-(win_w/2))+',top='+((screen.height/2)-(win_h/2));
	var oldPopStyle = false;
	
	if (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) < 4)
		oldPopStyle=true;
	window.name='mainWin';
	if (oldPopStyle)
		popBox = window.open(url,name,features); 
	else {
		popBox = window.open(url,name,features);
		popBox.focus();
	}
}

function zenShowMap() {
	centerPopNav('map.asp','zenmap',525,500);
}
