var menus = new Array();
var menusCnt = 0;
var menusID = new Array();
var currentEl = null;
var xmlDoc;

function init()
{
	var random_num = (Math.round((Math.random()*13)+1))
	var elm = document.getElementById("cnt");
	elm.style.backgroundImage = "url('Images/cntFtr" + random_num + ".png')";

	preLoadImg();

	var cnt = document.getElementById("cntBdy");
	setOpacity(cnt, 0);
	cnt.style.visibility = "visible";
	fadeIn("cntBdy",0,10);	

	log();
}

function preLoadImg()
{
	if (document.images)
  	{
     		pic1on= new Image(101,43);
     		pic1on.src="Images/bttnGr.gif"; 
/* 
     		pic1on= new Image(101,43);
     		pic1on.src="Images/bttnAltB1.gif";
     		pic1on= new Image(101,43);
     		pic1on.src="Images/bttnAltB2.gif";
     		pic1on= new Image(101,43);
     		pic1on.src="Images/bttnDB.gif";
     		pic1on= new Image(101,43);
     		pic1on.src="Images/bttnLB.gif";
     		pic1on= new Image(101,43);
     		pic1on.src="Images/bttnWh.gif";
*/
   	}
}

function log()
{

	url = "log.aspx?__=" + encodeURIComponent((new Date()).getTime()) + "&u=Claybrooke.ca&p=" + window.location.href;

	if( window.XMLHttpRequest ) {
		xmlDoc = new XMLHttpRequest();
		xmlDoc.open("GET", url, true);
		xmlDoc.send(null);
    	} 
	// branch for IE/Windows ActiveX version
	else if (window.ActiveXObject) {
        	xmlDoc = new ActiveXObject("Microsoft.XMLHTTP");
        	if (xmlDoc) {
            		xmlDoc.open("GET", url, true);
            		xmlDoc.send();
		}
        }
}

function initNoBckGrnd()
{
	var cnt = document.getElementById("cntBdy");

	setOpacity(cnt, 0);
	cnt.style.visibility = "visible";
	fadeIn("cntBdy",0,10);	
}

function initSiteMap()
{
	var random_num = (Math.round((Math.random()*13)+1))
	var elm = document.getElementById("cnt");

	elm.style.backgroundImage = "url('Images/cntFtr" + random_num + ".png')";
}

function show( id, order )
{
        var el = document.getElementById( id );
	var sub = document.getElementById( id + "_sub" );
	var anchor = document.getElementById( "mnCntRt" );
	var multiplier = 21;
	
	if(is_ie) multiplier += 1;
	//if(is_safari) multiplier -= 1;

	if( id.indexOf('.') == -1 ) hide();
	else hideSiblings( id );

	if( sub == null ) return;

	if( !menus[ id ] )
	{
		menus[ id ] = true;
		menusID[ menusCnt ] = id;
		menusCnt++;
	}

	//if( !is_safari) setOpacity(sub,0);
	sub.style.display = "block"; 
	sub.style.zIndex = "10";

	if( id.indexOf(".") == -1 ) 
	{
		sub.style.top = is_safari?anchor.offsetTop + 10 + "px":anchor.offsetTop + "px";
		sub.style.left = el.offsetLeft + "px";
	}
	else
	{
		sub.style.top = is_safari?anchor.offsetTop + 10 + (order*((order==1)?multiplier+2:multiplier)) 
					+ "px":anchor.offsetTop + (order*((order==1)?multiplier+2:multiplier)) + "px";
		sub.style.left = el.offsetParent.offsetLeft + el.offsetParent.offsetWidth + "px";
	}
	//if(!is_safari) fadeIn(sub.id,25,25);

	if( (id.match(/./g).length % 2) == 0 )
		sub.style.backgroundColor = "#757575";
}

function hide()
{
	if( menusCnt > 0 )
	{
		for( i=0; i < menusCnt; i++ )
		{
			var sub = document.getElementById( menusID[ i ] + "_sub" );
			
			if( sub == null ) return;
			
			//if( !is_safari) fadeOut(sub.id, 100, 50);
			//else
			//{
				sub.style.display = "none";
				sub.style.zIndex = "-1";
			//}
		}

		menus = new Array();
		menusCnt = 0;
		menusID = new Array();
	}
}

function hideSiblings( id )
{
	for( i=0; i < menusCnt; i++ )
	{

		if( menusID[ i ].match(/./g).length >= id.match(/./g).length && menusID[ i ] != id )
		{
			var sub = document.getElementById( menusID[ i ] + "_sub" );
			
			//if( !is_safari) fadeOut(sub.id, 100, 50);
			//else
			//{
				sub.style.display = "none";
				sub.style.zIndex = "-1";
			//}

			menus[ id ] = null;
			menusID[ i ] = null;
			menusCnt--;
		}
	}
}

function fadeIn(objId,opacity,step) 
{
	if (document.getElementById) 
	{
		obj = document.getElementById(objId);
		if (opacity <= 100) 
		{
			setOpacity( obj, opacity );
			opacity += step;
			window.setTimeout( "fadeIn('" + objId + "',"+opacity + "," + step + ")", 100 );
		}
	}
}

function fadeOut(objId,opacity,step) 
{
	if (document.getElementById) 
	{
		obj = document.getElementById(objId);
		if (opacity >= 0) 
		{
			setOpacity( obj, opacity );
			opacity -= step;
			window.setTimeout( "fadeOut('" + objId + "',"+opacity + "," + step + ")", 100 );
		}
		else
		{
			obj.style.display = "none";
			obj.style.zIndex = "-1";
		}
	}
}

function setOpacity(obj, opacity) 
{
	opacity = (opacity == 100)?99.999:opacity;
	obj.style.filter = "alpha(opacity:"+opacity+")";
	obj.style.KHTMLOpacity = opacity/100;
	obj.style.MozOpacity = opacity/100;
	obj.style.opacity = opacity/100;
}
function highlight(el, cName)
{
	currentEl = el.className;'grButton'
	el.className = cName;
}

function returnback(el)
{
	el.className = currentEl;
}

function openWin(w,h,nav,loc,sts,menu,scroll,resize,name,url) 
{
	// ex. openWin(800,600,false,false,false,false,false,true,'Win','http://www.google.ca');

	var windowProperties=''; 

	if(nav==false) windowProperties+='toolbar=no,'; 
	else windowProperties+='toolbar=yes,'; 

	if(loc==false) windowProperties+='location=no,'; 
	else windowProperties+='location=yes,'; 

	if(sts==false) windowProperties+='status=no,';
	else windowProperties+='status=yes,'; 

	if(menu==false) windowProperties+='menubar=no,';
	else windowProperties+='menubar=yes,'; 

	if(scroll==false) windowProperties+='scrollbars=no,';
	else windowProperties+='scrollbars=yes,'; 

	if(resize==false) windowProperties+='resizable=no,';
	else windowProperties+='resizable=yes,'; 

	if(w!="") windowProperties+='width='+w+',';
	if(h!="") windowProperties+='height='+h; 

	if(windowProperties!="") { 
 		if( windowProperties.charAt(windowProperties.length-1)==',') 
   			windowProperties=windowProperties.substring(0,windowProperties.length-1); 
	} 
 	window.open(url,name,windowProperties);
}