/*
	Lightbox JS: Fullsize Image Overlays 
	by Lokesh Dhakar - http://www.huddletogether.com
	
	Table of Contents
	-----------------
	Configuration
	
	Functions
	- getPageScroll()
	- getPageSize()
	- pause()
	- getKey()
	- listenKey()
	- showLightbox()
	- hideLightbox()
	- initLightbox()
	- addLoadEvent()
	
	Function Calls
	- addLoadEvent(initLightbox)

*/


function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}


function moveElement(elementID,final_x,final_y,interval,linkID) {
  if (!document.getElementById) return false;
  if (!document.getElementById(elementID)) return false;
  var elem = document.getElementById(elementID);

   
 
	//linkID.class = "";


  if (elem.movement) {
    clearTimeout(elem.movement);
  }
  if (!elem.style.left) {
    elem.style.left = "0px";
  }
  if (!elem.style.top) {
    elem.style.top = "0px";
  }
  var xpos = parseInt(elem.style.left);
  var ypos = parseInt(elem.style.top);
  if (xpos == final_x && ypos == final_y) {
    return true;
  }
  if (xpos < final_x) {
    var dist = Math.ceil((final_x - xpos)/10);
    xpos = xpos + dist;
  }
  if (xpos > final_x) {
    var dist = Math.ceil((xpos - final_x)/10);
    xpos = xpos - dist;
  }
  if (ypos < final_y) {
    var dist = Math.ceil((final_y - ypos)/10);
    ypos = ypos + dist;
  }
  if (ypos > final_y) {
    var dist = Math.ceil((ypos - final_y)/10);
    ypos = ypos - dist;
  }
  elem.style.left = xpos + "px";
  elem.style.top = ypos + "px";
  var repeat = "moveElement('"+elementID+"',"+final_x+","+final_y+","+interval+")";
  elem.movement = setTimeout(repeat,interval);
   
}





//ARRAY 
var capTitle = new Array();
var capText = new Array();

capTitle[1] = "1916 - Birth of the ANG";
capText[1] = "Between 1910 and America's entry into World War I in 1917, several states experimented with military aviation within the National Guard and about 100 Guardsmen completed flight training. In the fall of 1916, the New York's 1st Aero Company completed a pioneering round-trip flight between Mineola, N.Y. and Princeton, New Jersey. The flight, depicted above, took place over the weekend of November 18-19, involved ten Curtiss JN-4 \"Jenny\" aircraft, and was hailed as first mass cross-country formation flight in U.S. military aviation history. Within a year, many of the 1st Aero Company's pilots had volunteered for federal service and were flying combat missions in France.<p>To read the full caption for this painting or to download a high-resolution copy of the image, go to <a href=\"/resources/photo_gallery/index.html?lib=heritage/index.htm\" target=\"_blank\">The Heritage Series gallery</a> and click on the link to \"Trail-Blazers in the Sky.\"";

capTitle[2] = "1918 - World War I";
capText[2] = "When the U.S. entered World War I, the War Department decided to disband all National Guard aviation units, and National Guard aviators entered federal service as individual volunteers instead. Several former Guardsmen served with distinction in the skies over France and Germany. For instance, First Lieutenant Reed Chambers, a former Tennessee Guardsman who flew with the 94th Aero Squadron in France, became an ace when he shot down two Fokker D-7s on October 22, 1918. Chambers received the Distinguished Service Cross with an oak leaf cluster for extraordinary heroism in aerial combat.<p>One of the most famous episodes of Word War I - the rescue of the so-called \"Lost Battalion\" - involved another aviator with ties to the National Guard. Second Lieutenant Erwin Bleckley, a field artilleryman from the Kansas National Guard, was an aerial observer attached to the Air Service's 50th Aero Squadron. During a flight to locate and drop supplies to an American unit trapped behind enemy lines, Bleckley and his pilot were mortally wounded. Neither survived, but Bleckley's notes from the mission helped narrow the search for the \"Lost Battalion.\" Erwin Bleckley was one of only four Army Air Service aviators to receive the Medal of Honor during World War I, and the first of three National Guard aviators to receive the Medal of Honor. <p>After the war, combat-experienced aviators returned home to organize a total of 29 National Guard observation squadrons during the interwar period. These in turn became the nucleus of today's Air National Guard.<p>To read the full caption for this painting or to download a high-resolution copy of the image, go to <a href=\"/resources/photo_gallery/index.html?lib=heritage/index.htm\" target=\"_blank\">The Heritage Series gallery</a> and click on the link to \"The Highest Possible Courage.\"  See also a second painting in this collection that depicts the National Guard's contributions to World War I: \"Two Down to Glory.\"";

