window.addEvent('domready', function(){
	$('comparison-chart').setAttribute('href', 'javascript:showComparison()');
});

function showComparison(){
	$(document.body).setStyle('cursor', 'wait');
	$$('a').each(function(el){el.setStyle('cursor','wait')});
	new Request.HTML({
		url:ROOT+'/ajax/getcomparison',
		onComplete:function(first, second, HTML){
			document.body.setStyle('cursor', 'auto');
			$$('a').each(function(el){el.setStyle('cursor','auto')});
			blank=new Element('DIV');
			blank.setStyles({
				width:'100%',
				height:document.getScrollHeight(),
				opacity:.7,
				backgroundColor:'#000000',
				position:'absolute',
				left:0,
				top:0,
				zIndex:500
			});
			blank.injectInside(document.body);
			chart=new Element('DIV');
			chart.set('html', HTML);
			chart.setAttribute('id', 'comparison-holder');
			chart.setStyles({
				position:'absolute',
				width:800,
				marginLeft:-400,
				left:'50%',
				top:100,
				backgroundColor:'#FFFFFF',
				border:'solid 1px #CCC',
				padding:10,
				zIndex:600
			});
			chart.injectInside(document.body);
			chart.addEvent('click', function(){killModal()});
			blank.addEvent('click', function(){killModal()});
		}
	}).post({type:'brewery'});
}

function killModal(){
	chart.destroy();
	blank.destroy();
}
