// JavaScript Document

window.onload = function() {
	promoImages();
	clearSignup();
	assignYAH();

	
}

/* -- checker function - checks to see if variables in each function exist -- */

function checkVars(e) {
	var x = e.split(",");
	var pass = true;
	checkerInvalid = new Array;

	for(i=0; i<x.length; i++) {
		
		if(!eval(x[i])) {
		pass = false; 
		checkerInvalid[checkerInvalid.length] = x[i];
		}
		
	}
	
	return pass;

}

/* -- displays a random image and caption on pages promo01.php, promo02.php, promo03.php, promo04.php, promo05.php and promo06.php --*/

function promoImages () {
	
	if(!checkVars('document.getElementById("promo-image"), document.getElementById("promo-caption")')) {
		return;
	}	
	
	
	var promo_array = new Array();
	promo_array[0] = (["http://strasburgrailroad.com/img/random-images/rnd_Train-Station-Night.jpg", "Step back in time as you enter our East Strasburg station, circa 1915."]);
	promo_array[1] = (["http://strasburgrailroad.com/img/random-images/rnd_RR-Museum_1.jpg", "Another world-class collection is just across the street at The Railroad Museum of PA."]);
	promo_array[2] = (["http://strasburgrailroad.com/img/random-images/rnd_Boy-holding-ears.jpg", "The joy on their faces will make you want to return again and again."]);
	promo_array[3] = (["http://strasburgrailroad.com/img/random-images/rnd_SRR_Santa_Express_Car_1.jpg", "Special events throughout the year offer even more ways to enjoy the Strasburg Rail Road."]);
	promo_array[4] = (["http://strasburgrailroad.com/img/random-images/rnd_First-Class.jpg", "Accommodations range from the classic Coach to First Class fares."]);
	promo_array[5] = (["http://strasburgrailroad.com/img/random-images/rnd_SRR_Engineers_1824.jpg", "There are no actors here. No scripts. Just authentic railroaders, with great stories to tell."]);
	promo_array[6] = (["http://strasburgrailroad.com/img/random-images/rnd_pump-car.jpg", "Operate the hand-powered Pump Car for real hands-on fun!"]);
	promo_array[7] = (["http://strasburgrailroad.com/img/random-images/rnd_SRR_Engine475-in-spring.jpg", "Engine 475 rolls along on a beautiful Spring day."]);
	promo_array[8] = (["http://strasburgrailroad.com/img/random-images/rnd_Train_90_JTower.jpg", "Authentic structures such as this switch tower, offer visitors a genuine railroad experience."]);
	promo_array[9] = (["http://strasburgrailroad.com/img/random-images/rnd_Dining-Car-v01.jpg", "Enjoy the ride as you eat on board one of our dining cars."]);
	promo_array[10] = (["http://strasburgrailroad.com/img/random-images/rnd_cagney.jpg", "Fun extras along the mall at our East Strasburg station include this Cagney Miniature Train."]);
	promo_array[11] = (["http://strasburgrailroad.com/img/random-images/rnd_Dad-Kids_Train.jpg", "Every generation finds something special about their visit to Strasburg Rail Road."]);
	promo_array[12] = (["http://strasburgrailroad.com/img/random-images/rnd_StarsburgRRImage6.jpg", "Every season is a great season to ride the Strasburg Rail Road."]);
	promo_array[13] = (["http://strasburgrailroad.com/img/random-images/rnd_mother_son_train.jpg", "Enjoy all we have to offer – and the memories you’ll take with you."]);
	promo_array[14] = (["http://strasburgrailroad.com/img/random-images/rnd_Train_90_04.jpg", "Experience the peaceful countryside of PA Dutch Country from our unique vantage point."]);
	promo_array[15] = (["http://strasburgrailroad.com/img/random-images/rnd_East-Strasburg-Station.jpg", "Harvest time arrives at our East Strasburg station."]);
	promo_array[16] = (["http://strasburgrailroad.com/img/random-images/rnd_engineer-and-mom-and-sons.jpg", "Explore engines and rail cars up close."]);
	promo_array[17] = (["http://strasburgrailroad.com/img/random-images/rnd_Thomas_03_300.jpg", "A Very Useful Engine™ has been known to pull our trains from time to time."]);
	
	var num_to_show = 1
	var image_div = document.getElementById("promo-image");
	var caption_div = document.getElementById("promo-caption");
	var image_begin = '<img src="';
	var image_end = '" class="promo-random-image" alt="">';
	
	for(i=0; i<num_to_show; i++) {
			var max = promo_array.length;
			var num = Math.floor((Math.random() * max));
			
			image_div.innerHTML = image_begin + promo_array[num][0] + image_end;
			caption_div.innerHTML = promo_array[num][1];
			
			
	}	
}


function clearSignup() {


	var email_input = document.getElementById("email");
	
	if(!checkVars('document.getElementById("email")')) {
		return;
	}	
	
	email_input.onfocus = function() {
		email_input.value = "";
	}
	
}
	
	
function assignYAH() {
	
	if(!checkVars('document.getElementById("left"), document.getElementsByTagName("li")')) {
		return;
	}	
	
	var navArray = document.getElementById("left").getElementsByTagName("li");
	if(typeof(pageName)!="undefined") {
		for(var i=0;i<navArray.length;i++) {
			var linkName = navArray[i].getElementsByTagName("a")[0].name;
			if(pageName == linkName) {
				navArray[i].className = "left-active";
				break;
			}
		}
	}
}

function open_window(url) {
mywin = window.open(url,"win",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes,width=425,height=425,left=400,top=300');
	self.setTimeout("mywin.focus()",1000);
}
