window.addEvent('domready', function () {
	
	if($('coupon')){
		new PopUp('coupon', 'coupon_help');
	}
	
	scrollBar = new ScrollBar('scrollbar-wrapper', 'store-list',{
		hScroll: false,
		wheel: 20
	});
	
	var store_locator = {
		current_state: null,
		callout: $('state-callout'),
		stores: $$('#scrollbar-wrapper div')[0],
		state_selector: $('state-selector'),
		wrapper: $('scrollbar-wrapper'),
		initialize: function () {
			var that = this;
			that.state_selector.addEvent('change', function () {
				
				if (that.wrapper.getStyle('visibility') === 'hidden') {
					that.callout.setStyle('display', 'none');
					that.wrapper.setStyle('visibility', 'visible');
					that.wrapper.fade('hide');
					that.wrapper.fade('in');
				}
				
				if ($$('div.' + this.value).length != 0) {
					that.current_state = $$('div.' + this.value)[0];
					that.stores.scrollTo(0, that.current_state.getPosition(that.stores).y);
					scrollBar.update();
				}
			});
		}
	};
	
	store_locator.initialize();
	
});