var _sitenav= [
		{
		"n":"Home","u":"index.html","s":[
			{"n":"The Highway","u":"highway/about-407-etr.html","g":"images/sectionHighway.gif","s":[
				{"n":"About 407 ETR","u":"highway/about-407-etr.html","s":[
					{"n":"Corporate Information","u":"about/corporate-info.html"},
					{"n":"Background Information","u":"about/background-information.html"},
					{"n":"In the Community","u":"about/in-the-community.html"},			
					{"n":"Corporate Biographies","u":"about/corporate-biographies.html"},
					{"n":"Investors","u":"about/investors.html"},
					{"n":"Media","u":"about/media.html"},
					{"n":"Policies","u":"about/policies.html"},
					{"n":"Awards","u":"about/awards.html"},
					{"n":"Promotions/Offers","u":"about/promotions.html"},
					{"n":"Careers","u":"about/careers.html"},
					{"n":"Accessibility","u":"about/accessibility.html"},
				]},
				{"n":"Map","u":"highway/map.html"},
				{"n":"Construction","u":"highway/construction.html","s":[
					{"n":"Past Construction","u":"highway/past-construction.html"}
				] },
				{"n":"Closures","u":"highway/closures.html"},
				{"n":"Safety","u":"highway/safety.html"},
				{"n":"The Environment","u":"highway/environment.html"},
				{"n":"Roadside Assistance","u":"highway/roadside-assistance.html"},
				{"n":"Fleet Management","u":"highway/fleet-management.html","s":[
					{"n":"Plate Upload","u":"highway/fleet-plate-upload.html"}
				] },
				{"n":"Stories from the Road","u":"highway/stories.html"},
				{"n":"Newsletter","u":"newsletter/main.html"},
//				{"n":"Newsletter","u":"newsletter/newsletter.html"},
				{"n":"FAQ","u":"help/faq.html#highway"}
			] },
			{"n":"Tolls & Fees","u":"tolls/tolls-explained.html","g":"images/sectionTolls.gif","s":[
				{"n":"Tolls Explained","u":"tolls/tolls-explained.html"},
				{"n":"Rate Chart","u":"tolls/rate-chart-2012.html","s":[
					{"n":"Light Vehicle","u":"tolls/rate-chart-2012.html"},
					{"n":"Heavy Single Unit Vehicle","u":"tolls/rate-chart-heavy-2012.html"},
					{"n":"Heavy Multiple Unit Vehicle","u":"tolls/rate-chart-multi-2012.html"},
					{"n":"Complete Fee Details","u":"tolls/rate-chart-complete-2012.html"}
				] },
				{"n":"Toll Calculator","u":"highway/map.html"},
				{"n":"Out-Of-Province","u":"tolls/out-of-province.html"},
				{"n":"ETR Rewards Program","u":"tolls/etr-rewards.html","s":[
					{"n":"Gas Savings Card","u":"tolls/gas-savings-card.html"}
				] },
				{"n":"Heavy Vehicle Savings Program","u":"tolls/heavy-vehicle-savings.html"},
				{"n":"FAQ","u":"help/faq.html#tolls"}
			] },
			{"n":"Transponders","u":"transponders/what-is-a-transponder.html","g":"images/sectionTransponders.gif","s":[
				{"n":"What is a Transponder","u":"transponders/what-is-a-transponder.html"},
				{"n":"Order a Transponder","u":"transponders/order-a-transponder.html"},
				//{"n":"Get Fasteners","u":"transponders/get-fasteners.html"},
				{"n":"Mounting Instructions","u":"transponders/mounting-instructions.html"},
				{"n":"FAQ","u":"help/faq.html#transponders"}
			] },
			{"n":"Payments","u":"payments/payment-options.html","g":"images/sectionPayments.gif","s":[
				{"n":"Payment Options","u":"payments/payment-options.html","s":[
					{"n":"Anonymous Account","u":"payments/anonymous-account.html"}
				] },
				{"n":"Pay your Bill","u":"payments/pay-your-bill.html"},
				{"n":"One Simple Bill","u":"payments/one-simple-bill.html"},
				//{"n":"Gift Cards","u":"payments/gift-cards.html","s":[
				//	{"n":"Order Gift Card","u":"payments/order-gift-card.html"},
				//	{"n":"Check Gift Card Balance","u":"payments/check-gift-card-balance.html"}
				//] },
				{"n":"Dispute Resolution","u":"payments/dispute-resolution.html","s":[
					{"n":"Exceptional Hardship Plan","u":"payments/exceptional-hardship.html"},
					{"n":"Ombudsman Annual Reports","u":"payments/ombudsman-annual-reports.html"},
					{"n":"Ombudsman Contact Form","u":"Documents/Ombudsman_Contact_Form.pdf"}
				] },
				{"n":"Collections","u":"payments/collections.html","s":[
					{"n":"Plate Denial","u":"payments/plate-denial.html"}
				] },
				{"n":"FAQ","u":"help/faq.html#payments"}
			] },
      {"n":"My Account","u":"myaccount/Overview.jsf","g":"images/sectionMyAccount.png","s":[
        {"n":"Login","u":"myaccount/Overview.jsf","h":1},
				{"n":"Forgot Password","u":"myaccount/ForgotPassword.jsf","h":1},
				{"n":"Create Web Account","u":"myaccount/SignUpEnterAccount.jsf","h":1},
				{"n":"FAQ","u":"help/faq.html#your407ETRAccount","h":1}
			] },
			{"n":"Help","u":"help/faq.html","g":"images/sectionHelp.gif","h":1,"s":[
				{"n":"Search","u":"help/search.html"},
				{"n":"FAQ","u":"help/faq.html"},
				{"n":"Contact Us","u":"myaccount/ContactUs.jsf","h":1},
				{"n":"Sitemap","u":"help/sitemap.html"}
			] },
			{"n":"About","u":"about/corporate-info.html","g":"images/sectionAbout.gif","h":1,"s":[
				{"n":"Corporate Information","u":"about/corporate-info.html"},
				{"n":"Background Information","u":"about/background-information.html","s":[
					{"n":"History","u":"about/background-information1.html","h":2},
					{"n":"Facts and Stats","u":"about/background-information2.html","h":2},
					{"n":"Technology and Innovation","u":"background-information3.html","h":2},
					{"n":"Customer Service","u":"about/background-information4.html","h":2},
					{"n":"Customer Accounts","u":"about/background-information5.html","h":2},
					{"n":"In the Community","u":"about/background-information6.html","h":2},
					{"n":"Safety and Maintenance","u":"about/background-information7.html","h":2},
					{"n":"Extension and Expansion","u":"about/background-information8.html","h":2},
					{"n":"Ongoing Investments","u":"about/background-information9.html","h":2}
				] },
				{"n":"In the Community","u":"about/in-the-community.html","s":[
					{"n":"SickKids Foundation","u":"about/in-the-community1.html","h":2},
					{"n":"SickKids Radiothon","u":"about/in-the-community2.html","h":2},
					{"n":"United Way of York Region","u":"about/in-the-community3.html","h":2},
					{"n":"York University","u":"about/in-the-community4.html","h":2},
					{"n":"The James Fund","u":"about/in-the-community5.html","h":2},
					{"n":"Rogers Cup","u":"about/in-the-community6.html","h":2},
					{"n":"Adopt a School Program","u":"about/in-the-community7.html","h":2},
					{"n":"Abilities Centre","u":"about/in-the-community8.html","h":2},
					{"n":"Vaughan Minor Sports","u":"about/in-the-community9.html","h":2},
					{"n":"The George Hull Centre","u":"about/in-the-community10.html","h":2},
					{"n":"Special Opportunities","u":"about/in-the-community11.html","h":2},
					{"n":"St. John Ambulance","u":"about/in-the-community12.html","h":2}
				] },
				{"n":"Corporate Biographies","u":"about/corporate-biographies.html","s":[
					{"n":"Jose Tamariz","u":"about/corporate-biographies1.html","h":2},
					{"n":"Louis-M. St-Maurice","u":"about/corporate-biographies2.html","h":2},
					{"n":"Mike Miller","u":"about/corporate-biographies3.html","h":2},
					{"n":"Brian Fernandes","u":"about/corporate-biographies4.html","h":2},
					{"n":"Greg MacKenzie","u":"about/corporate-biographies5.html","h":2},
					{"n":"Paul Ruttan","u":"about/corporate-biographies6.html","h":2},
					{"n":"Randy Luyk","u":"about/corporate-biographies7.html","h":2},
					{"n":"Robert Ives","u":"about/corporate-biographies8.html","h":2},
					{"n":"Wayne Anthony","u":"about/corporate-biographies9.html","h":2},
					{"n":"Kevin Sack","u":"about/corporate-biographies10.html","h":2},
					{"n":"Jim Horton","u":"about/corporate-biographies11.html","h":2},
					{"n":"Craig White","u":"about/corporate-biographies12.html","h":2}
				] },
				{"n":"Investors","u":"about/investors.html","s":[
					{"n":"Sales Agreements","u":"about/sales-agreement.html"},
					{"n":"Usage Statistics","u":"about/usage-statistics.html"},
					{"n":"Public Presentations","u":"about/public-presentations.html"}
				] },
				{"n":"Media","u":"about/media.html","s":[
					{"n":"News Releases","u":"about/news.html","s":[
//						{"n":"News Releases","u":"about/news.html","h":2},
					]},														 
					{"n":"Archived Releases","u":"about/news-older.html","s":[
					
//						{"n":"News Releases","u":"about/news-","h":2},																					
					]},
					{"n":"Fast Facts","u":"about/fast-facts.html"}
				] },
					{"n":
						"Newsletter","u":"newsletter/newsletter.html","s":[
					{"n":"ETR REWARDS","u":"newsletter/article1.html","h":2},
					{"n":"MESSAGE FROM THE PRESIDENT","u":"newsletter/article2.html","h":2},
					{"n":"ETR Sponsorships","u":"newsletter/article3.html","h":2},
					{"n":"OPP Corner","u":"newsletter/article4.html","h":2},
					{"n":"In the Community","u":"newsletter/article5.html","h":2},
					{"n":"Customer Service","u":"newsletter/article6.html","h":2},
					{"n":"Pre-Authorized Payment Offer/Online Services","u":"newsletter/article7.html","h":2}
				] },
				{"n":"Policies","u":"about/policies.html","s":[
					{"n":"Privacy Policy","u":"about/privacy-policy.html"},
					{"n":"Code of Conduct","u":"Documents/Code_of_Conduct.pdf"},
					{"n":"Environment","u":"Documents/Environmental_Policy.pdf"}
				] },
				{"n":"Awards","u":"about/awards.html"},
				{"n":"Careers","u":"about/careers.html"}
			] }
		] }
];
var _sitefooter = [
	{"n":"Home","u":"index.html"},
	{"n":"About","u":"about/corporate-info.html"},
	{"n":"407&nbsp;ETR Map","u":"highway/map.html"},
	{"n":"Investors","u":"about/investors.html"},
	{"n":"Media","u":"about/media.html"},
	{"n":"FAQ","u":"help/faq.html"},
	{"n":"Privacy Policy","u":"about/privacy-policy.html"},
	{"n":"Sitemap","u":"help/sitemap.html"}
];
var _sitecopy = "&copy; 2010, 407 ETR.  All rights reserved.";
//var _siteback = [ "images/background_image1_03.jpg", "images/background_image3_03.jpg" ];
var _siteback = [ "images/background_image1_03.jpg" ];


