var IrishHeart = new Class(
{
	initialize: function()
	{
		this.loadToolTips();
		this.loadShoppingCart();
		this.loadEventsOther();
	},

	loadToolTips: function()
	{
		/*
		var tips = $$('.event');
		var oktips = new Array();
		for(var i=0; i<tips.length; i++)
		{
			var id = tips[i].id.toString().replace(/event_/, "tooltip_");
			var title = $(id);
			if(title != null && title.value.toString().length > 0)
			{
				tips[i].setProperty('title', title.value);
				oktips.push(tips[i]);
			}
		}
		
		var myTips = new Tips(oktips, {
			timeOut: 700,
			maxTitleChars: 50,
			titleAttribute: 'title',
			maxOpacity: .9,
			onShow: function(tip){
				new Fx.Style(tip, 'opacity', {duration: 300}).start(0,1);
			},
			onHide: function(tip){
				new Fx.Style(tip, 'opacity', {duration: 100}).start(1,0);
			}
		});
		*/
		
		//var tips = new Tips('.event');
	
	
		var tips = $$('.event');
		var oktips = new Array();
		for(var i=0; i<tips.length; i++)
		{
			var id = tips[i].id.toString().replace(/event_/, "tooltip_");
			var title = $(id);
			if(title != null && title.value.toString().length > 0)
			{
				//tips[i].setProperty('title', title.value);
				tips[i].store('tip:title', '');
				tips[i].store('tip:text', title.value);
			}
		}
		var tips = new Tips('.event', {className:'tool-tip'});
	},
	
	loadShoppingCart: function()
	{
		if($chk($('cart_quantity')) && $chk($('shoppingcart')))
		{
			//$('cart_quantity').action = $('cart_quantity').action + '&ajax=1';
			
			var quantities = $$('input.cart_quantity');
			var i = 0;
			
			for(i=0; i<quantities.length; i++)
			{
				quantities.addEvent('blur', function(event)
				{
					event = new Event(event);
					event.stop();
					
					$('cart_quantity').send();
				});
			}
			
			var parentObj = this;
			
			if($chk($('button_continue_shopping')))
			{
				$('button_continue_shopping').addEvent('click', function(event)
				{
					event = new Event(event);
					event.stop();
					
					parentObj.showLoading();
					
					$('cart_quantity').set('send', 
					{
						onComplete: function()
						{
							window.location = $('button_continue_shopping').href;
						}
					});
					$('cart_quantity').send();
					
					return false;
				});
			}
			
			if($chk($('button_checkout')))
			{
				$('button_checkout').addEvent('click', function(event)
				{
					event = new Event(event);
					event.stop();
					
					parentObj.showLoading();
					
					$('cart_quantity').set('send', 
					{
						onComplete: function()
						{
							window.location = $('button_checkout').href;
						}
					});
					$('cart_quantity').send();
					
					return false;
				});
			}
		}
	},
	
	showLoading: function()
	{
		var checkoutButtons = $('checkout_buttons');
		/*
		var opacityChange = new Fx.Style(checkoutButtons, 'opacity', {duration:500});
		opacityChange.start(1, 0);
		checkoutButtons.setStyles({'display': 'none', 'opacity': '0'});
		*/
		checkoutButtons.fade(0);
		
		var cartLoading = $('cart_loading');
		cartLoading.setStyles({'display': 'block', 'opacity': '0'});
		/*
		var opacityChange = new Fx.Style(cartLoading, 'opacity', {duration:500});
		opacityChange.start(0, 1);
		*/
		cartLoading.fade(1);
	},
	
	loadEventsOther: function()
	{
		if($chk($('event_other')))
		{
			if($('event_dropdown').value != '-1')
			{
				$('event_other').setStyles({'display':'none'});
			}
		}
		if($chk($('event_dropdown')))
		{
			$('event_dropdown').addEvent('change', this.eventChange.bind(this));
		}
	},
	
	eventChange: function(event)
	{
		event = new Event(event);
		event.stop();
		
		if($('event_dropdown').value == '-1')
		{
			$('event_other').setStyles({'display':'block'});
		}
		else
		{
			$('event_other').setStyles({'display':'none'});
		}
	}
});

window.addEvent('domready', function()
{
	var irishHeart = new IrishHeart();
});