
function showHide() {
	
	var show_hide = $("#minicart").css('display');
	if(show_hide == "block"){
		$(".show_hide_cart img").attr("src", "/images/minicart/minicart-show.png");
		$("#minicart").hide("slow");
		$.get('/cart_indicator', null, null, "script");
		$("#cart_indicator").show("slow");
	}else{
		$(".show_hide_cart img").attr("src", "/images/minicart/minicart-hide.png");
		$("#cart_indicator").hide("slow");
		$.get('/show_minicart', null, function(data) {
			$("form.minicart_shipping").submit(getShipping);
		}, "script");
		$("#minicart").show("slow");
		$("#minicart").stickyfloat({duration: 500});
		return false;
	}	
}

function toggle_mini_ship() {
	$("#mini_ship_body").slideToggle(200, function () {
		var $body = $("#mini_ship_body");
		if($body.is(':visible')){
			$("#mini_ship_button img").attr("src", "/images/minicart/mini-button-shipping-hide.jpg");
		}else{
			$("#mini_ship_button img").attr("src", "/images/minicart/mini-button-shipping.jpg");
		}	
	}); 
	return false;
}

$(document).ready(function(){
	if ($("td.category_cell").length > 0 ) {
		$.get('/show_minicart', null, function(data) {
			$("form.minicart_shipping").submit(getShipping);
		}, "script");
		$("#minicart").show("slow");
		$(".show_hide_cart img").attr("src", "/images/minicart/minicart-hide.png");
		$("#cart_indicator").hide();
		return false;
	}
});

var getShipping = function() {
	$('form.minicart_shipping').append($(document.createElement('p')).attr('id', 'mini_ship_loader'));
	$('form.minicart_shipping p:last').append($(document.createElement('img')).attr('src', '/images/ajax_loader.gif'));
	$.post($(this).attr("action"), $(this).serialize(), function() {
		$('form.minicart_shipping p:last').remove();
	}, "script");
	return false;
};


$(document).ready(function() {
	$("form.cart").submit(function() {
		if ($("select[name=variant]", this).length > 0) {
			var variant = $("select[name=variant]", this).val();
		} else {
			var variant = $("input[name=variant]", this).val();
		}
		var quantity = $("input[name=quantity]", this).val();
		var url = window.location.href;
		
		$(".show_hide_cart img").attr("src", "/images/minicart/minicart-hide.png");
		$("#cart_indicator").hide("slow");
		$.post('/orders', "variant=" + variant +"&quantity=" + quantity + "&url=" + url, function(data) {
			$("form.minicart_shipping").submit(getShipping);
		}, "script");
		$("#minicart").show("slow");
		$("#mini_ship_body").hide();
		$("#mini_ship_button").show();
		$("#minicart").stickyfloat({duration: 500});
	return false;
	});	
})



		/*
		 * stickyfloat - jQuery plugin for verticaly floating anything in a constrained area
		 * 
		 * Example: jQuery('#menu').stickyfloat({duration: 400});
		 * parameters:
		 * 		duration 	- the duration of the animation
		 *		startOffset - the amount of scroll offset after it the animations kicks in
		 *		offsetY		- the offset from the top when the object is animated
		 *		lockBottom	- 'true' by default, set to false if you don't want your floating box to stop at parent's bottom
		 * $Version: 05.16.2009 r1
		 * Copyright (c) 2009 Yair Even-Or
		 * vsync.design@gmail.com
		 */

		$.fn.stickyfloat = function(options, lockBottom) {
			var $obj 				= this;
			var parentPaddingTop 	= parseInt($obj.parent().css('padding-top'));
			var startOffset 		= $obj.parent().offset().top;
			var opts 				= $.extend({ startOffset: startOffset, offsetY: parentPaddingTop, duration: 200, lockBottom:false }, options);

			$obj.css({ position: 'absolute' });

			if(opts.lockBottom){
				var bottomPos = $obj.parent().height() - $obj.height() + parentPaddingTop; //get the maximum scrollTop value
				if( bottomPos < 0 )
					bottomPos = 0;
			}

			$(window).scroll(function () { 
				
				$obj.stop(); // stop all calculations on scroll event

				var pastStartOffset			= $(document).scrollTop() > opts.startOffset;	// check if the window was scrolled down more than the start offset declared.
				var objFartherThanTopPos	= $obj.offset().top > startOffset;	// check if the object is at it's top position (starting point)
				var objBiggerThanWindow 	= $obj.height() > $(window).height();	// if the window size is smaller than the Obj size, then do not animate.
				
				// if window scrolled down more than startOffset OR obj position is greater than
				// the top position possible (+ offsetY) AND window size must be bigger than Obj size
				if( (pastStartOffset || objFartherThanTopPos) ){
					if( objBiggerThanWindow) {
						var bottom = $(window).height() + $(document).scrollTop() - 20;
						var newpos = bottom  - $obj.height();
					} else {
						var newpos = ($(document).scrollTop() -startOffset + opts.offsetY );
					}
					if ( newpos > bottomPos )
						newpos = bottomPos;
					if ( $(document).scrollTop() < opts.startOffset ) // if window scrolled < starting offset, then reset Obj position (opts.offsetY);
						newpos = parentPaddingTop;

					$obj.animate({ top: newpos }, opts.duration );
					
				}
			});
		};



  $(function(){ 
		  settings = {
          tl: { radius: 20 },
          tr: { radius: 20 },
          bl: { radius: 20 },
          br: { radius: 20 },
          antiAlias: true,
          autoPad: true,
          validTags: ["div"]
      }

  //$('#minicart_content').corner(settings);

  });



