/* Scrolling Title Script */
var textDisplay = new Array ("Brad Armitage's Electronic Portfolio", "Site Updated 06-30-2008"); 
var textCount=2; 

var x=1; 
var y=0; 
var z=1; 
function animate() 
{ 
window.document.title=textDisplay[y].substr(0, x)+""; 
if (z==0) x--; 
if (z==1) x++; 
if (x==-1) {z=1;x=0;y++;y=y%textCount;} 
if (x==textDisplay[y].length+10) {z=0;x=textDisplay[y].length;} 
parent.window.document.title=textDisplay[y].substr(0, x)+""; 
setTimeout("animate()",75); 
}


/* New Javascript Window Script */
var win = null;
function NewWindow(mypage,myname,w,h,scroll,resize){
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings =
'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable='+resize+','
win = window.open(mypage,myname,settings)
}


/* Show/Hide Layers Script */
// resize fix for ns4
var origWidth, origHeight;
if (document.layers) {
	origWidth = window.innerWidth; origHeight = window.innerHeight;
	window.onresize = function() { if (window.innerWidth != origWidth || window.innerHeight != origHeight) history.go(0); }
}

var cur_lyr;	// holds id of currently visible layer
function swapLayers(id) {
  if (cur_lyr) hideLayer(cur_lyr);
  showLayer(id);
  cur_lyr = id;
}

function showLayer(id) {
  var lyr = getElemRefs(id);
  if (lyr && lyr.css) lyr.css.visibility = "visible";
}

function hideLayer(id) {
  var lyr = getElemRefs(id);
  if (lyr && lyr.css) lyr.css.visibility = "hidden";
}

function getElemRefs(id) {
	var el = (document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? getLyrRef(id,document): null;
	if (el) el.css = (el.style)? el.style: el;
	return el;
}

// get reference to nested layer for ns4
function getLyrRef(lyr,doc) {
	if (document.layers) {
		var theLyr;
		for (var i=0; i<doc.layers.length; i++) {
	  	theLyr = doc.layers[i];
			if (theLyr.name == lyr) return theLyr;
			else if (theLyr.document.layers.length > 0) 
	    	if ((theLyr = getLyrRef(lyr,theLyr.document)) != null)
					return theLyr;
	  }
		return null;
  }
}


/* Tree Menu Script */
img1=new Image()
img1.src="img/folder.gif"
img2=new Image()
img2.src="img/folderopen.gif"

var curr = null;
function change(e)
{
	if (!document.getElementsByTagName)
		return;

	var clicked = document.getElementsByTagName && !document.all ?  e.target : event.srcElement;
	var par = clicked.parentNode;
	if (/^folding|menu$/.test(clicked.className))
	{
		if (null != curr && par != curr)
		{
			curr.getElementsByTagName('img')[0].src = 'img/folder.gif';
			curr.getElementsByTagName('ul')[0].style.display = 'none';
		}
		var ul = par.getElementsByTagName('ul')[0];
		var icon = par.getElementsByTagName('img')[0];
		icon.src = (/folder.gif/.test(icon.src)) ? 'img/folderopen.gif' : 'img/folder.gif';
		ul.style.display = (ul.style.display == 'none') ? '' : 'none';
		curr = par;
	}
}

document.onclick = change;


/* Rollover Buttons Script */
function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		goback_2 = newImage("img/goback_2.gif");
		preloadFlag = true;
	}
}


/* Countdown Timer Script */
function countdown_clock(year, month, day, hour, minute, format)
         {
         html_code = '<div id="countdown" style="color:#FF3300; font-size:18px;"></div>';
         
         document.write(html_code);
         
         countdown(year, month, day, hour, minute, format);                
         }
         
function countdown(year, month, day, hour, minute, format)
         {
         Today = new Date();
         Todays_Year = Today.getFullYear() - 2000;
         Todays_Month = Today.getMonth();                  
         
         //Convert both today's date and the target date into miliseconds.                           
         Todays_Date = (new Date(Todays_Year, Todays_Month, Today.getDate(), 
                                 Today.getHours(), Today.getMinutes(), Today.getSeconds())).getTime();                                 
         Target_Date = (new Date(year, month - 1, day, hour, minute, 00)).getTime();                  
         
         //Find their difference, and convert that into seconds.                  
         Time_Left = Math.round((Target_Date - Todays_Date) / 1000);
         
         if(Time_Left < 0)
            Time_Left = 0;
         
         switch(format)
               {
               case 0:
                    //The simplest way to display the time left.
                    document.all.countdown.innerHTML = Time_Left + ' seconds.';
                    break;
               case 1:
                    //More datailed.
                    days = Math.floor(Time_Left / (60 * 60 * 24));
                    Time_Left %= (60 * 60 * 24);
                    hours = Math.floor(Time_Left / (60 * 60));
                    Time_Left %= (60 * 60);
                    minutes = Math.floor(Time_Left / 60);
                    Time_Left %= 60;
                    seconds = Time_Left;
                    
                    dps = 's,'; hps = 's,'; mps = 's'; sps = 's.';
                    //ps is short for plural suffix.
                    if(days == 1) dps =',';
                    if(hours == 1) hps =',';
                    if(minutes == 1) mps ='';
                    if(seconds == 1) sps ='.';
                    
					//document.all.countdown.innerHTML = 'These modifications will be live in exactly: ';
                    document.all.countdown.innerHTML = days + ' day' + dps + ' ';
                    document.all.countdown.innerHTML += hours + ' hour' + hps + ' ';
                    document.all.countdown.innerHTML += minutes + ' minute' + mps + ' and ';
                    document.all.countdown.innerHTML += seconds + ' second' + sps;
                    break;
               default: 
                    document.all.countdown.innerHTML = Time_Left + ' seconds.';
               }
               
         //Recursive call, keeps the clock ticking.
         setTimeout('countdown(' + year + ',' + month + ',' + day + ',' + hour + ',' + minute + ',' + format + ');', 1000);
         }


/* New Javascript Window Script */
var win = null;
function NewWindow(mypage,myname,w,h,scroll,resize){
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings =
'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable='+resize+','
win = window.open(mypage,myname,settings)
}

