$(document).ready(function () {
	
	// sticky footer plugin
	(function($){
	  var footer;

	  $.fn.extend({
	    stickyFooter: function(options) {
	      footer = this;

	      positionFooter();

	      $(window)
	        .scroll(positionFooter)
	        .resize(positionFooter);

	      function positionFooter() {
	        var docHeight = $(document.body).height() - $("#footer-push").height();
	        if(docHeight < $(window).height()){
	          var diff = $(window).height() - docHeight;
	          if (!$("#footer-push").length > 0) {
	            $(footer).before('<div id="footer-push"></div>');
	          }
	          $("#footer-push").height(diff);
	        }
	      }
	    }
	  });
	})(jQuery);
	
	
	$(".cart-button").click(function () {
		$('.cart-contents').slideToggle('slow');
	});    
	
	$("#footer_container").stickyFooter();
	
 	$('a[id^=clearcart_button]').replaceWith('<a onclick="" id="clearcart_button" class="remove">' + $('#clearcart_button').html() + '</a>');
   
    $('a[id^=clearcart_button]').live("click", function () {
		$.ajax({
			type: 'post',
			url: 'index.php?route=module/cart/clear',
			dataType: 'html',
			data: $(this).parent().children(':input'),
			success: function (html) {
				$('#module_cart').html(html);
				window.location = "/bases/";
		    }
		});
    });
	
	$('a[class^=add-to-cart]').replaceWith('<a onclick="" class="add-to-cart button">' + $('.add-to-cart').html() + '</a>');
	
	$('a[class^=add-to-cart]').live("click", function () {
		var element = $(this);
		var value = element.siblings("input[name=product_id]").attr("value");
	
		$.ajax({
			type: 'post',
			url: 'index.php?route=module/cart/callback',
			dataType: 'html',
			data: $('#add_' + value + ' :input'),
				success: function (html) {
					$('#module_cart').html(html);
					
					$(".cart-button").click(function () {
						$('.cart-contents').slideToggle('slow');
					});    

				}							
		});
	});
	
	
	$('a[class^=remove-from-mix]').replaceWith('<a onclick="" class="remove-from-mix" title="Remove From Mix">' + $('.remove-from-mix').html() + '</a>');
	
	$('a[class^=remove-from-mix]').live("click", function () {
		var element = $(this);
		var value = element.siblings("input[name=product_id]").attr("value");
				
		$.ajax({
			type: 'post',
			url: 'index.php?route=module/cart/change',
			dataType: 'html',
			data: $('#remove_' + value + ' :input'),
				success: function (html) {
					$('#module_cart').html(html);
					$('a[class^=remove-from-mix]').replaceWith('<a onclick="" class="remove-from-mix" title="Remove From Mix">' + $('.remove-from-mix').html() + '</a>');
					
					$(".cart-button").click(function () {
						$('.cart-contents').slideToggle('slow');
					}); 
				}							
		});
	});
	
	$('#new_collection_button').replaceWith('<a onclick="" id="new_collection_button" class="button">' + $('#new_collection_button').html() + '</a>');
	   
	$('#new_collection_button').live("click", function () {
	        $.ajax({
	            type: 'post',
	            url: 'index.php?route=module/cart/collection',
	            dataType: 'html',
	            data: $('#new_collection :input'),
	            success: function (html) {
	                $('#module_cart').html(html);
	            }
	        });           
	    });
	
	
	$('.zoom').fancybox();

	Cufon.replace('h1', {
			textShadow: '#999 1px 1px'
		});
	
	$('.faq').find('.answer').hide().end().find('.question').click(function() {
		 var answer = $(this).next();
		 if (answer.is(':visible')) {
			 answer.slideUp();
		 } else {
			 answer.slideDown();
		 }
	});

	jQuery.validator.addMethod("mixName", function( value, element, param ) {
	        return this.optional(element) || value.length >= 6 && /[a-z]/i.test(value);
	}, "Your name must be at least 6 characters long and contain at least one character.");
	
});

