/*
CROSS-BROWSER DHTML POP-UP MENUS by Kevin Yank (kevin@sitepoint.com) Version 1.0 (26/02/2001)
Visit http://www.sitepoint.com/newsletter/ to subscribe to the SitePoint Tech Times for more free scripts, tips, and tutorials like this one!
TERMS OF USE: SitePoint hereby grants permission for anyone to make use of the scripts contained in this page, on the condition that this notice appears before the first relevant <script> in any page that makes use of this code, either in its original or modified form. That's not much to ask, is it?
*/

// THIS BEGINS DHTML DROP-DOWN MENU BUILDER
/* Menu Height = (menuItemHeight+1)*numMenuItems)+1 */
var menuItemWidth = 190; //180
var menuItemHeight = 17;
if (document.images) {

var otherButtons = new Array();
    otherButtons[0] = new Image();
    otherButtons[0].src = "/assets/tn_contact_off.gif";
	
var menuOutButtons = new Array();
    menuOutButtons[0] = new Image();
    menuOutButtons[0].src = "/assets/tn_services_off.gif";
	menuOutButtons[1] = new Image();
    menuOutButtons[1].src = "/assets/tn_resources_off.gif";
	menuOutButtons[2] = new Image();
    menuOutButtons[2].src = "/assets/tn_about_off.gif";

var menuOverButtons = new Array();
    menuOverButtons[0] = new Image();
    menuOverButtons[0].src = "/assets/tn_services_on.gif";
    menuOverButtons[1] = new Image();
    menuOverButtons[1].src = "/assets/tn_resources_on.gif";
	menuOverButtons[2] = new Image();
    menuOverButtons[2].src = "/assets/tn_about_on.gif";

var moreButtons = new Array();
	moreButtons[0] = new Image();
	moreButtons[0].src = "/assets/sn_partner_on.gif";
	moreButtons[1] = new Image();
	moreButtons[1].src = "/assets/sn_professional_on.gif";
	moreButtons[2] = new Image();
	moreButtons[2].src = "/assets/sn_you_on.gif";
}

var menuLengths = new Array(9,7,3);

var menuURLs = new Array(menuLengths.length);
for (i=0;i<menuLengths.length;i++) 
    menuURLs[i] = new Array(menuLengths[i]);

menuURLs[0][0] = "/services/assessment.php";
menuURLs[0][1] = "/services/professional_assessment.php";
menuURLs[0][2] = "/services/individual.php";
menuURLs[0][3] = "/services/group.php";
menuURLs[0][4] = "/services/couples.php";
menuURLs[0][5] = "/services/non_violent_offender.php";
menuURLs[0][6] = "/services/partners.php";
menuURLs[0][7] = "/services/iop.php";
menuURLs[0][8] = "/services/phoneweb.php";

menuURLs[1][0] = "/resources/selftests/";
menuURLs[1][1] = "/resources/articles/";
menuURLs[1][2] = "/resources/online.php";
menuURLs[1][3] = "/resources/12step.php";
menuURLs[1][4] = "/resources/nationalprograms.php";
//menuURLs[1][5] = "/resources/individual_treatment_resources.php";
menuURLs[1][5] = "/resources/bookstore.php";

menuURLs[2][0] = "/about/director.php";
menuURLs[2][1] = "/about/staff.php";
menuURLs[2][2] = "/about/professionalservices.php";


var menuTimers = new Array(menuLengths.length);

function getStyleObj(id) {
    if (document.getElementById || // DOM-compliant browsers (MSIE5, NSN6, O5)
        document.all) {            // or MSIE 4
        return getObj(id).style;
    } else return getObj(id); // NSN4
}

function getObj(id) {
    if (document.getElementById) { // DOM-compliant browsers (MSIE5, NSN6, O5)
        return document.getElementById(id);
    } else if (document.all) { // MSIE4
        return document.all[id];
    } else if (document.layers) { // NSN4
        return document.layers[id];
    } else { // Trap DHTML-impaired browsers 
        return false;
    }
}

function showMenu(index) {
    if (menuTimers[index-1]) clearTimeout(menuTimers[index-1]);
    for (i=1;i<=menuLengths.length;i++)
    if (i!=index) closeMenu(i);
	var menu = getStyleObj("menu"+index);
	if (menu) menu.visibility = "visible";
	if (document.images) document.images["menubutton"+index].src =
	menuOverButtons[index-1].src;
}

