var FrontProductsCompare_float01 = {
	topPosition :100,
	leftPosition :0,
	alignLeft :true,
	compId :"",
	compare : function(url) {
		window.open(url, "",
				"toolbar=yes,menubar=yes,resizable=yes,location=yes,scrollbars=yes");
	},
	/* 向浮动框增加一个对比商品，productId:商品ID */
	addProduct : function(productId) {
		var ajaxHref = "/comp-" + FrontProductsCompare_float01.compId
				+ "?oper=add&productId=" + productId;
		jQuery.ajax( {
			url :ajaxHref,
			type :'get',
			dataType :'html',
			timeout :5000,
			cache :false,
			error : function() {
				alert('Error loading XML document');
			},
			success : function(xml) {
				jQuery("#" + FrontProductsCompare_float01.compId + "_productList")
						.html(xml);
			}
		});
		this.showCompare();
	},
	/* 向浮动框去除一个对比商品，productId:商品ID */
	removeProduct : function(productId) {
		var ajaxHref = "/comp-" + FrontProductsCompare_float01.compId
				+ "?oper=remove&productId=" + productId;
		jQuery.ajax( {
			url :ajaxHref,
			type :'get',
			dataType :'html',
			timeout :5000,
			cache :false,
			error : function() {
				alert('Error loading XML document');
			},
			success : function(xml) {
				jQuery("#" + FrontProductsCompare_float01.compId + "_productList")
						.html(xml);
			}
		});
	},
	/* 浮动框清空所有对比商品 */
	removeAllProducts : function() {
		var ajaxHref = "/comp-" + FrontProductsCompare_float01.compId
				+ "?oper=clear";
		jQuery.ajax( {
			url :ajaxHref,
			type :'get',
			dataType :'html',
			timeout :5000,
			cache :false,
			error : function() {
				alert('Error loading XML document');
			},
			success : function(xml) {
				jQuery("#" + FrontProductsCompare_float01.compId + "_productList")
						.html(xml);
			}
		});
	},
	/* 显示对比浮动框 */
	showCompare : function() {
		if (jQuery("#" + FrontProductsCompare_float01.compId).is(":hidden")) {
			jQuery("#" + FrontProductsCompare_float01.compId).fadeIn("slow");
		}
	},
	/* 关闭对比浮动框 */
	fadeOutCompare : function() {
		if (!jQuery("#" + FrontProductsCompare_float01.compId).is(":hidden")) {
			jQuery("#" + FrontProductsCompare_float01.compId).fadeOut("slow");
		}
	},
	hideCompare : function() {
		if (!jQuery("#" + FrontProductsCompare_float01.compId).is(":hidden")) {
			jQuery("#" + FrontProductsCompare_float01.compId).hide();
		}
	},
	/* 最小化或最大化浮动框 */
	minOrMaxCompare : function() {
		if (jQuery("#" + FrontProductsCompare_float01.compId + "_content").is(
				":hidden")) {
			jQuery("#" + FrontProductsCompare_float01.compId + "_content").slideDown(
					"slow");
		} else {
			jQuery("#" + FrontProductsCompare_float01.compId + "_content").slideUp(
					"slow");
		}
	},
	init : function() {
		/* 页面发生scroll事件时触发 */
		jQuery(window).scroll(
				function() {
					jQuery("#" + FrontProductsCompare_float01.compId).css(
							"top",
							FrontProductsCompare_float01.topPosition
									+ jQuery(document).scrollTop());
				});

		/* 浮动窗口拖拽事件 */
		jQuery("#" + FrontProductsCompare_float01.compId).draggable();

		/* 绑定拖拽事件结束后重新设置距上边距的距离 */
		jQuery("#" + FrontProductsCompare_float01.compId).bind(
				"dragstop",
				function(event, ui) {
					FrontProductsCompare_float01.topPosition = jQuery(
							"#" + FrontProductsCompare_float01.compId).offset().top
							- jQuery(document).scrollTop();
				});

		jQuery("#" + FrontProductsCompare_float01.compId).css("top",
				FrontProductsCompare_float01.topPosition);
		if (FrontProductsCompare_float01.alignLeft) {
			jQuery("#" + FrontProductsCompare_float01.compId).css("left",
					FrontProductsCompare_float01.leftPosition)
		} else {
			jQuery("#" + FrontProductsCompare_float01.compId).css(
					"left",
					jQuery("body").innerWidth()
							- jQuery("#" + FrontProductsCompare_float01.compId).outerWidth()
							- FrontProductsCompare_float01.leftPosition);
		}
		/*-
		FrontProductsCompare_float01.topPosition = jQuery(
				"#" + FrontProductsCompare_float01.compId).offset().top;
		 */
		/* 改变浮动窗口大小的事件 */
		// jQuery("#"+FrontProductsCompare_float01.compId).resizable();
	}
}