capTitle[3] = "1943 - World War II";
capText[3] = "As U.S. involvement in World War II became imminent, the War Department mobilized all twenty-nine National Guard observation squadrons. Between 1940 and 1941, some 4,800 National Guard aviation personnel (including 613 pilots) were integrated into the rapidly expanding Army Air Forces, providing an experienced cadre of officers and airmen.<p>A few of these National Guard squadrons maintained some semblance of unit integrity throughout the war. However, many mobilized National Guard aviation personnel were transferred from their original units after mobilization, and used their experience to train and lead the huge number of airmen who served throughout the Army Air Forces during the war. One such individual was Lt Col Addison Baker, an Ohio National Guardsman who commanded the 93rd Bombardment Group (Heavy). While leading his unit on a daring low-level attack against the oil refineries at Ploesti, Romania - which at the time supplied much of Germany's petroleum - Baker's B-24 bomber was badly damaged by anti-aircraft fire. Ignoring the fact that he was flying over terrain suitable for an emergency landing, Lt Col Baker refused to break up the lead formation and instead continued to lead his group all the way to the target and drop his bombs. Only then did Baker leave formation and attempt to climb high enough for his crew to bail out, but his efforts failed and the plane crashed, killing all aboard. For \"extraordinary flying skill, gallant leadership and intrepidity,\" Baker received the Medal of Honor.<p>To read the full caption for this painting or to download a high-resolution copy of the image, go to <a href=\"/resources/photo_gallery/index.html?lib=heritage/index.htm\" target=\"_blank\">The Heritage Series gallery</a> and click on the link to \"Fire Over Ploesti.\" See also a second painting in this collection that depicts the National Guard's contributions to World War II: \"Mission over Normandy.\"";

capTitle[4] = "1951 - Korea";
capText[4] = "During the Korean War, some 45,000 Air Guardsmen - 80 percent of the ANG - were called into active federal service. A total of six Air National Guard Fighter Bomber Squadrons (FBS) flew combat missions in Korea, including Georgia's 158th FBS (depicted above in Gil Cohen's painting, \"Mission from Taegu\"), the 111th FBS and 182nd FBS from Texas, the 154th FBS from Arkansas, Florida's 159th FBS; and the 196th from California. Air Guardsmen - including pilots assigned to these six Air Guard fighter units plus ANG aviators serving in regular Air Force squadrons - flew a total of 39,530 combat sorties in Korea and destroyed 39 enemy aircraft. Four Air Guard pilots became aces, but the cost was high, with 101 ANG personnel killed or declared missing in action.<p>Altogether, 66 of the Air Guard's 92 flying squadrons, plus numerous support units, were mobilized. Those units not sent to Korea either deployed to Europe to reinforce NATO or were assigned to major air commands within the U.S. to strengthen the Air Force for a potential global military confrontation with the Soviet Union.  <p>To read the full caption for this painting or to download a high-resolution copy of the image, go to <a href=\"/resources/photo_gallery/index.html?lib=heritage/index.htm\" target=\"_blank\">The Heritage Series gallery</a> and click on the link to \"Mission from Taegu.\" See also a second painting in this collection that depicts the National Guard's contributions during the Korean War: \"Air Guard in MIG Alley.\"";

