var ecomm = {

	add_to_bag: function() {
		
		$('a.add_to_bag').click(function() {

			var select = $('select#session_prop_misc'), 
					selected = select.find('option:selected'),
					button = $(this),
					url = button.attr('href');
					
			if ( select.length ) {
				if ( selected.index() === 0 ) {
					alert('Please select a size first.');
					return false;
				}
				else {
					url = url + '&sessionprop=' + 'Ring_Size@' + selected.val();
				}		 
			}
			
			button.html('<span>Adding item...</span>');
			
			$.ajax({
				type: 'post',
				url: url,
				success: function() {
					button.html('<span>Item Added</span>').qtip({
						content: {
							text: '<div class="add_message"><p>This item has been added to your shopping bag.</p> <p><a href="#" class="continue">Continue Shopping</a> | <a href="'+ cartURL +'">View Shopping Bag</a></p></div>'
						},
						container: $(this).parent(),
						show: {
							ready: true
						},
						hide: false,
						position: {
							corner: {
								tip: true,
								target: 'leftMiddle',
								tooltip: 'rightMiddle'
							},
							adjust: {
								x: - 2
							}
						},
						style: {
							border: {
								width: 2,
								radius: 2,
								color: '#717480'
							},
							width: {
								max: 400
							},
							tip: {
								corner: 'rightMiddle',
								size: {
									x: 6,
									y: 10
								}
							}
						},
						api: {
							onRender: function () {
								var self = this;
								$(self.elements.tooltip).find('a.continue').click(function() {
									$(self.elements.target).html('<span>Add to shopping bag</span>');
									self.destroy();
									return false;
								});
							}
						}
					});
				}
			});
			return false;
		});	
	}
	
}

/*$(function() {
	ecomm.add_to_bag();
});*/

