(function(F){var a=/(\.jpg|\.png|\.gif|\.bmp|\.jpeg|\.svg)$/i;F.fn.powerFloat=function(t){return F(this).each(function(){var r=F.extend({},s,t||{});var e=function(t,e){if(z.target&&z.target.css("display")!=="none"){z.targetHide()}z.s=t;z.trigger=e},i;switch(r.eventType){case"hover":{F(this).hover(function(){if(z.timerHold){z.flagDisplay=true}var t=parseInt(r.showDelay,10);e(r,F(this));if(t){if(i){clearTimeout(i)}i=setTimeout(function(){z.targetGet.call(z)},t)}else{z.targetGet()}},function(){if(i){clearTimeout(i)}if(z.timerHold){clearTimeout(z.timerHold)}z.flagDisplay=false;z.targetHold()});if(r.hoverFollow){F(this).mousemove(function(t){z.cacheData.left=t.pageX;z.cacheData.top=t.pageY;z.targetGet.call(z);return false})}break}case"click":{F(this).click(function(t){if(z.display&&z.trigger&&t.target===z.trigger.get(0)){z.flagDisplay=false;z.displayDetect()}else{e(r,F(this));z.targetGet();if(!F(document).data("mouseupBind")){F(document).bind("mouseup",function(t){var e=false;if(z.trigger){var i=z.target.attr("id");if(!i){i="R_"+Math.random();z.target.attr("id",i)}F(t.target).parents().each(function(){if(F(this).attr("id")===i){e=true}});if(r.eventType==="click"&&z.display&&t.target!=z.trigger.get(0)&&!e){z.flagDisplay=false;z.displayDetect()}}return false}).data("mouseupBind",true)}}});break}case"focus":{F(this).focus(function(){var t=F(this);setTimeout(function(){e(r,t);z.targetGet()},200)}).blur(function(){z.flagDisplay=false;setTimeout(function(){z.displayDetect()},190)});break}default:{e(r,F(this));z.targetGet();F(document).unbind("mouseup").data("mouseupBind",false)}}})};var z={targetGet:function(){if(!this.trigger){return this}var t=this.trigger.attr(this.s.targetAttr),e=typeof this.s.target=="function"?this.s.target.call(this.trigger):this.s.target;switch(this.s.targetMode){case"common":{if(e){var i=typeof e;if(i==="object"){if(e.size()){z.target=e.eq(0)}}else if(i==="string"){if(F(e).size()){z.target=F(e).eq(0)}}}else{if(t&&F("#"+t).size()){z.target=F("#"+t)}}if(z.target){z.targetShow()}else{return this}break}case"ajax":{var l=e||t;this.targetProtect=false;if(!l){return}if(!z.cacheData[l]){z.loading()}var h=new Image;h.onload=function(){var t=h.width,e=h.height;var i=F(window).width(),r=F(window).height();var s=t/e,a=i/r;if(s>a){if(t>i/2){t=i/2;e=t/s}}else{if(e>r/2){e=r/2;t=e*s}}if(t==0&&e==0&&/\.svg$/i.test(l)){t=200;if(t>i/2)t=i/2}var o='<img class="float_ajax_image" src="'+l+'"';if(t>0)o+=' width="'+t+'"';if(e>0)o+=' height="'+e+'"';o+="/>";z.cacheData[l]=true;z.target=F(o);z.targetShow()};h.onerror=function(){if(a.test(l)){z.target=F('<div class="float_ajax_error">图片加载失败。</div>');z.targetShow()}else{F.ajax({url:l,success:function(t){if(typeof t==="string"){z.cacheData[l]=true;z.target=F('<div class="float_ajax_data">'+t+"</div>");z.targetShow()}},error:function(){z.target=F('<div class="float_ajax_error">数据没有加载成功。</div>');z.targetShow()}})}};h.src=l;break}case"list":{var o='<ul class="float_list_ul">',f;if(F.isArray(e)&&(f=e.length)){F.each(e,function(t,e){var i="",r="",s,a;if(t===0){r=' class="float_list_li_first"'}if(t===f-1){r=' class="float_list_li_last"'}if(typeof e==="object"&&(s=e.text.toString())){if(a=e.href||"javascript:"){i='<a href="'+a+'" class="float_list_a">'+s+"</a>"}else{i=s}}else if(typeof e==="string"&&e){i=e}if(i){o+="<li"+r+">"+i+"</li>"}})}else{o+='<li class="float_list_null">列表无数据。</li>'}o+="</ul>";z.target=F(o);this.targetProtect=false;z.targetShow();break}case"remind":{var r=e||t;this.targetProtect=false;if(typeof r==="string"){z.target=F("<span>"+r+"</span>");z.targetShow()}break}default:{var s=e||t,i=typeof s;if(s){if(i==="string"){if(/^.[^:#\[\.,]*$/.test(s)){if(F(s).size()){z.target=F(s).eq(0);this.targetProtect=true}else if(F("#"+s).size()){z.target=F("#"+s).eq(0);this.targetProtect=true}else{z.target=F("<div>"+s+"</div>");this.targetProtect=false}}else{z.target=F("<div>"+s+"</div>");this.targetProtect=false}z.targetShow()}else if(i==="object"){if(!F.isArray(s)&&s.size()){z.target=s.eq(0);this.targetProtect=true;z.targetShow()}}}}}return this},container:function(){var t=this.s.container,e=this.s.targetMode||"mode";if(e==="ajax"||e==="remind"){this.s.sharpAngle=true}else{this.s.sharpAngle=false}if(this.s.reverseSharp){this.s.sharpAngle=!this.s.sharpAngle}if(e!=="common"){if(t===null){t="plugin"}if(t==="plugin"){if(!F("#floatBox_"+e).size()){F('<div id="floatBox_'+e+'" class="float_'+e+'_box"></div>').appendTo(F("body")).hide()}t=F("#floatBox_"+e)}if(t&&typeof t!=="string"&&t.size()){if(this.targetProtect){z.target.show().css("position","static")}z.target=t.empty().append(z.target)}}return this},setWidth:function(){var t=this.s.width;if(t==="auto"){if(this.target.get(0).style.width){this.target.css("width","auto")}}else if(t==="inherit"){this.target.width(this.trigger.width())}else{this.target.css("width",t)}return this},position:function(){if(!this.trigger||!this.target){return this}var t,s=0,a=0,e=0,i=0,o,l,r,h,f,n,c=this.target.data("height"),g=this.target.data("width"),u=F(window).scrollTop(),d=parseInt(this.s.offsets.x,10)||0,p=parseInt(this.s.offsets.y,10)||0,v=this.cacheData;if(!c){c=this.target.outerHeight();if(this.s.hoverFollow){this.target.data("height",c)}}if(!g){g=this.target.outerWidth();if(this.s.hoverFollow){this.target.data("width",g)}}t=this.trigger.offset();s=this.trigger.outerHeight();a=this.trigger.outerWidth();o=t.left;l=t.top;var w=function(){if(o<0){o=0}else if(o+s>F(window).width()){o=F(window).width()-a}},m=function(){if(l<0){l=0}else if(l+s>F(document).height()){l=F(document).height()-s}};if(this.s.hoverFollow&&v.left&&v.top){if(this.s.hoverFollow==="x"){o=v.left;w()}else if(this.s.hoverFollow==="y"){l=v.top;m()}else{o=v.left;l=v.top;w();m()}}var y=["4-1","1-4","5-7","2-3","2-1","6-8","3-4","4-3","8-6","1-2","7-5","3-2"],b=this.s.position,_=false,D;F.each(y,function(t,e){if(e===b){_=true;return}});if(!_){b="4-1"}var x=function(t){var e="bottom";switch(t){case"1-4":case"5-7":case"2-3":{e="top";break}case"2-1":case"6-8":case"3-4":{e="right";break}case"1-2":case"8-6":case"4-3":{e="left";break}case"4-1":case"7-5":case"3-2":{e="bottom";break}case"top":case"right":case"left":case"bottom":{e=t;break}}return e};var k=function(t){if(t==="5-7"||t==="6-8"||t==="8-6"||t==="7-5"){return true}return false};var H=function(t){var e=0,i=0,r=z.s.sharpAngle&&z.corner?true:false;if(t==="right"){i=o+a+g+d;if(r){i+=z.corner.width()}if(i>F(window).width()){return false}}else if(t==="bottom"){e=l+s+c+p;if(r){e+=z.corner.height()}if(e>u+F(window).height()){return false}}else if(t==="top"){e=c+p;if(r){e+=z.corner.height()}if(e>l-u){return false}}else if(t==="left"){i=g+d;if(r){i+=z.corner.width()}if(i>o){return false}}return true};D=x(b);if(this.s.sharpAngle){this.createSharp(D)}if(this.s.edgeAdjust){if(H(D)){(function(){if(k(b)){return}var t={top:{right:"2-3",left:"1-4"},right:{top:"2-1",bottom:"3-4"},bottom:{right:"3-2",left:"4-1"},left:{top:"1-2",bottom:"4-3"}};var e=t[D],i;if(e){for(i in e){if(!H(i)){b=e[i]}}}})()}else{(function(){if(k(b)){var t={"5-7":"7-5","7-5":"5-7","6-8":"8-6","8-6":"6-8"};b=t[b]}else{var e={top:{left:"3-2",right:"4-1"},right:{bottom:"1-2",top:"4-3"},bottom:{left:"2-3",right:"1-4"},left:{bottom:"2-1",top:"3-4"}};var i=e[D],r=[];for(var s in i){r.push(s)}if(H(r[0])||!H(r[1])){b=i[r[0]]}else{b=i[r[1]]}}})()}}var S=x(b),j=b.split("-")[0];if(this.s.sharpAngle){this.createSharp(S);e=this.corner.width(),i=this.corner.height()}if(this.s.hoverFollow){if(this.s.hoverFollow==="x"){r=o+d;if(j==="1"||j==="8"||j==="4"){r=o-(g-a)/2+d}else{r=o-(g-a)+d}if(j==="1"||j==="5"||j==="2"){h=l-p-c-i;n=l-i-p-1}else{h=l+s+p+i;n=l+s+p+1}f=t.left-(e-a)/2}else if(this.s.hoverFollow==="y"){if(j==="1"||j==="5"||j==="2"){h=l-(c-s)/2+p}else{h=l-(c-s)+p}if(j==="1"||j==="8"||j==="4"){r=o-g-d-e;f=o-e-d-1}else{r=o+a-d+e;f=o+a+d+1}n=t.top-(i-s)/2}else{r=o+d;h=l+p}}else{switch(S){case"top":{h=l-p-c-i;if(j=="1"){r=o-d}else if(j==="5"){r=o-(g-a)/2-d}else{r=o-(g-a)-d}n=l-i-p-1;f=o-(e-a)/2;break}case"right":{r=o+a+d+e;if(j=="2"){h=l+p}else if(j==="6"){h=l-(c-s)/2+p}else{h=l-(c-s)+p}f=o+a+d+1;n=l-(i-s)/2;break}case"bottom":{h=l+s+p+i;if(j=="4"){r=o+d}else if(j==="7"){r=o-(g-a)/2+d}else{r=o-(g-a)+d}n=l+s+p+1;f=o-(e-a)/2;break}case"left":{r=o-g-d-e;if(j=="2"){h=l-p}else if(j==="6"){h=l-(g-a)/2-p}else{h=l-(c-s)-p}f=r+e;n=l-(g-e)/2;break}}}if(i&&e&&this.corner){this.corner.css({left:f,top:n,zIndex:this.s.zIndex+1})}this.target.css({position:"absolute",left:r,top:h,zIndex:this.s.zIndex});return this},createSharp:function(t){var e,i,r="",s="";var a={left:"right",right:"left",bottom:"top",top:"bottom"},o=a[t]||"top";if(this.target){e=this.target.css("background-color");if(parseInt(this.target.css("border-"+o+"-width"))>0){i=this.target.css("border-"+o+"-color")}if(i&&i!=="transparent"){r='style="color:'+i+';"'}else{r='style="display:none;"'}if(e&&e!=="transparent"){s='style="color:'+e+';"'}else{s='style="display:none;"'}}if(!F("#floatCorner_"+t).size()){var l='<div id="floatCorner_'+t+'" class="float_corner float_corner_'+t+'">'+'<span class="corner corner_1" '+r+">◆</span>"+'<span class="corner corner_2" '+s+">◆</span>"+"</div>";F("body").append(F(l))}this.corner=F("#floatCorner_"+t);this.corner.siblings(".float_corner").remove();return this},targetHold:function(){if(this.s.hoverHold){var t=parseInt(this.s.hideDelay,10)||200;if(this.target){this.target.hover(function(){z.flagDisplay=true},function(){if(z.timerHold){clearTimeout(z.timerHold)}z.flagDisplay=false;z.targetHold()})}z.timerHold=setTimeout(function(){z.displayDetect.call(z)},t)}else{this.displayDetect()}return this},loading:function(){this.target=F('<div class="float_loading"></div>');this.targetShow();this.target.removeData("width").removeData("height");return this},displayDetect:function(){if(!this.flagDisplay&&this.display){this.targetHide();this.timerHold=null}return this},targetShow:function(){z.cornerClear();this.display=true;this.container().setWidth().position();this.target.show();if(F.isFunction(this.s.showCall)){this.s.showCall.call(this.trigger,this.target)}return this},targetHide:function(){this.display=false;this.targetClear();this.cornerClear();if(F.isFunction(this.s.hideCall)){this.s.hideCall.call(this.trigger)}this.target=null;this.trigger=null;this.s={};this.targetProtect=false;return this},targetClear:function(){if(this.target){if(this.target.data("width")){this.target.removeData("width").removeData("height")}if(this.targetProtect){this.target.children().hide().appendTo(F("body"))}this.target.unbind().hide()}},cornerClear:function(){if(this.corner){this.corner.remove()}},target:null,trigger:null,s:{},cacheData:{},targetProtect:false};F.powerFloat={};F.powerFloat.hide=function(){z.targetHide()};var s={width:"auto",offsets:{x:0,y:0},zIndex:999,eventType:"hover",showDelay:0,hideDelay:0,hoverHold:true,hoverFollow:false,targetMode:"common",target:null,targetAttr:"rel",container:null,reverseSharp:false,position:"4-1",edgeAdjust:true,showCall:F.noop,hideCall:F.noop}})(jQuery);