window.addEvent('domready', function(){
	
	$(document.body).getElements('a.show_epdownload').addEvent('click', function(e){
		showOverlay('downloadover');
		e.stop();
	});
	
	$(document.body).getElements('a.show_sbdownload').addEvent('click', function(e){
		showOverlay('sbdownloadover');
		e.stop();
	});
	
	$('hidesbdownload').addEvent('click', function(e){
		hideOverlay('sbdownloadover');
		e.stop();
	});
	
	$('sbdownloadoverbg').addEvent('click', function(e){
		hideOverlay('sbdownloadover');
		e.stop();
	});
	
	
	$('hidedownload').addEvent('click', function(e){
		hideOverlay('downloadover');
		e.stop();
	});
	
	$('downloadoverbg').addEvent('click', function(e){
		hideOverlay('downloadover');
		e.stop();
	});
	
	/*
	$('showphoto').addEvent('click', function(e){
		showOverlay('photoover');
		e.stop();
	});
	
	$('hidephoto').addEvent('click', function(e){
		hideOverlay('photoover');
		e.stop();
	});
	
	$('photooverbg').addEvent('click', function(e){
		hideOverlay('photoover');
		e.stop();
	});
	*/
	
	if (Browser.Engine.trident4) {
		fixIe6Fixed('downloadover');
		window.addEvent('scroll', fixIe6Fixed.bind(this,'downloadover'));
		
		fixIe6Fixed('photoover');
		window.addEvent('scroll', fixIe6Fixed.bind(this,'photoover'));
	}
	
	$('sbamount').addEvent('change', function(e){
		setSBoptions();
	});
	
	$('sbcommerceformsubmit').addEvent('click', function(e) {
		$('sbcommerceform').submit();
		e.stop();	
	});	
	
	setSBoptions();
	
});

function setSBoptions() {
	if ($('sbamount').get('value') > 29.99) {
		$('optionsselect').set('html','');
		new Element('option',{text:'Just a thank you','value':'Songbook Donation'}).inject('optionsselect');
		new Element('option',{text:'Physical CD','value':'Songbook CD'}).inject('optionsselect');
		new Element('option',{text:'CD + Tote Bag','value':'Songbook CD + Tote Bag'}).inject('optionsselect');
		new Element('option',{text:'CD + T Shirt (S)','value':'Songbook CD + Shirt (S)'}).inject('optionsselect');
		new Element('option',{text:'CD + T Shirt (M)','value':'Songbook CD + Shirt (M)'}).inject('optionsselect');
		new Element('option',{text:'CD + T Shirt (L)','value':'Songbook CD + Shirt (L)'}).inject('optionsselect');
		new Element('option',{text:'CD + T Shirt (XL)','value':'Songbook CD + Shirt (XL)'}).inject('optionsselect');
	} else if (($('sbamount').get('value') > 14.99) && ($('sbamount').get('value') < 30)) {
		$('optionsselect').set('html','');
		new Element('option',{text:'Just a thank you','value':'Songbook Donation'}).inject('optionsselect');
		new Element('option',{text:'Physical CD','value':'Songbook CD'}).inject('optionsselect');
	} else {
		$('optionsselect').set('html','');
		new Element('option',{text:'Just a thank you','value':'Songbook Donation'}).inject('optionsselect');
	}
}

function showOverlay(whichOverlay) {
	$(whichOverlay).setStyle('zIndex',500);
	$(whichOverlay).setStyle('visibility','visible');
	$(whichOverlay + 'bg').get('tween', {property:'opacity',duration:125}).start(0,0.85).chain(function(){
		$(whichOverlay + 'content').get('tween', {property:'opacity',duration:350}).start(0,1);
	});
}

function hideOverlay(whichOverlay) {
	$(whichOverlay + 'content').get('tween', {property:'opacity',duration:350}).start(1,0);
	$(whichOverlay + 'bg').get('tween', {property:'opacity',duration:125}).start(0.85,0).chain(function(){
		$(whichOverlay).setStyle('zIndex',20);
		$(whichOverlay).setStyle('visibility','hidden');
	});
}
