/* CLIQUE */
/* Alert Widget Enhancements Pattern Javascript
----------------------------------------------------------------------------- */


	(function($) {


	$.fn.cliqueAlertWidget = function(parameters) {
	
		var defaults = {
		
			format: 'inline'

		};

		var parameters = $.extend(defaults, parameters);


/* PRESERVE CHAINING
----------------------------------------------------------------------------- */

	
	return this.each(function() {


		var $this = $(this);
	

/* CART ADDITION REPEATOR
----------------------------------------------------------------------------- */


	$('div.widget-item').each(function() {
	
		$(this).find('select').each(function() {

			$(this).find('option').each(function(index) {
			
				if ($(this).hasClass(':selected')) {
					$(this).addClass('previous');
				}
			
			});

		});

		$(this).find('input[type=radio]').each(function() {

			if ($(this).hasClass(':checked')) {
				$(this).addClass('previous');
			}

		});
	
	});
	
	if ($(this).children('h3').text().match('cart')) {

		$this.children('ul.actions').prepend('<li><a class="action another" href="#">Buy Another</a></li>');
	
		$this.find('a.another').click(function() {
		
			$('div.widget-item select').each(function() {
	
				$dropdown = $(this);
	
				$(this).find('option').each(function(index) {
				
					if ($(this).hasClass('.previous')) {
						$dropdown[0].selectedIndex = index;
						$('div.widget-item select').attr('disabled','disabled').hide();
						$dropdown.removeAttr('disabled').show();
					}
				
				});
	
			});
			
			$('div.widget-item input[type=radio]').removeAttr('checked');
	
			$(this).find('input.previous').each(function() {
	
				$(this).attr('checked','checked');
	
			});
			
			$('div.widget-item.display input[name=buy]').click();
			
			return false;
	
		});
	
	}


/* END PLUG-IN
----------------------------------------------------------------------------- */


			});

		};

	})(jQuery);
