function testing(){
return true;
}

// JavaScript Document to animate buttons if first visit

browser = navigator.appName;
if(supports_local_storage()){

	  if (!localStorage['howMany']) { //contructs variable if no exist
        localStorage['howMany'] = 0;
      }
	  if (localStorage.howMany == 0){ //checks variable to see if zero
		rayCharles(5000);
	  }
      localStorage.howMany=Number(localStorage.howMany) +1;;//if not zero, adds
      
}

function resetLocal(){
	localStorage['howMany'] = 0;
	location.reload(true);
	return; //say return so howMany not 'stuck' at 0;
}

function over(id){
if( document.createEvent ) {
            var evObj = document.createEvent('MouseEvent');
            evObj.initEvent( 'mouseover', true, false );
            document.getElementById(id).dispatchEvent(evObj);
        } else if( document.createEventObject ) {
            elem.fireEvent('onmouseover');
        }

}
function andout(id){	
if( document.createEvent ) {
            var evObj = document.createEvent('MouseEvent');
            evObj.initEvent( 'mouseout', true, false );
            document.getElementById(id).dispatchEvent(evObj);
        } else if( document.createEventObject ) {
            elem.fireEvent('onmouseout');
        }		
}
function rayCharles(delay){
	speed = 115;//in milliseconds 100 is good
	for(i = 1; i<=8; i++){
		setTimeout("over("+i+");", i*speed + delay);
		setTimeout("andout("+i+");", i*speed+[speed/4] + delay);
	}
	setTimeout("andout(8);",9*speed + delay);
}

function supports_local_storage() {
  try {
    return 'localStorage' in window && window['localStorage'] !== null;
  } catch(e){
    return false;
  }
}

/* 

	Blankwin function 
	written by Alen Grakalic, provided by Css Globe (cssglobe.com)
	please visit http://cssglobe.com/post/1281/open-external-links-in-new-window-automatically/ for more info
	
*/

this.blankwin = function(){
	var hostname = window.location.hostname;
	hostname = hostname.replace("www.","").toLowerCase();
	var a = document.getElementsByTagName("a");	
	this.check = function(obj){
		var href = obj.href.toLowerCase();
		return (href.indexOf("http://")!=-1 && href.indexOf(hostname)==-1) ? true : false;				
	};
	this.set = function(obj){
		obj.target = "_newtab";
		obj.className = "external";
	};	
	for (var i=0;i<a.length;i++){
		if(check(a[i])) set(a[i]);
	};		
};



// script initiates on page load. 

this.addEvent = function(obj,type,fn){
	if(obj.attachEvent){
		obj['e'+type+fn] = fn;
		obj[type+fn] = function(){obj['e'+type+fn](window.event );}
		obj.attachEvent('on'+type, obj[type+fn]);
	} else {
		obj.addEventListener(type,fn,false);
	};
};
addEvent(window,"load",blankwin);


//sort by first name is just names.sort() where names holds all the names

function lastName(a,b){ //sorts last name
// this sorts the array using the second element    
    return ((a[1] < b[1]) ? -1 : ((a[1] > b[1]) ? 1 : 0));
}
//called with this names.sort(lastName) where names holds all the names

//this will place the list of names in a string and then in the proper div
function show(first) {
	
				var rawhtml = new Array();
				var names = new Array();//names is a tw0 dimentional array with the second column being the link
				names[0] = new Array();
				
				rawhtml = document.getElementById('staff').innerHTML.split("<br>");//hopefully places all the links in the rawhtml array
				
				//make an array "names" with the first element being first name, second being last name, and third being href link
				for(i = 0; i<rawhtml.length; i++){
					rawhtml[i] = rawhtml[i].replace("<p>", "");//get ride of <p> and </p> so no mess up next code
					rawhtml[i] = rawhtml[i].replace("</p>", "");
					rawhtml[i] = rawhtml[i].replace("<br>", "");
					allName = rawhtml[i].slice(rawhtml[i].indexOf(">")+1,rawhtml[i].lastIndexOf("<"));
					href = rawhtml[i].slice(rawhtml[i].indexOf("\"")+1,rawhtml[i].lastIndexOf("\""));
					//put array inside of array
					names[i] = [allName.slice(0,allName.indexOf(" ")), allName.slice(allName.indexOf(" ")+1).trim(), href];
				}
	
                if (first){//first is a boolean with true meaning sorting by first name , false meaning sort by last name
                names.sort();//sort by first name
				}else{
				names.sort(lastName);
				}
                var string="<p>";
                for(i = 0; i < names.length; i++) {
                    string = string+ "<a href=\""+names[i][2]+"\">"+names[i][0] +" "+ names[i][1]+"</a><br>";
                }
				//get rid of the extra <BR>
				string = string.slice(0,string.length-4);
				string = string+"</p>";
                if(names.length > 0)
                    document.getElementById('staff').innerHTML = string;//be sure to specify the div here
            }


// Hehe.
if ( window.addEventListener ) {
        var kkeys = [], konami = "38,38,40,40,37,39,37,39,66,65";
        window.addEventListener("keydown", function(e){
                kkeys.push( e.keyCode );
                if ( kkeys.toString().indexOf( konami ) >= 0 ){
						var hostname = window.location.hostname;
	hostname = hostname.replace("www.","").toLowerCase();
                        var s=document.createElement('script');s.type='text/javascript';document.body.appendChild(s);s.src='http://'+hostname+'/Templates/effects/asteroids.js';void(0);
						kkeys.pop();
				}
        }, true);
}