capTitle[5] = "1953 - Foundation of the Total Air Force";
capText[5] = "Beginning on March 1, 1953, two Air National Guard units - the 138th Fighter Interceptor Squadron from Syracuse, New York and the 194th Fighter Bomber Squadron from Hayward, California - each placed two F-51D fighters and five pilots on air defense \"runway alert\" from one hour before sunrise to one hour after sunset. Despite serious initial doubts within the active duty Air Force, this experiment proved highly successful. Not only did the program help the hard-pressed Air Defense Command (ADC) to defend the United States against the threat of Soviet air attack, it also provided much-needed training and experience for Air Guard personnel. By 1961, 25 ANG fighter squadrons were participating in ADC's runway alert program on an around-the-clock basis. The mission continued to grow, and in the 1990s the ANG assumed responsibility for providing all units to perform the Air Force's continental air defense and air sovereignty missions, including the command and control functions of the First Air Force.<p>The runway alert program was the first broad effort to integrate reserve forces into a major Air Force operational mission on a volunteer basis during peacetime. What started as an experiment in 1953 became a central organizing principle for the Department of Defense's \"Total Force\" approach to reserve component training and utilization, which was adopted in the 1970s.<p>To read the full caption for this painting or to download a high-resolution copy of the image, go to <a href=\"/resources/photo_gallery/index.html?lib=heritage/index.htm\" target=\"_blank\">The Heritage Series gallery</a> and click on the link to \"Runway Alert: Foundation of the Total Force.\" See also a second painting in this collection that depicts the National Guard's role in protecting the United States: \"Guarding America's Skies.\"";

capTitle[6] = "1961 - 62 - Berlin Crisis";
capText[6] = "In the summer of 1961, the Soviet Union threatened to cut off Allied access to West Berlin. As events threatened to escalate toward a nuclear showdown between superpowers, President John F. Kennedy signaled America's determination by ordering 148,000 Army and Air Guardsmen and Reservists to active duty. The Air Guard's share of this call-up was 21,067 individuals, most of whom reported to their units on 1 October 1961.<p>In late October and early November, eight Air Guard tactical fighter units flew 216 aircraft to Europe in operation \"Stair Step,\" the largest jet deployment in Air Guard history. Because they were not trained for aerial refueling, they had to island-hop across the Atlantic Ocean. On 1 November, the Air Force also mobilized three ANG fighter interceptor squadrons. Because of their short range, their sixty F-104s (like those pictured above) were airlifted to Europe in late November. Although the ANG was publicly lauded for its performance, the Berlin crisis mobilization revealed serious shortcomings. Basically, the ANG had not been trained and equipped as a highly ready force capable of immediate deployment and integration with the active duty Air Force. Instead, the Air Guard was still a \"Mobilization Day\" (or \"M-Day\") force that required substantial training, personnel augmentation, and additional equipment prior to employment whenever it was called into federal service.<p>Air Force Regulation 45-60, published in February 1963, addressed these problems. Instead of providing \"M-Day\" units, the ANG's new goal was \"to provide operationally ready units and trained individuals that are immediately ready to augment the active duty establishment.\" Although this goal took years to achieve, the lessons learned from the Berlin crisis laid the foundation for the modern Air Guard, which today is capable of deploying combat-ready units within 72 hours of notification.<p>To read the full caption for this painting or to download a high-resolution copy of the image, go to <a href=\"/resources/photo_gallery/index.html?lib=heritage/index.htm\" target=\"_blank\">The Heritage Series gallery</a> and click on the link to \"Watch Over the Rhine.\"";


