MooTools.More={version:"1.2.4.4",build:"6f6057dc645fdb7547689183b2311063bd653ddf"};Fx.Scroll=new Class({Extends:Fx,options:{offset:{x:0,y:0},wheelStops:true},initialize:function(b,a){this.element=this.subject=document.id(b);
this.parent(a);var d=this.cancel.bind(this,false);if($type(this.element)!="element"){this.element=document.id(this.element.getDocument().body);}var c=this.element;
if(this.options.wheelStops){this.addEvent("start",function(){c.addEvent("mousewheel",d);},true);this.addEvent("complete",function(){c.removeEvent("mousewheel",d);
},true);}},set:function(){var a=Array.flatten(arguments);if(Browser.Engine.gecko){a=[Math.round(a[0]),Math.round(a[1])];}this.element.scrollTo(a[0],a[1]);
},compute:function(c,b,a){return[0,1].map(function(d){return Fx.compute(c[d],b[d],a);});},start:function(c,g){if(!this.check(c,g)){return this;}var e=this.element.getScrollSize(),b=this.element.getScroll(),d={x:c,y:g};
for(var f in d){var a=e[f];if($chk(d[f])){d[f]=($type(d[f])=="number")?d[f]:a;}else{d[f]=b[f];}d[f]+=this.options.offset[f];}return this.parent([b.x,b.y],[d.x,d.y]);
},toTop:function(){return this.start(false,0);},toLeft:function(){return this.start(0,false);},toRight:function(){return this.start("right",false);},toBottom:function(){return this.start(false,"bottom");
},toElement:function(b){var a=document.id(b).getPosition(this.element);return this.start(a.x,a.y);},scrollIntoView:function(c,e,d){e=e?$splat(e):["x","y"];
var h={};c=document.id(c);var f=c.getPosition(this.element);var i=c.getSize();var g=this.element.getScroll();var a=this.element.getSize();var b={x:f.x+i.x,y:f.y+i.y};
["x","y"].each(function(j){if(e.contains(j)){if(b[j]>g[j]+a[j]){h[j]=b[j]-a[j];}if(f[j]<g[j]){h[j]=f[j];}}if(h[j]==null){h[j]=g[j];}if(d&&d[j]){h[j]=h[j]+d[j];
}},this);if(h.x!=g.x||h.y!=g.y){this.start(h.x,h.y);}return this;},scrollToCenter:function(c,e,d){e=e?$splat(e):["x","y"];c=$(c);var h={},f=c.getPosition(this.element),i=c.getSize(),g=this.element.getScroll(),a=this.element.getSize(),b={x:f.x+i.x,y:f.y+i.y};
["x","y"].each(function(j){if(e.contains(j)){h[j]=f[j]-(a[j]-i[j])/2;}if(h[j]==null){h[j]=g[j];}if(d&&d[j]){h[j]=h[j]+d[j];}},this);if(h.x!=g.x||h.y!=g.y){this.start(h.x,h.y);
}return this;}});

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

	// equalize column heights
	document.getElements('.equalize').equalize('height');
	document.getElements('.equalize2').equalize('height');
	
	// set height of cheeseboard
	var h = document.getElements('.text')[0].getSize().y + document.getElements('.footer')[0].getSize().y;
	
	if (document.getElements('.homepics').length > 0){
		h += document.getElements('.homepics')[0].getSize().y - 55;
	}
				
	document.getElements('.cb').setStyle('height', h);

});

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

	$('contact').setStyles({
		'top': (window.getSize().y / 2) - 221,
		'left': (window.getSize().x / 2) - 221
	});

	$('preshop').setStyles({
		'top': (window.getSize().y / 2) - 221,
		'left': (window.getSize().x / 2) - 221
	});

});

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

