
// we want to make sure that the hover state images don't need to load on the actual hover
var preload = [
    "/img/global/sitebar/link-hover-l.gif",
    "/img/global/sitebar/link-hover-r.gif",
    "/img/global/sitebar/dropdown-top.png",
    "/img/global/sitebar/dropdown-bottom.png",
    "/img/global/th3/subitem-bottom-border.gif"
];
setTimeout(function() {
    preload.each(function(img) {
        new Element('img', { 'src': (window.CRS) ? '/static'+img:img });
    });
}, 10);

document.observe('dom:loaded', function(e) {
    $$('ol#sitenav > li').each(function(el) {
        new Tablet.HoverElement(el, {hasActive:true, cssHover:true});
    });
    if ($('subnav')) {
        $$('ol#subnav li.hoverparent').each(function(el) {
            new Tablet.HoverElement(el);
        });
    }
    // this search thing is no longer here
    // var sitebar = $('sitebar');
    // if (sitebar) {
    //     var frm = sitebar.down('form.findlocation');
    //     if (frm) {
    //         var npt = frm.down('[name=ftl]');
    //         
    //         if (npt) {
    //             var sbmt = npt.next('input.hoverelement');
    //             if (sbmt) {
    //                 npt.observe('focus', function(e) {
    //                     sbmt.activate();
    //                 });
    //                 
    //                 npt.observe('blur', function(e) {
    //                     sbmt.deactivate();
    //                 });
    //             }
    //         }
    //     }
    // }
});

document.observe('dom:loaded', function(e) {
    new Tablet.Search.TextInput('finddestination', {
        url:'/javascript/LocationComplete',
        completer:'destinationcomplete',
        select:false
    });
});
var termsLayer;

Event.addBehavior({
  "#showlang:click" : function(e) {
    $('selectlang').className = ($('selectlang').className == 'current') ? '' : 'current';
    return false;
  },
  "#accountquestion input:click" : function(e) {
	  $('fromaccount').className = this.id;
  },
  "a.terms:click" : function(e){
	termsLayer.show();
	return false;
  }
});

Event.onReady(function() {
	$$('#accountquestion input').each(function(option) {
		if (option.checked) {
			$('fromaccount').className = option.id;
		}
	});
	termsLayer = new Tablet.Pane('tabletplusTerms');
});
