window.addEvent('domready', function() {

	if ( $defined( $('calendar1') ) ) {
		new vlaDatePicker('calendar1', { style: 'adobe_cs3', format: 'y/m/d', separator: '-', ieTransitionColor: '', prefillDate: 'false' }); 
	}
	if ( $defined( $('calendar2') ) ) {
		new vlaDatePicker('calendar2', { style: 'adobe_cs3', format: 'y/m/d', separator: '-', ieTransitionColor: '', prefillDate: 'false' }); 
	}


	var pageScroll = new Fx.Scroll( $('pagebody'), {
		duration: 500
	});

	
	var faq_anchor_index;
	$$('ul.tips li a').each( function(trigger, index) {
		trigger.addEvent('click', function(e){
			e.stop();
			
			tip_index = index + 1;
			pageScroll.toElement('tip' + tip_index);
		});
	});


	$$('a.scrollto').each( function(trigger, index) {
		trigger.addEvent('click', function(e){
			e.stop();
			
			tip_index = index + 1;
			pageScroll.toElement('scrollto' + tip_index);
		});
	});


	$$('.backtotop').addEvent('click', function(e){
		e.stop();
		pageScroll.toTop();
	});


	var panelNavCookie = Cookie.read('panel-nav');
	if ( !$defined(panelNavCookie) ) {
		Cookie.write('panel-nav', 'panel-storage-quotes', {path: '/'});
	}
	
	
	if ( $('panel-triggers') ) {

		var nS4 = new noobSlide({
			box: $('panel-wrapper'),
			items: $$('#panel-wrapper div.panel'),
			size: 465,
			handles: $$('#panel-triggers span'),
			onWalk: function(currentItem,currentHandle){
				if ( currentItem.get('id') == 'panel-storage-quotes' ) {
					Cookie.write('panel-nav', 'panel-storage-quotes', {path: '/'});
					$('header-photo').removeClass('search');
					$('header-photo').addClass('quote');
				} else
				if ( currentItem.get('id') == 'panel-storage-search' ) {
					Cookie.write('panel-nav', 'panel-storage-search', {path: '/'});
					$('header-photo').removeClass('quote');
					$('header-photo').addClass('search');
				}
				
				this.handles.removeClass('active');
				currentHandle.addClass('active');
			}
		});
		
		if ( panelNavCookie == 'panel-storage-search' ) {
			nS4.walk(1, true, true);
		}
	
	}


	if ( $('map-locations') ) {
		$$('#map-locations a.btn-favorites').addEvents({
			'click' : function(e) {
				pageScroll.toTop();
				if ( !this.getParent('div').getParent('div').hasClass('active') ) {
					this.getParent('div').getParent('div').addClass('active');
				}
			}
		});
	}


	if ( $('testimonials-panel-wrapper') ) {
		//SAMPLE 1 (auto, every 5 sec)
		var nS1 = new noobSlide({
			box: $('testimonials-panel-wrapper'),
			items: [0,1,2],
			size: 222,
			interval: 10000,
			autoPlay: true
		});
	}


	var submenu_panels = $$('.state-locations-panel');
	var submenu_triggers = $$('.state-locations-trigger');
	var stateLocationsSlideFx = new Array();
	
	submenu_panels.each(function(thisExpandable, i) {
		var newFX = new Fx.Slide(thisExpandable, {
			duration: 200,
			'onComplete':
				function(thisExpandable) {
					var hidden = thisExpandable.getParent().getStyle('height') == '0px' ? true : false;
					thisExpandable.getParent().setStyle('height','');
					if(window.ie6 && hidden) thisExpandable.getParent().setStyle('height','0px');
				}
		}).hide();
		
		stateLocationsSlideFx[i] = newFX;
	});


	submenu_triggers.each(function(thisTrigger, i) {
		thisTrigger.addEvent('click', function(e) {
			e.stop();
	
			if ( thisTrigger.hasClass('active') ) {
				thisTrigger.removeClass('active');
			} else {
				thisTrigger.addClass('active');
			}
			
			stateLocationsSlideFx[i].toggle();
		});
	});


	// attach a click event to each premier company ad placement that uses the URL attached to the logo
	$$('.premier-company').each(function(el, i) {
		el.addEvent('click', function(e) {
			e.stop();
			window.location.href = el.getChildren('a').get('href');
		});
	});


	$$('table.form tr').each(function(el,i){
		classname = ( i % 2 ) ? 'odd' : 'even';
		if ( !el.hasClass('buttons') ) {
			el.addClass( classname );
		}
	});


	$$('table.resultset tr').each(function(el,i){
		classname = ( i % 2 ) ? 'odd' : 'even';
		if ( !el.hasClass('buttons') && !el.hasClass('blank') && !el.getParent('table').hasClass('no-highlight') ) {
			el.addClass( classname );
		}
		
		if ( !el.hasClass('blank') && !el.getParent('table').hasClass('no-highlight') && !el.getParent('table').hasClass('no-hover') ) {
			el.addEvent('mouseenter', function(e){
				el.addClass('hover');
			});
			el.addEvent('mouseleave', function(e){
				el.removeClass('hover');
			});
		}
	});


});