// ------------ DO NOT EDIT BELOW THIS LINE ---------------
var _site = {};

// Private
_site._breadcrumb = "";
_site._alert = "";
_site._topnav = "";
_site._leftnav = "";
_site._search = "";
_site._footnav = "";
_site._loginnav = "";
_site._logednav = "";
_site._homenav = "";
_site._backimg = "";

_site.addTNavNode = function(o,b,l,r) {	//object, breadcrumb, level, link-pre-append
	var c = "";
	var c2 = "";
	var t = "";
	var m = false;

	// Top Nav
	t = "<li>";
	if( _site.checkMatch(o.u) ) {
		m = true;
		c += " navSelected";
		c2 += " active";

		//Breadcrumb
		_site._breadcrumb = b+o.n;
	}
	if( o.h==2 ) c2 += " navHide";		// Hide from both
	if( o.h==1 ) c2 += " navHide1";		// Hide from top only
	t = '<li class="'+c2+'"><a class="'+c+'" href="'+r+o.u+'"'+'>'+o.n+'</a>';

	var ch = "";
	//Next Level
	if( o.s !== undefined ) {
		for( var i in o.s ) {
			ch += _site.addTNavNode( o.s[i], b+'<a href="'+r+o.u+'">'+o.n+'</a> > ', l+1, r );
		}
		if( ch.indexOf("navSelected") > 0) {
			t+='<ul class="navOpen">'; m = true;
			if( l==1 ) t = t.replace(/a class=\"/, 'a class="navSelected ');
		} else if( m ) t+='<ul class="navOpen">';
		else t+= '<ul class="navClose">';
		t+=ch+'</ul>';
	}
	t+='</li>';

	// Left Menu
	if( l==1 && m && o.h!=2 ) {
		_site._leftnav = '<img src="'+r+(o.g!==undefined?o.g:'images/sectionHighway.gif')+'" />'+
					'<ul class="contentNav">'+
						'<li class="sectionTitle">'+o.n+'</li>'+
						ch.replace(/navSelected/g,"").replace(/navHide1/g,"")+
					'</ul>';
	}

	return ( l==1 ? t.replace(/navHide1/g, "navHide") : t );
}

function getHostname(str) {
	var re = new RegExp('^(?:f|ht)tp(?:s)?\://([^/]+)', 'im');
	return str.match(re)[1].toString();
}

_site.checkMatch = function(str) {
	return ( ( typeof(_page_override)!="undefined" ? _page_override:window.location.pathname ).lastIndexOf(str) >= 0 );
}

//Get cookie routine by Shelley Powers
_site.get_cookie = function(Name) {
  var search = Name + "="
  var returnvalue = "";
  if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    // if cookie exists
    if (offset != -1) {
      offset += search.length
      // set index of beginning of value
      end = document.cookie.indexOf(";", offset);
      // set index of end of cookie value
      if (end == -1) end = document.cookie.length;
      returnvalue=unescape(document.cookie.substring(offset, end))
      }
   }
  return returnvalue;
}