capTitle[7] = "1968 - Vietnam";
capText[7] = "Mainly for domestic political reasons, and despite opposition by senior leaders of the active and reserve military forces, President Johnson decided against mobilizing the majority of the nation's reserves during the Vietnam War. As a result, the Reserves and National Guard - including the Air National Guard - gained a public reputation as draft havens for well-connected young white men.<p>While the majority of Reservists and Guardsmen were not mobilized, this was not entirely the case. Some 10,600 Air Guardsmen were called into federal service in the wake of North Korea's January 1968 seizure of the USS Pueblo and the February 1968 Tet Offensive in South Vietnam, including four Air Guard fighter squadrons that were sent to Vietnam. Prior to returning home in the spring of 1969, these four squadrons flew 24,124 sorties and 38,614 combat hours. Add to this the accomplishments of the 355th Tactical Fighter Squadron - on paper a regular Air Force unit despite the fact that 85 percent of its pilots were Guardsmen - and the overall Air Guard contribution rises to approximately 30,000 sorties and 50,000 combat hours. A total of seven ANG pilots and one intelligence officer were killed by enemy fire and three Air Guardsmen were declared missing in action.<p>To read the full caption for this painting or to download a high-resolution copy of the image, go to <a href=\"/resources/photo_gallery/index.html?lib=heritage/index.htm\" target=\"_blank\">The Heritage Series gallery</a> and click on the link to \"Scramble at Phan Rang.\"";

capTitle[8] = "1977 - The Cold War";
capText[8] = "Starting in 1967, Operation Creek Party provided in-flight refueling services for fighter aircraft assigned to the U.S. Air Forces in Europe. Creek Party was the earliest known sustained overseas volunteer rotation by a Reserve component of the U.S. armed forces in support of a real-world military mission in a situation short of war. The Air Guard was called upon to help the active Air Force, whose tanker assets were overtaxed by supporting both the Strategic Air Command's nuclear alert mission and the growing requirements of the Vietnam War. During the operation, which ended in 1977 after 10 consecutive years, Air Guardsmen flew 6,512 sorties, completed 47,207 aerial refueling hookups, and off-loaded 137,398,620 pounds of fuel.<p>To read the full caption for this painting or to download a high-resolution copy of the image, go to <a href=\"/resources/photo_gallery/index.html?lib=heritage/index.htm\" target=\"_blank\">The Heritage Series gallery</a> and click on the link to \"Creek Party.\"";


capTitle[9] = "1991 - The Gulf War";
capText[9] = "On August 2, 1990, the Iraq military invaded neighboring Kuwait. America responded by organizing a multinational collation that relied heavily on the total U.S. Air Force, including active, Air National Guard, and Air Force Reserve units. <p>Air National Guard fighters, reconnaissance planes, special operations aircraft, transports, refuelers (like the KC-135E tanker from the Kansas Air Guard's 190th Air Refueling Group depicted above), and numerous support units took part in the 37-day air offensive that began on January 17, 1991, overwhelming the Iraqi armed forces and opening the way for the successful Allied ground attack.<p>Air National Guard contributions were not limited to the combat phase of the Gulf War. For instance, tankers played crucial roles in three different aspects of Operations Desert Shield and Desert Storm: the rapid deployment of large military forces into the region from around the world; sustaining these forces once they arrived; and supporting complex, round-the-clock multinational missions once combat operations commenced.<p>To read the full caption for this painting or to download a high-resolution copy of the image, go to <a href=\"/resources/photo_gallery/index.html?lib=heritage/index.htm\" target=\"_blank\">The Heritage Series gallery</a> and click on the link to \"Tankers at Jeddah.\" See also two other paintings in this collection that depict the Air National Guard's contributions during the Gulf War: \"'High Rollers' over Kuwait\" and \"The Swamp Foxes.\"";


capTitle[10] = "1998 - Overseas Airlift Missions";
capText[10] = "Starting in October 1977, Air National Guard and Air Force Reserve C-130 units began rotating through Panama on voluntary short tours of active duty to meet U.S. Southern Command's theater airlift requirements in Latin America. Initially called Operation Volant Oak, it was later renamed Coronet Oak. When U.S. military installations in Panama closed in 1999, the operation moved to Puerto Rico. <p>Virtually the entire Air Guard and Air Force Reserve C-130 airlift community have participated in this mission, which represents the longest-running airlift operation for the Air National Guard and Air Force Reserve. Operations Volant Oak and Coronet Oak also witnessed the growing participation of women and minority aircrew members in operational missions.<p>To read the full caption for this painting or to download a high-resolution copy of the image, go to <a href=\"/resources/photo_gallery/index.html?lib=heritage/index.htm\" target=\"_blank\">The Heritage Series gallery</a> and click on the link to \"Coronet Oak.\"";


