sfHover=function()
{var timeout=550;var cssClass="sfhover";var queue=[];var reCSS=new RegExp("\\b"+cssClass+"\\b");var sfEls=document.getElementById("nav").getElementsByTagName("li");for(var i=0;i<sfEls.length;i++){sfEls[i].onmouseover=function(){queueFlush();this.className+=" "+cssClass;}
sfEls[i].onmouseout=function(){queue.push([setTimeout(queueTimeout,timeout),this]);}
sfEls[i].onclick=function(){var e=window.event;if(this.className.search(reCSS)==-1){var elems=this.parentNode.getElementsByTagName("li");for(var i=0;i<elems.length;i++){elems[i].className=elems[i].className.replace(reCSS,"");}
this.className+=" "+cssClass;}else{var elems=this.getElementsByTagName("li");for(var i=0;i<elems.length;i++){elems[i].className=elems[i].className.replace(reCSS,"");}
this.className=this.className.replace(reCSS,"");}
if(e){e.cancelBubble=true;}else{e.stopPropagation();}}}
queueFlush=function(){while(queue.length){clearTimeout(queue[0][0]);queueTimeout();}}
queueTimeout=function(){if(queue.length){var el=queue.shift()[1];el.className=el.className.replace(reCSS,"");}}};


// @w	window reference
// @fn	function reference
function IEContentLoaded(w, fn) {
	var d = w.document, done = false,
	// only fire once
	init = function () {
		if (!done) {
			done = true;
			fn();
		}
	};
	// polling for no errors
	(function () {
		try {
			// throws errors until after ondocumentready
			d.documentElement.doScroll('left');
		} catch (e) {
			setTimeout(arguments.callee, 50);
			return;
		}
		// no errors, fire
		init();
	})();
	// trying to always fire before onload
	d.onreadystatechange = function() {
		if (d.readyState == 'complete') {
			d.onreadystatechange = null;
			init();
		}
	};
}

function News() {
	var self = this;
	var arrlen = 0;
	var newsarr = [];
	var target = $('news');
	var xhr = new XMLHttpRequest();
	xhr = (xhr) ? xhr : new ActiveXObject("Msxml2.XMLHTTP");
	var preloaderstring = "<br/><div class=\"cnt b f10\">Loading News...</div>";

	this.load = function() 
	{
		target.innerHTML = preloaderstring;
		xhr.open("GET", "/json/news.json?"+Math.random(), true);
		xhr.setRequestHeader("Content-Type", "application/json");
		xhr.onreadystatechange = function() 
		{
			if (xhr.readyState == 4 && xhr.status==200) 
			{
				response = xhr.responseText;
				text = eval("("+response+")");
				if (typeof text == "object") {
					newsarr = text.News;
					arrlen = newsarr.length;
					str = "";
					for(i=0; i < arrlen; i++) {
					   var item = newsarr[i];
					   var xurl = item.url;
					   var xtitle = item.title;
					   var xdate = item.date;
					   var xpopwin = item.popwin;
					   if (xpopwin) {
					   		xpopwin = " onclick=\"window.open(this.href); return false;\""
					   } else {
					   		xpopwin = "";
					   }
					   str += "<a href=\""+xurl+"\" "+xpopwin+"><b>"+xtitle+"</b><br/><span class=\"normal\">"+xdate+"</span></a><br/><br/>";
					}
					if (str != "") {
						target.innerHTML = str;
					}
					
				} else {
					target.innerHTML = "Error Parsing JSON";
				}
			} else {
				target.innerHTML = preloaderstring;
			}
		};
		xhr.send(null);
	}; //load

}


