var main = '';
var headerSize = 0; // pixels

function init(m,h) {
	main = m;
	headerSize = h;

	if(main == 'index') initCycle();

	window.onresize = handleResize;
	handleResize();
}

function handleResize() {
	contentDiv = document.getElementById('content_div');
	if(contentDiv) {
		if(typeof(window.innerHeight) == 'number')
			ih = window.innerHeight;
		else if (document.documentElement && document.documentElement.clientHeight)
			ih = document.documentElement.clientHeight;
		else
			ih = document.body.clientHeight;

		newHeight = contentDiv.scrollHeight;
		if(headerSize + contentDiv.scrollHeight > ih) {
			setHeight = ih - headerSize;
			if(setHeight >= 100) newHeight = setHeight;
		}
	
		contentDiv.style.height = newHeight + 'px';

		if(typeof(window.innerWidth) == 'number')
			iw = window.innerWidth;
		else if (document.documentElement && document.documentElement.clientWidth)
			iw = document.documentElement.clientWidth;
		else
			iw = document.body.clientWidth;

		// first off we need to decide if we have to display the side at all based on the current width.
		// a thousand is the width of the content div
		// adjust up the size of the content div by 2x to create a 'border effect'. i.e. x=15px
		cw  = 1000 + (2*5);

		divs = '';
		if(iw > cw) {
			// for starters, we are going to track the overall height.
			// for some odd reason, repeat-y didn't work with background-position so,
			// we have to manage the overall height as well
			// basically set the horizontal run height and the vertical run height, hh and vh.
			divHeight = newHeight;
			if(ih > divHeight) divHeight = ih - headerSize;

			vh = 100;
			hh = 0;
			if(divHeight < 100) vh = divHeight;
			if(divHeight > 100) hh = divHeight - 100;

			// next in the display dance we need to divide the remaining space equally between 
			// the left and right sides.  if iw is odd, floor down, plan on giving it to the right later
			availableWidth = Math.floor((iw - cw) / 2);
			
			// starting with the left slice, figure out the starting position and width
			remainder = availableWidth % 100;
			if(availableWidth > 100 && remainder > 0) {
				divs = divs + '<div style="position:absolute;                   left:   0px; height:' + vh + 'px; width: ' + remainder + 'px; background-image:url(/images/slant_left_horizontal.png); background-position:' + remainder + 'px 0px"><img src="/images/spacer.gif" /></div>';
			}

			// now the left horizontal run, see if we need it
			hw = 0; // horizontal width
			if(availableWidth >= 200) {
				// get the width of this div by removing a hundred from the available, 
				// then divide out the tenths and ones places
				hw = Math.floor((availableWidth - 100) / 100) * 100;
				divs = divs + '<div style="position:absolute;                   left:  ' + remainder + 'px; height:' + vh + 'px; width:' + hw + 'px; background-image:url(/images/slant_left_horizontal.png); background-repeat:repeat-x"><img src="/images/spacer.gif" /></div>';
			}

			// now see if there is enough room to display the shadow divs, _corner and _vertical
			vl = hw + remainder;  // vertical left
			vw = 100;
			vp = 0;
			if(availableWidth < 100) {
				vl = 0;  // vertical left
				vw = availableWidth;
				vp = availableWidth;
			}

			divs = divs + '<div style="position:absolute;                   left:' + vl + 'px; height:' + vh + 'px; width:' + vw + 'px; background-image:url(/images/slant_left_corner.png); background-position:' + vp + 'px 0px"><img src="/images/spacer.gif" /></div>';

			// as I alluded to before, the repeat-y doesn't work with background position.... so,
			// we need to floor and mod the hh resuly and chunk it up...
			if(hh > 0) {
				ndivs = Math.floor(hh / 100);
				for(i=1; i<=ndivs; i++) divs = divs + '<div style="position:absolute; margin-top:' + (i*100) + 'px; left:' + vl + 'px; height:100px; width:' + vw + 'px; background-image:url(/images/slant_left_vertical.png); background-position:' + vp + 'px 0px"><img src="/images/spacer.gif" /></div>';

				hremainder = hh % 100;
				divs = divs + '<div style="position:absolute; margin-top:' + (i*100) + 'px; left:' + vl + 'px; height:' + hremainder + 'px; width:' + vw + 'px; background-image:url(/images/slant_left_vertical.png); background-position:' + vp + 'px 0px"><img src="/images/spacer.gif" /></div>';
			}

			// now, working on the right:
			vl = iw - availableWidth;
			vw = 100;
			if(availableWidth < 100) {
				vw = availableWidth;
			}

			divs = divs + '<div style="position:absolute;                   left:' + vl + 'px; height:' + vh + 'px; width:' + vw + 'px; background-image:url(/images/slant_right_corner.png);"><img src="/images/spacer.gif" /></div>';
			divs = divs + '<div style="position:absolute; margin-top:100px; left:' + vl + 'px; height:' + hh + 'px; width:' + vw + 'px; background-image:url(/images/slant_right_vertical.png); background-repeat:repeat-y"><img src="/images/spacer.gif" /></div>';

			if(availableWidth > 100) {
				hw = availableWidth - 100;
				divs = divs + '<div style="position:absolute;                   left:' + (vl+100) + 'px; height:' + vh + 'px; width:' + hw + 'px; background-image:url(/images/slant_right_horizontal.png); background-repeat:repeat-x"><img src="/images/spacer.gif" /></div>';
			}
		}

		document.getElementById('slants').innerHTML = divs;
	}
}