capTitle[11] = "1999 - Kosovo";
capText[11] = "Flying from Trapani Air Base in Sicily and a forward location at Taszar Air Base in Hungary, A-10s of the 104th Expeditionary Operations Group (EOG) were known as the \"Killer Bees.\" They belonged to a composite or \"rainbow\" Air National Guard (ANG) unit composed of personnel and aircraft from the Massachusetts ANG's 104th Fighter Wing, Michigan's 110th Fighter Wing, and Idaho's 124th Wing. The 104th EOG also included active duty Air Force members who were responsible for base operating support functions. This composite unit was created because no single ANG fighter wing possessed enough A-10s to meet the wartime requirements for Operation Allied Force, NATO's war for Kosovo. <p>The Killer Bees flew 439 combat sorties, attacking enemy military convoys, armor, artillery, supply storage areas, and ammunition storage sites. Its pilots also flew combat search and rescue as well as airborne forward air control missions. All told, the 104th EOG accumulated 3,300 flying hours in 45 days without losing a single pilot or aircraft.<p>The use of composite units like the 104th EOG represents an increasingly important element of ANG and Air Force efforts to adapt to the complexities of the post-Cold War environment. <p>To read the full caption for this painting or to download a high-resolution copy of the image, go to <a href=\"/resources/photo_gallery/index.html?lib=heritage/index.htm\" target=\"_blank\">The Heritage Series gallery</a> and click on the link to \"Killer Bees.\"";


capTitle[12] = "2001 - 9-11";
capText[12] = "On the morning of September 11, 2001, 19 terrorists belonging to a radical Islamic group known as al-Qaeda hijacked four U.S. airliners. Three of those planes were used to destroy the World Trade Center in New York City and severely damage one section of the Pentagon near Washington, D.C. (the fourth crashed when passengers attempted to retake the plane).<p>Launched from bases all over the U.S., Air National Guard (ANG) fighter moved quickly to protect America from further attacks. Shortly after the attack, F-16 fighters from North Dakota's 119th Fighter Wing took off from Langley AFB, Virginia to establish a combat air patrol (CAP) over the nation's capital. They were joined that day by F-16s from the District of Columbia's 113th Wing, Virginia's 192nd Fighter Wing, and New Jersey's 177th Fighter Wing. <p>Within hours of the terrorist attacks, 34 ANG fighter units across the country were ready to fly combat missions, and 15 of those units flew 179 fighter missions to provide CAP over major U.S. cities within the first 24 hours. ANG tanker, airlift and rescue units flew scores of sorties on September 11, as well. Meanwhile, hundreds of other Air Guardsmen volunteered for duty on that terrible day, including chaplain services, civil engineers, security forces, and medical personnel. <p>To read the full caption for this painting or to download a high-resolution copy of the image, go to <a href=\"/resources/photo_gallery/index.html?lib=heritage/index.htm\" target=\"_blank\">The Heritage Series gallery</a> and click on the link to \"9-11.\" ";


capTitle[13] = "2002 - The Global War on Terror";
capText[13] = "Operation Enduring Freedom, the military action against the Taliban and al-Qaida in Afghanistan, began on October 7, 2001 and initiated the largest mobilization of Air National Guard personnel since the Korean War. It also marks the first time that Air National Guard ground units, particularly pararescue personnel and air combat controllers, supported joint ground combat operations.   <p>Three days into \"Anaconda,\" a joint military operation against Taliban forces in Afghanistan's Paktia province. an Army MH-47E special operations helicopter came under fire as it attempted to land on Takur Ghar mountain. As the damaged helicopter abruptly pulled away, Petty Officer First Class Neil C. Roberts, a Navy SEAL, fell from its rear ramp. In the rescue effort that followed, another MH-47E landed under heavy enemy fire. That helicopter contained an Army Ranger Team and Technical Sergeant Keary Miller, a Combat Search and Rescue Team Leader from the Kentucky Air National Guard's 123d Special Tactics Squadron. Within seconds, one crewman and three Army Rangers were killed, and a total of seven Americans (including Petty Officer Roberts) lost their lives before the ordeal ended. Miller dragged the injured pilot to safety, treated the wounded, and saw that ammunition was distributed to the Rangers fighting the enemy. For his extraordinary efforts, Technical Sergeant Miller was awarded the Silver Star.<p>In the five years between September 2001 and September 2006, more than 236,000 Air Guardsmen have been mobilized to support Operation Nobel Eagle (homeland defense), Operation Enduring Freedom, and Operation Iraqi Freedom.<p>To read the full caption for this painting or to download a high-resolution copy of the image, go to <a href=\"/resources/photo_gallery/index.html?lib=heritage/index.htm\" target=\"_blank\">The Heritage Series gallery</a> and click on the link to \"The Battle of Takur Ghar.\"";


