if (!window.LFI)
	var LFI = new Object();
	
// EaseFromTo (adapted from "Quart.EaseInOut")
Effect.Transitions.EaseFromTo = function(pos) {
if ((pos/=0.5) < 1) return 0.5*Math.pow(pos,4);
return -0.5 * ((pos-=2)*Math.pow(pos,3) - 2);
};

var imgT = new Template('<img src="#{src}" id="main-image"/>');
var imgD = [
	'http://content.lacrosseeurope.eu.s3.amazonaws.com/images/2010/shots/Hike-1.jpg',
	// 'http://content.lacrosseeurope.eu.s3.amazonaws.com/images/2010/shots/Hike-2.jpg',
	'http://content.lacrosseeurope.eu.s3.amazonaws.com/images/2010/shots/Horse-1.jpg',
	'http://content.lacrosseeurope.eu.s3.amazonaws.com/images/2010/shots/Hunt-1.jpg',
	'http://content.lacrosseeurope.eu.s3.amazonaws.com/images/2010/shots/Hunt-2.jpg'
	// 'http://content.lacrosseeurope.eu.s3.amazonaws.com/images/2010/shots/IceFish-1.jpg',
	// 'http://content.lacrosseeurope.eu.s3.amazonaws.com/images/2010/shots/Shop-1.jpg'
];

document.observe('dom:loaded', function(){
	var e = {};
	$$('#links a').each(function(el){
		el.observe('mouseover', function(){
			if (e[el.identify()]) e[el.identify()].cancel();
			e[el.identify()] = new Effect.Morph(this, {
				style: { color: '#999' },
				duration: 0.5
			});
		}).observe('mouseout', function(){
			if (e[el.identify()]) e[el.identify()].cancel();
			e[el.identify()] = new Effect.Morph(this, {
				style: { color: '#bababa' },
				duration: 0.5
			});
		});
		
	});
	
	// if ($$('object').length && $('shade')) {
	// 	Effect.Fade('shade', {
	// 		delay: 1.5,
	// 		duration: 2,
	// 		from: 1,
	// 		to: 0
	// 	});
	// }
	
	var clearSearch = $$('.input-address img')[0];
	if (clearSearch) {
		clearSearch.setOpacity(0).setStyle({display: 'block'});
		$('address').observe('keyup', function(){
			if ($F('address').empty()) {
				if (clearSearch.getOpacity() > 0) {
					new Effect.Opacity(clearSearch, {duration: 0.3, from: clearSearch.getOpacity(), to: 0});
				}
			} else {
				if (clearSearch.getOpacity() < 1) {
					new Effect.Opacity(clearSearch, {duration: 0.3, from: clearSearch.getOpacity(), to: 1});
				}
			}
		});

		clearSearch.observe('click', function(){
			$('address').setValue('');
			$('country').fire('value:change');
			new Effect.Opacity(clearSearch, {duration: 0.3, from: clearSearch.getOpacity(), to: 0});
		});
	}
	

	if ($$('.page-title .right').length) {
		$$('.page-title .right')[0].observe('click', function(){
			Effect.ScrollTo('online-stores', {duration: 1, transition: Effect.Transitions.EaseFromTo});
		});
	}
});



LFI.DropDown = Class.create();
LFI.DropDown.prototype = {
	id: null,
	el: null,
	name: null,
	options: null,
	dropDownItemT: new Template('<li id="v-#{id}-#{value}">#{title}</li>'+"\n"),
	dropDownT: new Template('<dl id="dd-#{id}" class="styledDropDown"><dt>#{currentValue}</dt><dd><div><ul>#{options}</ul></div></dd></dl>'),
	
	initialize: function(selector){
		this.el = $$(selector)[0];
		this.el.hide();
		this.id = this.el.identify();
		this.name = this.el.readAttribute('name');
		this.options = $H();
		this.parseOptions();
		this.draw.bind(this)();
	},
	
	parseOptions: function(){
		this.el.getElementsBySelector('option').each(function(option){
			var t = option.innerHTML;
			var v = option.readAttribute('value');
			this.options.set(v, {
				value: v,
				title: t
			});
		}.bind(this));
	},
	
	blur: function(e){
		if (e && $(e.target).descendantOf($$('#dd-'+this.id+' div')[0].identify())) {
			$(this.id).setValue(e.target.identify().split('-').pop());
			$$('#dd-'+this.id+' dt')[0].update(this.options.get($(this.id).getValue()).title);
			$(this.id).fire('value:change');
		}
		
		this.hide();
		
		$$('body')[0].stopObserving('click');
		$$('#dd-'+this.id+' dt')[0].observe('click', function(){
			this.show();
		}.bind(this));
	},
	
	hide: function(){
		Effect.BlindUp($$('#dd-'+this.id+' div')[0].identify(), {
			duration: 0.2,
			afterFinish: function(){
				$('dd-'+this.id).writeAttribute('style', '');
			}.bind(this)
		});
	},
	
	show: function(){
		$('dd-'+this.id).setStyle({
			WebkitBorderBottomLeftRadius: '0px',
			WebkitBorderBottomRightRadius: '0px',
			MozBorderRadiusBottomleft: '0px',
			MozBorderRadiusBottomright: '0px'
		});
		
		Effect.BlindDown($$('#dd-'+this.id+' div')[0].identify(), {
			duration: 0.2,
			afterFinish: function(){
				$$('body')[0].observe('click', this.blur.bind(this));
			}.bind(this)
		});
		
		$$('#dd-'+this.id+' dt')[0].stopObserving('click');
	},
	
	draw: function(){
		var options = '';
		this.options.each(function(item){
			var v = item[1];
			if (v.value.blank()) return;
			options += this.dropDownItemT.evaluate({
				id: this.id,
				value: v.value,
				title: v.title
			});
		}.bind(this));
		
		var current = this.options.get($F(this.id)) ? this.options.get($F(this.id)).title : this.options.values()[0].title;
		
		this.el.insert({
			after: this.dropDownT.evaluate({
				id: this.id,
				options: options,
				currentValue: current
			})
		});
		
		var dId = '#dd-'+this.id;
		$$(dId+' div')[0].hide();
		
		$$(dId+' dt')[0].observe('click', function(){
			this.show();
		}.bind(this));
		
		$$(dId+', '+dId+' li').each(function(item){
			item.observe('mouseover', function(){
				this.addClassName('over');
			}).observe('mouseout', function(){
				this.removeClassName('over');
			});
		});
		
	}
	
};




