jQuery.fn.extend({
    tips:function(tipInfo){
        return $(this).hover(
	        	function(event){
	        		var tip_array=tipInfo.split("?");
	        		var _context_path = tip_array[0];
	        		var productId = tip_array[1];
	        		var image = tip_array[2];
	        		var productName = tip_array[3];
	        		var author = tip_array[4];
	        		var price = tip_array[5];
	        		var isfree = parseInt(price) <= 0 ? true : false;
	        		var bookId = image.substr(image.indexOf("/")+1);
	        		var tip = '';
	        		var starthtml = '<div id="wxTip" class="a_wrap"><div class="a_wrap_i"><div class="a_wrap_c"><div class="a_img"><a href="'+_context_path+'/product/productdetail.html?id=' + productId + '"><img style="width: 78px; height: 120px;border:1px solid #cecece;" alt="' +  productName + '" src="/book/' + image + '/cover/small.png"></a></div><div class="a_info"><div class="a_bn"><a href="'+_context_path+'/product/productdetail.html?id=' + productId + '">' + productName +'</a></div><p>作者：' + author + '<br>价格：<span class="red">￥' + price + '</span></p>';
					var endhtml = '</div></div><div class="a_help"><a href="'+_context_path+'help/orderprocess.html">如何购买电子书？</a></div></div></div>';
	        		var freehtml= '<div class="a_buy"><a href="javascript:void(0);" onclick="javascript:readfreebook(\''+_context_path+'\',\'' + productId + '\',\'' + bookId + '\',true);">进入阅读</a></div><p><a href="javascript:void(0);" onclick="javascript:readfreebook(\''+_context_path+'\',\'' + productId + '\',\'' + bookId + '\',false);"><img id="addshelfimg" src="images/book/bottom21.jpg" /></a></p><div id="prompt2_'+productId+'"></div>';
					var nofreehtml = '<div class="a_buy"><a href="javascript:void(0);" onclick="javascript:cartappend(\''+_context_path+'\',\''+productId+'\');">立即购买</a></div><div id="prompt_'+productId+'"></div><p><a href="product/producttryread.html?id=' + productId + '#tryread"><img src="images/book/icon21.jpg" /></a></p>';
	        		if (isfree) {
	        			tip = starthtml + freehtml + endhtml;
	            	} else {
	            		tip = starthtml + nofreehtml + endhtml;
	            	}
	                $("body").append(tip);
	                $("#wxTip").css({"left":($(this).offset().left -15) + "px", "top":($(this).offset().top - 17) + "px"}).show("fast");
	            },
	        	function(event){
	            	var obj = $("#wxTip");
	            	var divLeft = obj.offset().left;
	            	var divTop = obj.offset().top;
	            	var divRight = divLeft + obj.width()+10;
	            	var divBottom = divTop + obj.height();
					var mouseX = $(this).getMouse(event).mouseX;
					var mouseY = $(this).getMouse(event).mouseY;
					
	            	if((mouseX < divLeft) || (mouseX > divRight) || (mouseY < divTop) || (mouseY > divBottom)){
						$("#wxTip").remove();
					} else {
						$("#wxTip").hover(null,function(){
							$("#wxTip").remove();
						});
					}
	            }
       ); 
    }
});

jQuery.extend({
    /**
	 * 批量设置tips
	 * @param {Object} obj id:msg键值对
	 * @return {Undefined} 无返回值
	 */
    tips:function(obj){
        for(var id in obj){
            $("#"+id).tips(obj[id]);
        }
    }
});


/**
 * 获取鼠标的坐标
 */
jQuery.fn.extend({
    getMouse:function(event){
        this.mouseX = 0;// x坐标
        this.mouseY = 0;// y坐标
        var evt = event || window.event;
        if (evt.pageX) {
            this.mouseX = evt.pageX;
            this.mouseY = evt.pageY;
        }else if (evt.clientX){
           this.mouseX = evt.clientX + (document.documentElement.scrollLeft?document.documentElement.scrollLeft:document.body.scrollLeft);
           this.mouseY = evt.clientY + (document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop);
        }
        return this;
    }
});

