var currentPosition = Cookie.read('lastPosition');
var rememberPosition = false;

if(currentPosition) {
	window.scrollTo(0,currentPosition);
}
Cookie.dispose('lastPosition',{domain: 'highersites.co.uk', path: '/'});
	
window.addEvent('unload', function() {
	if(rememberPosition) {
		currentPosition = window.getScroll().y;
		Cookie.write('lastPosition', currentPosition, {duration: 1, domain: 'highersites.co.uk', path: '/'});
	}
});
	
window.addEvent('domready', function() {

	new DatePicker('.datepicker', {format:'d/m/Y',inputOutputFormat: 'Y-m-d', pickerClass: 'datepicker_vista', allowEmpty: true});

	if($('standardSelect')) {
		$('standardSelect').addEvent('click',function(evt) {
			evt.stop();
			$('horizon').set('value','standard');
			$('basketForm').submit();
		});
	}

	if($('forwardSelect')) {
		$('forwardSelect').addEvent('click',function(evt) {
			evt.stop();
			$('horizon').set('value','forward');
			$('basketForm').submit();
		});
	}
	
	$$('#swatches .link').addEvent('click',function(evt) {
		evt.stop();
		rememberPosition = true;
		location = this.href;				
	});

				
	if($('colourChoice')) {
		$('colourChoice').addEvent('change',function() {
			if(this.options[this.selectedIndex].value != "") {
				rememberPosition = true;
				location = this.options[this.selectedIndex].value;				
			}
		})
	}
	
	if($('sizeChoice')) {
		$('sizeChoice').addEvent('change',function() {
			if(this.options[this.selectedIndex].value != "") {
				rememberPosition = true;
				location = this.options[this.selectedIndex].value;
			}
		})
	}
	
	
	if($('secondsizeChoice')) {
		$('secondsizeChoice').addEvent('change',function() {
			if(this.options[this.selectedIndex].value != "") {
				rememberPosition = true;
				location = this.options[this.selectedIndex].value;
			}
		})
	}

	$$('.quantity').addEvent('change', function() {
		var id = this.id.replace('quantity_','');
		var ajaxPrices = new Request.HTML({
			url:'/ajax-prices.php',
			update: $('ajax_prices_' + id) 
		}).post({
			'quantity': this.value,
			'products_id': id
		});
	}).fireEvent('change');
	
	$$('.quantity').addEvent('keyup', function() {
		var id = this.id.replace('quantity_','');
		var ajaxPrices = new Request.HTML({
			url:'/ajax-prices.php',
			update: $('ajax_prices_' + id) 
		}).post({
			'quantity': this.value,
			'products_id': id
		});
	});

	 	
});	