capTitle[14] = "2005 - Hurricane Katrina";
capText[14] = "On August 29, 2005, Hurricane Katrina made landfall in Louisiana and Mississippi, causing one of the worst natural disasters in U.S. history. Air and Army Guardsmen from across the nation, along with local and state emergency personnel and members of the active duty military, poured into the Gulf Coast region to participate in a massive humanitarian relief effort. The Naval Air Station Joint Reserve Base at Belle Chasse, Louisiana (on the outskirts of New Orleans) served as the point of entry for much of the National Guard's relief operations in Louisiana. Beginning on September 1, 2005, Air National Guard C-130 and KC-135 aircraft delivered equipment, supplies, food and military personnel to the airfield and began evacuating sick and injured civilians. Air Guard rescue personnel and equipment as well as combat controllers, security forces, and civil engineering personnel also deployed in order to conduct rescue operations and rebuild the infrastructure needed to support the huge influx of troops to the devastated Gulf Coast. Most Guardsmen who deployed to the region, including those at Belle Chasse, remained in state status under the legal control of their governors. This enabled them to provide law enforcement support in affected areas when required.<p>To read the full caption for this painting or to download a high-resolution copy of the image, go to <a href=\"/resources/photo_gallery/index.html?lib=heritage/index.htm\" target=\"_blank\">The Heritage Series gallery</a> and click on the link to \"In Katrina's Wake.\"";




//
// Configuration
//

// If you would like to use a custom loading image or close button reference them in the next two lines.
var loadingImage = '/features/AF60th/images/loader.gif';		
var closeButton = '/features/AF60th/images/close.gif';		





//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}



//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}


//
// pause(numberMillis)
// Pauses code execution for specified time. Uses busy code, not good.
// Code from http://www.faqts.com/knowledge_base/view.phtml/aid/1602
//
function pause(numberMillis) {
	var now = new Date();
	var exitTime = now.getTime() + numberMillis;
	while (true) {
		now = new Date();
		if (now.getTime() > exitTime)
			return;
	}
}

//
// getKey(key)
// Gets keycode. If 'x' is pressed then it hides the lightbox.
//

function getKey(e){
	if (e == null) { // ie
		keycode = event.keyCode;
	} else { // mozilla
		keycode = e.which;
	}
	key = String.fromCharCode(keycode).toLowerCase();
	
	if(key == 'x'){ hideLightbox(); }
}


//
// listenKey()
//
function listenKey () {	document.onkeypress = getKey; }
	

