var ds1 = new Spry.Data.XMLDataSet('../_includes/content.xml', 'pages/page');

var navHeads = new Array();
var navDown = 0;
var loadDone = 0;
var nid = gup("id");
if (!nid) { nid = 0; }



//
// Step 2: Add a data changed observer. The spry:region will kick off the loading
//         of our data set, so we don't have to do it manually.
//
ds1.addObserver({ onDataChanged: function(ds, type)
{
	// You can ask findRowsWithColumnValues() to return only the first matching row in the
	// data set that has all of the specified column values.
	//
	// Note, that we could've easily found the row we were interested in by just using "@id"
	// since every item in the data set has a unique id. Lastname was also used in this example
	// to illustrate that you *can* pass multiple column values to match against.
	

	var row = ds1.findRowsWithColumnValues({"@id": nid }, true);

	// If we have a matching row, make it the current row for the data set.

	if (row)
		ds1.setCurrentRow(row.ds_RowID);
		var rows = ds1.getData();
		for (var i = 0; i < rows.length; i++) {
			navHeads.push(rows[i]["navTitle"]);
		}
		if (nid == 0) {
			MM_swapImage('b' + nid,'','images/home-btn-sel.gif');
		} else {
			MM_swapImage('b' + nid,'','images/normal-sel.gif');
		}
		loadDone ++;
		
	}
	
	
});



function loadActions() {
	if (nid >= 3 && nid <= 6) {
		MM_findObj('pullq').style.backgroundColor = "#5995c7";
		MM_findObj('sect').style.color = "#5995c7";
	} else if (nid >= 7 && nid <= 10) {
		MM_findObj('pullq').style.backgroundColor = "#3D98C2";
		MM_findObj('sect').style.color = "#3D98C2";
	} else if (nid >= 11 && nid <= 11) {
		MM_findObj('pullq').style.backgroundColor = "#5995c7";
		MM_findObj('sect').style.color = "#5995c7";
	}
	MM_preloadImages('images/home-btn-on.gif', 'images/left-on.gif', 'images/right-on.gif', 'images/normal-on.gif', 'images/top-bg.gif');
	for (var i = 0; i <= 16; i++) {
		MM_preloadImages('../images/topImageSlider/slider_' + i + '.jpg');
	}
	loadDone++;
}

function gup( name )
{
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var tmpURL = window.location.href;
  var results = regex.exec( tmpURL );
  if( results == null )
    return "";
  else
    return results[1];
}

function goNext() {
	var id = parseInt(nid) + parseInt(1);
	if (id > 12) {
		id = 0;
	}
	goPage(id);
}

function goPrev() {
	var id = parseInt(nid) - parseInt(1);
	if (id < 0) {
		id = 13;
	}
	goPage(id);
}

function goPage( id ) {
	if (id == 0) {
		document.location.href = "index.html?id=0";
	} else if (id == 1) {
		document.location.href = "letterceo.html?id=1";
	} else if (id == 2) {
		document.location.href = "foundation.html?id=2";
	} else if (id == 11) {
		document.location.href = "letterpres.html?id=11";
	} else if (id == 12) {
		document.location.href = "bod.html?id=12";
	} else if (id == 13) {
		document.location.href = "grants.html?id=13";
	} else {
		document.location.href = "standard.html?id=" + id;
	}
}

function switchThumb(newThumb, newCap) {
	MM_setTextOfLayer('caption','',newCap);
	for (var i = 0; i <5; i++) {
		MM_findObj('lgPict' + i).style.display = "none";
	}
	MM_findObj('lgPict' + newThumb).style.display = "block";
}



function highlightNext() {
	if (loadDone < 2) { return; }
	hideNav();
	MM_swapImage('next','','images/right-on.gif');
}

function highlightPrev() {
	if (loadDone < 2) { return; }
	hideNav();
	MM_swapImage('prev','','images/left-on.gif');
}

function showNav( id ) {
	if (loadDone < 2) { return; }
	if (!navDown) {
		Spry.Effect.DoFade('navArea', {duration: 300, from:  0, to:  75});
		Spry.Effect.DoFade('navPictHolder', {duration: 300, from:  0, to:  100});
		Spry.Effect.DoFade('navText', {duration: 300, from:  0, to:  100});
	}
	navDown = 1;
	
	if (id == 0) {
		MM_swapImage('b' + id,'','images/home-btn-on.gif');
		MM_setTextOfLayer('navText','',navHeads[id]);
		MM_swapImage('navPict','','../images/topImageSlider/slider_0.jpg');
	} else {
		MM_swapImage('b' + id,'','images/normal-on.gif');
		MM_setTextOfLayer('navText','',navHeads[id]);
		MM_swapImage('navPict','','../images/topImageSlider/slider_' + id + '.jpg');
	}
}

function hideNav() {
	if (loadDone < 2) { return; }
	if (navDown) {
		Spry.Effect.DoFade('navArea', {duration: 300, from:  75, to:  0});
		Spry.Effect.DoFade('navPictHolder', {duration: 300, from:  100, to:  0});
		Spry.Effect.DoFade('navText', {duration: 300, from:  100, to:  0});
	}
	navDown = 0;
	restoreSquare( nid );
}

function restoreSquare( id ) {
	if (loadDone < 2) { return; }
	if (id == nid) {
		if (nid == 0) {
			MM_swapImage('b' + id,'','images/home-btn-sel.gif');
		} else {
			MM_swapImage('b' + id,'','images/normal-sel.gif');
		}
		return;
	}
	
	if (id == 0) {
		MM_swapImage('b' + id,'','images/home-btn-off.gif');
	} else if (id == 18) {
		MM_swapImage('prev','','images/left-off.gif');
	} else if (id == 19) {
		MM_swapImage('next','','images/right-off.gif');
	} else {
		MM_swapImage('b' + id,'','images/normal-off.gif');
	}
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

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;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_setTextOfLayer(objName,x,newText) { //v4.01
  if ((obj=MM_findObj(objName))!=null) with (obj)
    if (document.layers) {document.write(unescape(newText)); document.close();}
    else innerHTML = unescape(newText);
}