function nameplate_over(e) {
	e.style.cssText = 'border-right:1px solid #558241;cursor:pointer';
}

function nameplate_out(e) {
	e.style.cssText = 'border-right:1px solid #558241';
}

function button_over(e,s) {

	if(main !=  s) {
		e.style.cssText = 'background-color:white;color:green;cursor:pointer';
		//button = document.getElementById('button_'+s);
		//button.src = '/images/button_'+s+'_over_2.png';
	}
}

function button_out(e,s) {
	if(main !=  s) {
		e.style.cssText = '';
		//button = document.getElementById('button_'+s);
		//button.src = '/images/button_'+s+'_2.png';
	}
}


// Correctly handle PNG transparency in Win IE 5.5 or higher.
// http://homepage.ntlworld.com/bobosola. Updated 02-March-2004
function correctPNG() 
   {
   for(var i=0; i<document.images.length; i++)
      {
	  var img = document.images[i]
	  var imgName = img.src.toUpperCase()
	  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
	     {
		 var imgID = (img.id) ? "id='" + img.id + "' " : ""
		 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
		 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
		 var imgStyle = "display:inline-block;" + img.style.cssText 
		 if (img.align == "left") imgStyle = "float:left;" + imgStyle
		 if (img.align == "right") imgStyle = "float:right;" + imgStyle
		 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle		
		 var strNewHTML = "<span " + imgID + imgClass + imgTitle
		 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
	     + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		 + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
		 img.outerHTML = strNewHTML
		 i = i-1
	     }
      }
   }

<!--[if lte IE 6]>window.attachEvent("onload", correctPNG);<![endif]-->

function goToHere(e)	{
	document.location = e + ".php";
}

function hideEmail(name, domain, display) {
	displayed=(typeof(display)=="undefined") ? name+"@"+domain : display 
	document.write('<a href=mailto:' + name + '@' + domain + '>' + displayed + '</a>');
}

// index image cycling
var idx = 0;
var delay = 6000;
var remaining = 1500;
var specials = new Array();
var specialImgs = new Array();
var timeoutId = 0;

function initCycle() {
	divs = document.getElementsByTagName('div');

	j = 0;
	k = 0;

	for(i=0; i<divs.length; i++) {
		if(divs[i].id.indexOf('specials') >= 0) {
			specials[j++] = divs[i];
		}

		if(divs[i].id.indexOf('specialimgs') >= 0) {
			specialImgs[k++] = divs[i];
		}
	}

	idx = 0;

	timeoutId = window.setTimeout('switchSpecial()', delay);
}

function switchSpecial() {
	specials[idx].style.display="none";
	idx++;
	if(idx >= specials.length) idx = 0;
	specials[idx].style.display="block";

	timeoutId = window.setTimeout('switchSpecial()', delay);
}

function handleOut() {
//	specialImgs[idx].setAttribute ("class", "imgHoverOff");
//	specialImgs[idx].setAttribute ("className", "imgHoverOff");  // IE
	window.clearTimeout(timeoutId);
	timeoutId = window.setTimeout('switchSpecial()', remaining);
}

function handleOver() {
//	specialImgs[idx].setAttribute ("class", "imgHoverOn");
//	specialImgs[idx].setAttribute ("className", "imgHoverOn");  // IE
	window.clearTimeout(timeoutId);
}