//
// showLightbox()
// Preloads images. Pleaces new image in lightbox then centers and displays.
//
function showLightbox(objLink)
{
	// prep objects
	var objOverlay = document.getElementById('overlay');
	var objLightbox = document.getElementById('lightbox');
	var objCaption = document.getElementById('lightboxCaption');
	var objImage = document.getElementById('lightboxImage');
	var objLoadingImage = document.getElementById('loadingImage');
	var objLightboxDetails = document.getElementById('lightboxDetails');

	
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();

	// center loadingImage if it exists
	if (objLoadingImage) {
		objLoadingImage.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - objLoadingImage.height) / 2) + 'px');
		objLoadingImage.style.left = (((arrayPageSize[0] - 20 - objLoadingImage.width) / 2) + 'px');
		objLoadingImage.style.display = 'block';
	}

	// set height of Overlay to take up whole page and show
	objOverlay.style.height = (arrayPageSize[1] + 'px');
	objOverlay.style.display = 'block';

	// preload image
	imgPreload = new Image();

	imgPreload.onload=function(){
		objImage.src = objLink.href;

		// center lightbox and make sure that the top and left values are not negative
		// and the image placed outside the viewport
		var lightboxTop = arrayPageScroll[1] + ((arrayPageSize[3] - 35 - imgPreload.height) / 2);
		var lightboxLeft = ((arrayPageSize[0] - 20 - imgPreload.width) / 2);
		
		objLightbox.style.top = (lightboxTop < 0) ? "0px" : lightboxTop + "px";
		objLightbox.style.left = (lightboxLeft < 0) ? "0px" : lightboxLeft + "px";


		objLightboxDetails.style.width = imgPreload.width + 'px';
		
		if(objLink.getAttribute('title')){
			objCaption.style.display = 'block';
			//objCaption.style.width = imgPreload.width + 'px';
			var arrayNum = objLink.getAttribute('title');
			var innerTitle = capTitle[arrayNum];
			var innerCap = capText[arrayNum];
			
			objCaption.innerHTML = "<div id='capBox'><h2>"+innerTitle +"</h2><p>"+innerCap+"</div>";
		} else {
			objCaption.style.display = 'none';
		}
		
		// A small pause between the image loading and displaying is required with IE,
		// this prevents the previous image displaying for a short burst causing flicker.
		if (navigator.appVersion.indexOf("MSIE")!=-1){
			pause(250);
		} 

		if (objLoadingImage) {	objLoadingImage.style.display = 'none'; }

		// Hide select boxes as they will 'peek' through the image in IE
		selects = document.getElementsByTagName("select");
        for (i = 0; i != selects.length; i++) {
                selects[i].style.visibility = "hidden";
        }

	
		objLightbox.style.display = 'block';

		// After image is loaded, update the overlay height as the new image might have
		// increased the overall page height.
		arrayPageSize = getPageSize();
		objOverlay.style.height = (arrayPageSize[1] + 'px');
		
		// Check for 'x' keypress
		listenKey();

		return false;
	}

	imgPreload.src = objLink.href;
	
}





//
// hideLightbox()
//
function hideLightbox()
{
	// get objects
	objOverlay = document.getElementById('overlay');
	objLightbox = document.getElementById('lightbox');

	// hide lightbox and overlay
	objOverlay.style.display = 'none';
	objLightbox.style.display = 'none';

	// make select boxes visible
	selects = document.getElementsByTagName("select");
    for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}

	// disable keypress listener
	document.onkeypress = '';
}




