$(document).ready(function(){
	var maxHeight = $("div.center").height() - 80;
	floatDiv("basket", 471, maxHeight).float();
	$("#basket").hover(function(){
		$("#basket .basket-big").show();
	}, function(){
		$("#basket .basket-big").hide();
	});
});

var setFloatInterval = false;
var setFloatTimeOut = false;

function stopFloat(){
	clearInterval(setFloatInterval);
}

function floatDiv(id, startY, maxHeight) {
	var element = $("#" + id);
	window[id + "_object"] = element;
	element.currentY = element.startY = startY;
	element.setPosition = function(newY){
		this.css('top', newY);
	};
	element.float = function(){
		var pageY = $(document).scrollTop();
		this.currentY += (pageY + this.startY - this.currentY)/8;
		if(this.currentY > maxHeight){
			this.currentY = maxHeight;
		}
		this.setPosition(this.currentY);
		$(window).scroll(function(){
			if(setFloatInterval != false){
				clearInterval(setFloatInterval);
				clearTimeout(setFloatTimeOut);
			}
			setFloatInterval = setInterval(id + "_object.float()", 40);
			setFloatTimeOut = setTimeout("stopFloat()", 4000);
		});
	};
	return element;
}