/*
	// sort out form submission on shop
	if ($('frm-sagepay')) {
		if ($('frm-sagepay').getElement('.send a')){
			$('frm-sagepay').getElement('.send a')
			.addEvent('click', function(ev){
				ev.stop();
				$('frm-sagepay').submit();
			});
		}
	}
*/

	// slideshow of award stamps
	if($$('p.award img')) {
		
		// elements
		theawards = $$('p.award img');
		
		theawards.each(function(el){
			if (!el.hasClass('selected')) {
				el.setStyle('display', 'none');
			}
		});
		
	    // run promo bar rotator
		if(theawards) var awards = aw.periodical(5000);

	}
	
	$$('div.links li')
	.set('morph',{ duration: 100 })
	.addEvent('mousedown', function(ev){
	
		if (!this.hasClass('selected')){
		
			this.morph({
				'margin-top': 3,
				'height': 24
			});
			
		
			$$('div.links li.selected').morph({
				'margin-top': 0,
				'height': 27
			});	
			
		}
	
	})
	.addEvent('mouseleave', function(ev){
	
		if (!this.hasClass('selected')){
		
			this.morph({
				'margin-top': 0,
				'height': 27
			});		
			
			$$('div.links li.selected').morph({
				'margin-top': 3,
				'height': 24
			});	
			
		}
	
	})
	.addEvent('click', function(ev){
	
		var h = this.getElement('a').getProperty('href');
		if (h.indexOf('#contact') != -1){
		
			$('overlay').setStyles({
				'opacity': 0,
				'display': 'block'
			});
			
			$('contact').setStyles({
				'opacity': 0,
				'display': 'block'
			});
			
			$('overlay').tween('opacity', 1);
			$('contact').tween('opacity', 1);
			
			ev.stop();
		
		} 
		else if (h.indexOf('#shop') != -1){
		
			$('overlay').setStyles({
				'opacity': 0,
				'display': 'block'
			});
			
			$('preshop').setStyles({
				'opacity': 0,
				'display': 'block'
			});
			
			$('overlay').tween('opacity', 1);
			$('preshop').tween('opacity', 1);
			
			ev.stop();
		
		} else {
			location.href = '/' + h;
		}
	});
	
	$('contact').getElement('p.close a')
	.addEvent('click', function(ev){
	
		if (ev) ev.stop();
		
		$('overlay').tween('opacity', 0);
		$('contact').tween('opacity', 0);
		
		(function(){
			$('overlay').setStyles({
				'opacity': 0,
				'display': 'none'
			});
			
			$('contact').setStyles({
				'opacity': 0,
				'display': 'none'
			});
		}.delay(600));
	
	});
	
	$('contact').getElement('form').set('send', {
	  	onSuccess: function(success) { 	
			$('contact').getElement('form').empty();
			$('contact').getElement('form').set('html', '<p>Thanks for your message! We&rsquo;ll get back to you as soon as we can.</p>');
		}
	});
	
	$('contact').getElement('p.send a')
	.addEvent('click', function(ev){
	
		if (ev) ev.stop();
		
		$('contact').getElement('form').send();
		
	});	
	


	$('preshop').getElement('p.close a')
	.addEvent('click', function(ev){
	
		if (ev) ev.stop();
		
		$('overlay').tween('opacity', 0);
		$('preshop').tween('opacity', 0);
		
		(function(){
			$('overlay').setStyles({
				'opacity': 0,
				'display': 'none'
			});
			
			$('preshop').setStyles({
				'opacity': 0,
				'display': 'none'
			});
		}.delay(600));
	
	});
	
	$('preshop').getElement('form').set('send', {
	  	onSuccess: function(success) { 	
			$('preshop').getElement('form').empty();
			$('preshop').getElement('form').set('html', '<p>Thanks for your message! We&rsquo;ll get back to you as soon as we can.</p>');
		}
	});
	
	$('preshop').getElement('p.send a')
	.addEvent('click', function(ev){
	
		if (ev) ev.stop();
		
		$('preshop').getElement('form').send();
		
	});	
	
	
	$$('.getintouch').addEvent('click', function(cl){
		cl.stop();
	
		new Fx.Scroll($(document.body)).toElement($('thetop'));

		$('overlay').setStyles({
			'opacity': 0,
			'display': 'block'
		});
		
		$('contact').setStyles({
			'opacity': 0,
			'display': 'block'
		});
		
		$('overlay').tween('opacity', 1);
		$('contact').tween('opacity', 1);
				
	});
	

	$$('div.footer ul li p').addEvent('click', function(cl){

		cl.stop();	
		var h = this.getElement('a').getProperty('href');
				
		if (h.indexOf('#contact') != -1){
		
			new Fx.Scroll($(document.body)).toElement($('thetop'));

			$('overlay').setStyles({
				'opacity': 0,
				'display': 'block'
			});
			
			$('contact').setStyles({
				'opacity': 0,
				'display': 'block'
			});
			
			$('overlay').tween('opacity', 1);
			$('contact').tween('opacity', 1);
					
		} 		
		
		else if (h.indexOf('#shop') != -1){
		
			new Fx.Scroll($(document.body)).toElement($('thetop'));

			$('overlay').setStyles({
				'opacity': 0,
				'display': 'block'
			});
			
			$('preshop').setStyles({
				'opacity': 0,
				'display': 'block'
			});
			
			$('overlay').tween('opacity', 1);
			$('preshop').tween('opacity', 1);
					
		} else {
			location.href = h;
/* 			location.href = '/' + h; */
		}
		
	});
	
	window.fireEvent('resize');

});

// function to run awards ticker
var aw = function(){

	var el = $('awards').getElement('img.selected');
	var count = el.getAllPrevious('img').length;
		
	count = count + 1;	
				
	if (count == $$('p.award img').length){
		count = 0;
	}
		
	$$('p.award img.selected').removeClass('selected').each(function(el){
		if (el.getStyle('opacity') == 1){
			el.tween('opacity', 0);
		}
	});
	
	if (count == 0) {
		
		count++;
	
		$('a1').setStyles({
			'display':'block',
			'opacity': 0
		}).addClass('selected')
		.tween('opacity', 1);
	}
	else {
		el.getNext('img').setStyles({
			'display':'block',
			'opacity': 0
		}).addClass('selected')
		.tween('opacity', 1);
	}
					
}