//
// initLightbox()
// Function runs on window load, going through link tags looking for rel="lightbox".
// These links receive onclick events that enable the lightbox display for their targets.
// The function also inserts html markup at the top of the page which will be used as a
// container for the overlay pattern and the inline image.
//
function initLightbox()
{
	
	if (!document.getElementsByTagName){ return; }
	var anchors = document.getElementsByTagName("a");

	// loop through all anchor tags
	for (var i=0; i<anchors.length; i++){
		var anchor = anchors[i];

		if (anchor.getAttribute("href") && (anchor.getAttribute("rel") == "lightbox")){
			anchor.onclick = function () {showLightbox(this); return false;}
		}
	}

	// the rest of this code inserts html at the top of the page that looks like this:
	//
	// <div id="overlay">
	//		<a href="#" onclick="hideLightbox(); return false;"><img id="loadingImage" /></a>
	//	</div>
	// <div id="lightbox">
	//		<a href="#" onclick="hideLightbox(); return false;" title="Click anywhere to close image">
	//			<img id="closeButton" />		
	//			<img id="lightboxImage" />
	//		</a>
	//		<div id="lightboxDetails">
	//			<div id="lightboxCaption"></div>
	//			<div id="keyboardMsg"></div>
	//		</div>
	// </div>
	
	var objBody = document.getElementsByTagName("body").item(0);
	
	// create overlay div and hardcode some functional styles (aesthetic styles are in CSS file)
	var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','overlay');
	objOverlay.onclick = function () {hideLightbox(); return false;}
	objOverlay.style.display = 'none';
	objOverlay.style.position = 'absolute';
	objOverlay.style.top = '0';
	objOverlay.style.left = '0';
	objOverlay.style.zIndex = '90';
 	objOverlay.style.width = '100%';
	objBody.insertBefore(objOverlay, objBody.firstChild);
	
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();

	// preload and create loader image
	var imgPreloader = new Image();
	
	// if loader image found, create link to hide lightbox and create loadingimage
	imgPreloader.onload=function(){

		var objLoadingImageLink = document.createElement("a");
		objLoadingImageLink.setAttribute('href','#');
		objLoadingImageLink.onclick = function () {hideLightbox(); return false;}
		objOverlay.appendChild(objLoadingImageLink);
		
		var objLoadingImage = document.createElement("img");
		objLoadingImage.src = loadingImage;
		objLoadingImage.setAttribute('id','loadingImage');
		objLoadingImage.style.position = 'absolute';
		objLoadingImage.style.zIndex = '150';
		objLoadingImageLink.appendChild(objLoadingImage);

		imgPreloader.onload=function(){};	//	clear onLoad, as IE will flip out w/animated gifs

		return false;
	}

	imgPreloader.src = loadingImage;

	// create lightbox div, same note about styles as above
	var objLightbox = document.createElement("div");
	objLightbox.setAttribute('id','lightbox');
	objLightbox.style.display = 'none';
	objLightbox.style.position = 'absolute';
	objLightbox.style.zIndex = '100';	
	objBody.insertBefore(objLightbox, objOverlay.nextSibling);
	
	// create link
	var objLink = document.createElement("a");
	objLink.setAttribute('href','#');
	objLink.setAttribute('title','Click to close');
	objLink.onclick = function () {hideLightbox(); return false;}
	objLightbox.appendChild(objLink);

	// preload and create close button image
	var imgPreloadCloseButton = new Image();

	// if close button image found, 
	imgPreloadCloseButton.onload=function(){

		var objCloseButton = document.createElement("img");
		objCloseButton.src = closeButton;
		objCloseButton.setAttribute('id','closeButton');
		objCloseButton.style.position = 'absolute';
		objCloseButton.style.zIndex = '200';
		objLink.appendChild(objCloseButton);

		return false;
	}

	imgPreloadCloseButton.src = closeButton;

	// create image
	var objImage = document.createElement("img");
	objImage.setAttribute('id','lightboxImage');
	objLink.appendChild(objImage);
	
	// create details div, a container for the caption and keyboard message
	var objLightboxDetails = document.createElement("div");
	objLightboxDetails.setAttribute('id','lightboxDetails');
	objLightbox.appendChild(objLightboxDetails);

	// create caption
	var objCaption = document.createElement("div");
	objCaption.setAttribute('id','lightboxCaption');
	objCaption.style.display = 'none';
	objLightboxDetails.appendChild(objCaption);

	// create keyboard message
	var objKeyboardMsg = document.createElement("div");
	objKeyboardMsg.setAttribute('id','keyboardMsg');
	objKeyboardMsg.innerHTML = '<a href="#" style="color:#000;" onclick="hideLightbox(); return false;">x close window</a> ';
	objLightboxDetails.appendChild(objKeyboardMsg);


}




//
// addLoadEvent()
// Adds event to window.onload without overwriting currently assigned onload functions.
// Function found at Simon Willison's weblog - http://simon.incutio.com/
//
function addLoadEvent(func)
{	
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
    	window.onload = func;
	} else {
		window.onload = function(){
		oldonload();
		func();
		}
	}

}



addLoadEvent(initLightbox);	// run initLightbox onLoad