_site.buildNavElements = function() {

	var hostname= getHostname(location.href);
	//var r = ( _site.checkMatch("index.html") ? "":"../" );
	//var r1 = ( _site.checkMatch("Login.jsf") ? "":"../" );
	var r ="http://"+hostname+"/";

	var r1 = "https://"+hostname+"/myaccount/resources/";
	// Background
	var protocol = window.location.href.substring(5,0).toLowerCase();

	var isSecure = (protocol == "https");
	//alert(isSecure);
	var siteback_index = parseInt(_site.get_cookie("_siteback"));
	if( _site.get_cookie("_siteback") == "" ) {
		siteback_index = Math.floor( Math.random()*_siteback.length );
		document.cookie = "_siteback="+siteback_index;
	}
	if( siteback_index >= _siteback.length ) siteback_index = 1;
	if(isSecure) {
		_site._backimg = '<img src="'+r1+'images/background_image1_03.jpg" border="0" />';
	} else {
		_site._backimg = '<img src="'+r+'images/background_image1_03.jpg" border="0" />';
	}
	//if(isSecure) {
	//	_site._backimg = '<img src="'+r1+_siteback[siteback_index]+'" border="0" />';
	//} else {
	//	_site._backimg = '<img src="'+r+_siteback[siteback_index]+'" border="0" />';
	//}


	// Search menu
	_site._search =	'<a href="'+r+'myaccount/ContactUs.jsf">Contact Us</a>'+
					'<form action="'+r+'help/search.html" method="get" name="frmSearch">'+
						'<input type="textbox" size=18 name="search" value="" class="searchBox" />&nbsp;'+
						'<a href="#" onclick="document.frmSearch.submit();"><img src="';
						if(isSecure){
							_site._search+=r1;
						} else {
							_site._search+=r;
						}
						_site._search+='images/nav-search-btn.png" width=22 height=22 border=0 alt="GO"></a>'+
					'</form>';

	_site._topnav = '';
	for( var i in _sitenav[0].s )
		_site._topnav += _site.addTNavNode( _sitenav[0].s[i], '<a href="'+r+_sitenav[0].u+'">'+_sitenav[0].n+'</a> > ',1,r );
	_site._topnav = '<ul class="mlddn">'+_site._topnav+'</ul>';

	// Footer links
	_site._footnav = '<div class="footerLinks">';
	for( var j in _sitefooter )
		_site._footnav += '<a href="'+r+_sitefooter[j].u+'"'+(j==_sitefooter.length-1?' class="last"':'')+'>'+_sitefooter[j].n+'</a>';
	_site._footnav += 	'<br /><p>'+_sitecopy+'</p>' +
				'</div>' +
				'<div class="footerSponserImage" style="position:absolutee;left:-40px;">' +
					'<a href="'+r+'about/in-the-community.html">'+'<img src="';
					if(isSecure){
							_site._footnav +=r1;
						} else {
							_site._footnav +=r;
						}
				_site._footnav +=		'images/sponsors.png" alt="United Way, Sick Kids Foundation, York University" width="101" height="24" border="0" align="middle" />' +
					'</a>' +
				'<div class="footerSponserImage" style="position:absolute;right:-70px;top:-5px;">'+'<a href="'+r+'about/accessibility.html">'+'<img src="';
					if(isSecure){
							_site._footnav +=r1;
						} else {
							_site._footnav +=r;
						}
				_site._footnav +=	'images/icon-TM-nb.png" alt="accessibility" width="67" height="31" border="0" align="middle" />' +
					'</a>' +
				'</div>' +
				'<div class="footerSponsorText"style="position:absolute;right:140px;top:0px;">Proud&nbsp;supporter&nbsp;of&nbsp;</div>';

    // Add print button
    _site._alert = '<a href="javascript:window.print();" class="btnPrint">Print</a>';

	// Login
	_site._loginnav = '<div class="loginContent"></div>'+
				'<div class="loginLinks">' +
					'<a href="'+r1+'../SignUpEnterAccount.jsf">Create a <b>FREE</b> web account</a>' +
					'| <a href="'+r1+'../Login.jsf">Login</a>'+
				'</div>';

	// THIS CODE TO BE REPLACED WITH COOKIE RETRIEVAL CODE AND LINK TO SIGNOUT
	_site._logednav = '<div class="loginContent">'+
					'Welcome John Smith Super Long Name'+
				'</div>'+
				'<div class="loginLinks">'+
					'| <a href="'+r+'myaccount/Login.jsf">Sign Out</a>'+
				'</div>';

	if(isSecure) {
		_site._homenav = '<a href="'+r+_sitenav[0].u+'"><img src="'+r1+'images/nav-logo-small.png" border="0" width="82" height="17" alt="407 ETR" /></a>';

	} else {
		_site._homenav = '<a href="'+r+_sitenav[0].u+'"><img src="'+r+'images/nav-logo-small.png" border="0" width="82" height="17" alt="407 ETR" /></a>';

	}
}