function hideMenu(index) {
    if (menuTimers[index-1]) clearTimeout(menuTimers[index-1]);
	menuTimers[index-1] = setTimeout("closeMenu('"+index+"');",500);
}


function closeMenu(index) {
    var menu = getStyleObj("menu"+index);
	if (menu) menu.visibility = "hidden";
	if (document.images) document.images["menubutton"+index].src =
	menuOutButtons[index-1].src;
}


function overMenuItem() {
	this.hilightitem.visibility='visible';
	showMenu(this.menuid);
}

function outMenuItem() {
	this.hilightitem.visibility='hidden';
	hideMenu(this.menuid);
}

function clickMenuItem() {
    if (this.url) { // There is a URL associated with this item
    window.location = this.url;
    }
}


function setupMenus() {
        for (menuid=1;menuid<=menuLengths.length;menuid++) { // For each menu

            for (i=1;i<=menuLengths[menuid-1];i++) { // For each menu item
				var item = getObj("menu"+menuid+"item"+i);
                var onitem = getObj("menu"+menuid+"item"+i+"on");
                var itemstyle = getStyleObj("menu"+menuid+"item"+i);
                var onitemstyle = getStyleObj("menu"+menuid+"item"+i+"on");

                itemstyle.top = (menuItemHeight + 1) * (i-1) + 1;
                onitemstyle.top = (menuItemHeight + 1) * (i-1) + 1;
                
                if (navigator.appName=="Microsoft Internet Explorer") {
                    itemstyle.cursor = "hand";
                    onitemstyle.cursor = "hand";
                }

                item.hilightitem = onitemstyle;
                onitem.hilightitem = onitemstyle;

                item.menuid = menuid;
                onitem.menuid = menuid;

                var url = menuURLs[menuid-1][i-1];
                item.url = url;
                onitem.url = url;

                item.onmouseover = overMenuItem;
                onitem.onmouseover = overMenuItem;
                item.onmouseout = outMenuItem;
                onitem.onmouseout = outMenuItem;
                item.onclick = clickMenuItem;
                onitem.onclick = clickMenuItem;
        }
    }
}





// Global resize
function reSize() {
	window.history.go(0);
}
window.onresize = reSize;


// Opera resize
var OPERA = (window.opera);
if (OPERA) {
	origWidth  = this.innerWidth;
	origHeight = this.innerHeight;
	resizeHandler();
	onload = loadHandler;
	}
function resizeHandler() {
	if (this.innerWidth != origWidth || this.innerHeight != origHeight) location.reload();
	if (OPERA) setTimeout('resizeHandler()',1000);
}


// CSS builder
function css(id,left,other) {
	if (id=="START") return '<STYLE TYPE="text/css">\n<!--\n'
	else if (id=="END") return '-->\n</STYLE>'
	var str = id+' {left:'+left+';';
	if (other!=null) str += other;
	str += '}\n';
	return str;
}

// CSS builder #2
function writeCSS(str) {
	str = css('START')+str+css('END');
	document.write(str);
}


// Get starting x-pos for 3 div's
function WinWidth() {
	winW = (window.innerWidth)? window.innerWidth : document.body.offsetWidth;
	if (winW == null || '') {winW = 738;}
	if (winW < 738) {winW = 738;}
	halfWin = Math.floor(winW/2);
	startLeft = halfWin-369;
}




//used by Flevo's SlideDiv
function MM_findObj(n, d) { // v4.01  
  var p,i,x;  if(!d) d=document;  
if((p=n.indexOf("?"))>0&&parent.frames.length) {  
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}  
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++)  
x=d.forms[i][n];  
  for(i=0;!x&&d.layers&&i<d.layers.length;i++)  
x=MM_findObj(n,d.layers[i].document);  
  if(!x && d.getElementById) x=d.getElementById(n); return x;  
}