function Photos() {
	var self = this;
	var arrlen = 0;
	var interval = 5000;
	var firstimgflag = true;
	var photoarr = [];
	var photofiles = [];
	var preloaderstring = "<div style=\"width:590px; text-align:center;\"><div style=\"display:block; width:32px;  margin:0 auto;\"><br/><br/><br/><br/><br/><br/><br/><span style=\"font-size:14px\">Loading...</span><br/><br/><img class=\"imgcnt\" src=\"/vimages/ajaxloader.gif\" width=\"32\" height=\"32\" alt=\"\"  /></div></div>";
	var target = $('photos');
	var errbox = $('photoserrbox');
	var xhr = new XMLHttpRequest();
	var loadcheckInterval = null;

	this.load = function() 
	{
		target.innerHTML = preloaderstring;
		xhr.open("GET", "/json/photos.json?"+Math.random(), true);
		xhr.setRequestHeader("Content-Type", "application/json");
		xhr.onreadystatechange = function() 
		{
			if (xhr.readyState == 4 && xhr.status==200) 
			{
				response = xhr.responseText;
				text = eval("("+response+")");
				if (typeof text == "object") {
				
					photoarr = text.Photos;
					arrlen = photoarr.length;
					for(i=0; i < arrlen; i++) {
				       var img = photoarr[i];
					   var imgurl = photoarr[i].photourl;
				       img = new Image();
				       img.src = imgurl;
					   photofiles[i] = img;
					   photofiles[i].title = photoarr[i].title;
					   photofiles[i].desc = photoarr[i].description;
					   photofiles[i].url = photoarr[i].url;
					   photofiles[i].popwin = photoarr[i].popwin;
					   photofiles[i].style.position = "absolute";
					   //photofiles[i].style.opacity = 0;
					   //photofiles[i].style.filter = 'alpha(opacity=0)';
					   photofiles[i].style.display = 'none';
					   target.innerHTML = "";
				}
					self.play(Math.floor(Math.random()*arrlen));
				} else {
					target.innerHTML = "Error Parsing JSON";
				}
			} else {
				target.innerHTML = preloaderstring;
			}
		};
		xhr.send(null);
	}; //load
	
	this.next = function(i) {
		var int = i;
		setTimeout(function() {
			self.play(int+1);
		}, interval);
	}
	
	this.play = function(i) {

		//if ($('descdiv')) {
			//target.removeChild(descdiv);
		//}
		
		clearTimeout(loadcheckInterval);
		if (arrlen > 0) {
			if (i > arrlen-1) {
				i = 0;
			}
			var img = photofiles[i];
			var title = img.title;
			var url = img.url;
			var popwin = img.popwin;
			var titlestr = "";
			
			if (popwin) {
				popwin = "onclick=\"window.open(this.href); return false;\"";
			} else {
				popwin = "";
			}
			
			if (img.complete) 
			{
				if (firstimgflag) {
					//First Load
					img.style.display = 'block';
					target.appendChild(img);
					self.next(i);
				} else {
					//Recurring Loads
					img.style.opacity = 0;
					img.style.filter = 'alpha(opacity=0)';
					img.style.display = 'block';
					target.appendChild(img);
						var f = new tJS.fx.animate(img, "opacity", 1100, {start:0, end:100, easing:'easeOutQuad'}, 		function() {
					self.next(i);
					
					});
					delete f;
				}
				firstimgflag = false;
			} else {
				//quickly check for next ready image
				loadcheckInterval = setTimeout(function() { 
					self.play(i);
				}, 125);
			}

			
			
		} else {
			errbox = "No Photos Currently Available";
		}
	}
}

function loadJSON() {
	var pshow = new Photos();
	pshow.load();
	var news = new News();
	news.load();
}

//Onload
if (sec == "home") {
	if (document.addEventListener) {
		document.addEventListener("DOMContentLoaded", loadJSON, false);
	} else {
		//For IE DOMContentLoaded Emulation
		IEContentLoaded(window, loadJSON);
	}
}

function SetMenu(id)
{
	var obj = document.getElementById('nav'+id);
	if (obj)
	{
		obj.id = "nav"+id+"init";
		obj.onmouseout = null;
	}
}

function pageInit() {
	tJS.util.preloadImages("/vimages/btn_arrival_home_on.png","/vimages/btn_departure_home_on.png", "/vimages/btn_arrival_home.png","/vimages/btn_departure_home.png", "/vimages/btn_arrival_lt_on.png", "/vimages/btn_departure_lt_on.png", "/vimages/btn_arrival_lt.png", "/vimages/btn_departure_lt.png");
	//SetMenu(sec);
	sfHover();
}	

function validate(form) {
	var frm = form;
	if (frm)
	{

		if (frm.Email.value == "")
		{
			frm.Email.value = "";
			frm.Email.focus();
			alert("Email address is required");
			return false;
		}
		
		if (frm.Email.value != "" && ! /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(frm.Email.value)) 
		{
			alert("Email address is invalid");
			frm.Email.value = "";
			frm.Email.focus();
			return false;
		}
		
		if (frm.Category.value == "")
		{
			frm.Category.value = "";
			frm.Category.focus();
			alert("Category is required");
			return false;
		}
		if (frm.RouteInquiry.value == "")
		{
			frm.RouteInquiry.value = "";
			frm.RouteInquiry.focus();
			alert("Inquiry Type is required");
			return false;
		}
		if (frm.ResponseType.value == "")
		{
			frm.ResponseType.value = "";
			frm.ResponseType.focus();
			alert("Reply Type is required");
			return false;
		}
		if (frm.Comment.value == "")
		{
			frm.Comment.value = "";
			frm.Comment.focus();
			alert("Comment is required");
			return false;
		}
		if (frm.codeMatch.value == "")
		{
			frm.codeMatch.value = "";
			frm.codeMatch.focus();
			alert("Code Match is required");
			return false;
		}
		
		
	}
}

//Format Email Addresses
function FormatELink(name, domain, text)
{
	var strE = "<";
	strE += "a";
	strE += " href=";
	strE += "mail";
	strE += "to:";
	strE += name + "@" + domain + ">" + text + "</a>";
	document.write(strE);
}

//flash objects
function Fo(w,h,ver,path) {
		document.write("<object type=\"application/x-shockwave-flash\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version="+ver+",0,0,0\" width=\""+w+"\" height=\""+h+"\">");
		document.write("<param name=movie value=\"" + path + "\" />"); 
   		document.write("<param name=menu value=false />"); 
  		document.write("<param name=quality value=best />"); 
		document.write("<PARAM NAME=wmode VALUE=transparent />");
		document.write("<param name=scale value=exactfit />");
		document.write("<param name=salign value=LT />");
  		document.write("<embed src=\"" + path + "\" menu=false quality=best wmode=transparent bgcolor=#E9E1CC scale=exactfit salign=LT pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" width=\""+w+"\" height=\""+h+"\">"); 
   		document.write("</embed></object>"); 
};

window.onload = pageInit;