_site.buildNavElements();

_site.back = function() { document.write( _site._backimg ); }
_site.navAlert = function() { document.write( _site._alert ); }
_site.navSearch = function() { document.write( _site._search ); }

_site.navLogin = function(auth) {
  document.write("<span id='spanLoginInfoId'></span>");
  //document.write( ( auth==1?_site._logednav:_site._loginnav) );
} // Tweak once we add cookie code


_site.navContent = function() { document.write( _site._leftnav ); }
_site.navHead = function() { document.write( _site._topnav ); }
_site.navLogo = function() { document.write( _site._homenav ); }
_site.navFoot = function() { document.write( _site._footnav ); }
_site.navBreadcrumb = function() { document.write( _site._breadcrumb ); }
_site._loginInfo = new LoginInfo();
_site.getLoginInfo = function() { return this._loginInfo; }

function LoginInfo()
{
    // Constants
  this.hostname = getHostname(location.href);
  this.IS_TEST = location.href.indexOf("localhost") != -1;
  this.TIMEOUT_REFRESH_LOGIN_INFO = this.IS_TEST ? 3: 10; // in seconds
  this.TIMEOUT_CHECK_RESPONSE = 1; // in seconds
  this.URL_GET_LOGIN_INFO = "GetLoginInfo3.jsp";
  this.LOGIN_NONE = "none";

    // Data
  this._prefURL = this.IS_TEST ?
    "http://localhost:8080/onlineservices/" :
    "/myaccount/";

    // Getters
  this.getPrefURL =  function() { return this._prefURL; };

    // Functions
  this.getLoginInfoScript         = li_getLoginInfoScript;
  this.checkResponse              = li_checkResponse;
}