//Move div's
function flevSlideDiv() { // v2.0, Marja Ribbers-de Vroed, FlevOOware

	var sD = arguments[0], iNX = parseInt(arguments[1]), iNY = parseInt(arguments[2]);
	var iS = parseInt(arguments[3]), iPx = parseInt(arguments[4]);

if (arguments[0] == 'over2') {
	var sD = 'Home2', iNX = 0, iNY = 131, iS = 10, iPx = 6;
} else if (arguments[0] == 'out2') {
	var sD = 'Home2', iNX = 0, iNY = 73, iS = 10, iPx = 6;
} else if (arguments[0] == 'over4') {
	var sD = 'Home4', iNX = 246, iNY = 131, iS = 10, iPx = 6;
} else if (arguments[0] == 'out4') {
	var sD = 'Home4', iNX = 246, iNY = 73, iS = 10, iPx = 6;
} else if (arguments[0] == 'over6') {
	var sD = 'Home6', iNX = 492, iNY = 131, iS = 10, iPx = 6;
} else if (arguments[0] == 'out6') {
	var sD = 'Home6', iNX = 492, iNY = 73, iS = 10, iPx = 6;
}




	var iR = 0;
	var	oD = eval("MM_findObj('" + sD + "')");
	var iT = 10, sS = ""; if (!document.layers) {oD = oD.style;} 
	if (oD.tT != null) {clearTimeout(oD.tT);}
	var iCX = parseInt(oD.left), iCY = parseInt(oD.top);

	var iX = iNX, iY = iNY;
	if ((iCX != iNX) || (iCY != iNY)) {
		if (iPx > 0) { iT = iS;
			var iPxX = iPx, iPxY = iPx, iMX = Math.abs(iCX - iNX), iMY = Math.abs(iCY - iNY);
			if (iMX < iMY) {iPxY = (iMX != 0) ? ((iMY/iMX)*iPx) : iPx;}
			else {iPxX = (iMY != 0) ? ((iMX/iMY)*iPx) : iPx;}
			if (iPxX >= iMX) {iPxX = Math.min(Math.ceil(iPxX), iPx);}
			if (iPxY >= iMY) {iPxY = Math.min(Math.ceil(iPxY), iPx);}
			if ((iCX < iNX) && (iCX + iPxX < iNX)) {iNX = iCX + iPxX;}
			if ((iCX > iNX) && (iCX - iPxX > iNX)) {iNX = iCX - iPxX;}
			if ((iCY < iNY) && (iCY + iPxY < iNY)) {iNY = iCY + iPxY;}
			if ((iCY > iNY) && (iCY - iPxY > iNY)) {iNY = iCY - iPxY;}
		} else {
			var iMX = ((iNX - iCX) / iS); 
			iMX = (iMX > 0) ? Math.ceil(iMX) : Math.floor(iMX);
			iNX = iCX + iMX; 
			var iMY = ((iNY - iCY) / iS); 
			iMY = (iMY > 0) ? Math.ceil(iMY) : Math.floor(iMY);
			iNY = iCY + iMY;
		}
		if ((parseInt(navigator.appVersion)>4 || navigator.userAgent.indexOf("MSIE")>-1) && (!window.opera)) {sS="px";}
		if (iMX != 0) {eval("oD.left = '" + iNX + sS + "'");}
		if (iMY != 0) {eval("oD.top = '" + iNY + sS + "'");}
		var sFunction = "flevSlideDiv('" + sD + "'," + iX + "," + iY + "," + iS + "," + iPx + ",0)";
		oD.tT = setTimeout(sFunction,iT);
	}
}


// Email Check
function emailCheck() {
if ((document.contact.yemail.value == "") && (document.contact.yphone.value == "")) { 
alert('Please provide either your phone number or e-mail address so that we may contact you.');
return false;
}
}

/* Rollovers */

var browserType = "old";

//Initialize variables that can be used to make functions cross browser.

if (document.getElementById && !document.all) {
  browserType = "NN5";
} else if (parseInt(navigator.appVersion) >= 4) {
  if (navigator.appName == "Netscape") {
    browserType = "NN4";
  }else{
    browserType = "IE4";
  }
}

function preloadImages() {

  var totImages = preloadImages.arguments.length;
  
  var temp = new Array()
  
  for (i=0; i<totImages; i++) {
    temp[i] = new Image();
    temp[i].src = "assets/" + preloadImages.arguments[i];
  }

}

function loadImage(imageName,imgUrl) {
  document.images[imageName].src=imgUrl;
}