function li_getLoginInfoScript()
{
  var SCRIPT_ID_GET_LOGIN_INFO = "scriptGetLoginInfo";
  var elHead = $("head")[0];
  var elScriptOld = $("#"+SCRIPT_ID_GET_LOGIN_INFO)[0];
  if(elScriptOld) elHead.removeChild(elScriptOld);
  var elScript = document.createElement("script");
  elScript.setAttribute("type","text/javascript");
  elScript.setAttribute("src",this.getPrefURL() + this.URL_GET_LOGIN_INFO + "?"+new Date().getTime());
  elScript.setAttribute("id",SCRIPT_ID_GET_LOGIN_INFO);
  elHead.appendChild(elScript);
  setTimeout("_site.getLoginInfo().getLoginInfoScript()",this.TIMEOUT_REFRESH_LOGIN_INFO*1000);
}

function li_checkResponse()
{
  var el = $("#spanLoginInfoId")[0];
  if(el.innerHTML == "") saveLoginInfo(this.LOGIN_NONE);
}

function saveLoginInfo(eMail) {
  var li = _site.getLoginInfo();
  var el = $("#spanLoginInfoId")[0];
  var res;
  if(eMail.indexOf(li.LOGIN_NONE) != -1) {
    res =
      "<div class='loginContent'></div>"+
      "<div class='loginLinks'>" +
      "<a href='"+li.getPrefURL()+"SignUpEnterAccount.jsf'>Create a <b>FREE</b> web account</a>" +
      "| <a href='"+li.getPrefURL()+"myaccount/Overview.jsf'>Login</a>"+
      "</div>";

  }
  else {
    res  = "<div class='loginContent'>"+
      eMail +
      "</div>"+
      "<div class='loginLinks'>"+
        "| <a href='"+li.getPrefURL()+"Login.jsf'>Sign Out</a>"+
      "</div>";
  }
  el.innerHTML = res;
}

$(document).ready(function() {
    $("ul.mlddn li").hover( function() {
    	var ob = this;
        $(ob).addClass("hover");
    	ob.hoverDelay = setTimeout( function() { $('ul:first',ob).fadeIn('fast'); if( $(ob).hasClass("mlddnExpand") ) $(ob).addClass("mlddnCollapse"); } , 100 );
    	return;
    }, function() {
    	var ob = this;
    	ob.hoverDelay = clearTimeout(ob.hoverDelay);
        $(ob).removeClass("hover");
    	if( !$(this).parent().hasClass('mlddn') ) return;	// remove to enable collapse
        $(ob).removeClass("mlddnCollapse");
        $('li',ob).removeClass("mlddnCollapse");
        $('ul:first',ob).fadeOut('fast');
        $('ul',ob).fadeOut('fast');		// remove to enable collapse
    });
    $("ul.mlddn li ul li:has(ul)").addClass("mlddnExpand");

    var li = _site.getLoginInfo();
    li.getLoginInfoScript();
    setTimeout("_site.getLoginInfo().checkResponse()",li.TIMEOUT_CHECK_RESPONSE*1000);

});
