(function(p){p.cluetip={version:"1.0.3"};
var t,s,r,o,q,l,u,n;
p.fn.cluetip=function(a,b){if(typeof a=="object"){b=a;
a=null
}if(a=="destroy"){return this.unbind(".cluetip")
}return this.each(function(e){var x=this,W=p(this);
var S=p.extend(true,{},p.fn.cluetip.defaults,b||{},p.metadata?W.metadata():p.meta?W.data():{});
var ak=false;
var ah=+S.cluezIndex;
W.data("thisInfo",{title:x.title,zIndex:ah});
var an=false,X=0;
if(!p("#cluetip").length){p(['<div id="cluetip">','<div id="cluetip-outer">','<h3 id="cluetip-title"></h3>','<div id="cluetip-inner"></div>',"</div>",'<div id="cluetip-extra"></div>','<div id="cluetip-arrows" class="cluetip-arrows"></div>',"</div>"].join(""))[m](v).hide();
t=p("#cluetip").css({position:"absolute"});
r=p("#cluetip-outer").css({position:"relative",zIndex:ah});
s=p("#cluetip-inner");
o=p("#cluetip-title");
q=p("#cluetip-arrows");
l=p('<div id="cluetip-waitimage"></div>').css({position:"absolute"}).insertBefore(t).hide()
}var ag=(S.dropShadow)?+S.dropShadowSteps:0;
if(!u){u=p([]);
for(var T=0;
T<ag;
T++){u=u.add(p("<div></div>").css({zIndex:ah-1,opacity:0.1,top:1+T,left:1+T}))
}u.css({position:"absolute",backgroundColor:"#000"}).prependTo(t)
}var h=W.attr(S.attribute),ao=S.cluetipClass;
if(!h&&!S.splitTitle&&!a){return true
}if(S.local&&S.localPrefix){h=S.localPrefix+h
}if(S.local&&S.hideLocal){p(h+":first").hide()
}var ad=parseInt(S.topOffset,10),y=parseInt(S.leftOffset,10);
var al,ac,Z=isNaN(parseInt(S.height,10))?"auto":(/\D/g).test(S.height)?S.height:S.height+"px";
var ae,U,z,R,g,am;
var N=parseInt(S.width,10)||275,V=N+(parseInt(t.css("paddingLeft"),10)||0)+(parseInt(t.css("paddingRight"),10)||0)+ag,O=this.offsetWidth,Q,f,ai,i,aj;
var k;
var d=(S.attribute!="title")?W.attr(S.titleAttribute):"";
if(S.splitTitle){if(d==undefined){d=""
}k=d.split(S.splitTitle);
d=k.shift()
}if(S.escapeTitle){d=d.replace(/&/g,"&amp;").replace(/>/g,"&gt;").replace(/</g,"&lt;")
}var c;
var w=function(B){if(!S.onActivate(W)){return false
}an=true;
t.removeClass().css({width:N});
if(h==W.attr("href")){W.css("cursor",S.cursor)
}if(S.hoverClass){W.addClass(S.hoverClass)
}U=z=W.offset().top;
Q=W.offset().left;
i=B.pageX;
g=B.pageY;
if(x.tagName.toLowerCase()!="area"){ae=p(document).scrollTop();
aj=p(window).width()
}if(S.positionBy=="fixed"){f=O+Q+y;
t.css({left:f})
}else{f=(O>Q&&Q>V)||Q+O+V+y>aj?Q-V-y:O+Q+y;
if(x.tagName.toLowerCase()=="area"||S.positionBy=="mouse"||O+V>aj){if(i+20+V>aj){t.addClass(" cluetip-"+ao);
f=(i-V-y)>=0?i-V-y-parseInt(t.css("marginLeft"),10)+parseInt(s.css("marginRight"),10):i-(V/2)
}else{f=i+y
}}var C=f<0?B.pageY+ad:B.pageY;
t.css({left:(f>0&&S.positionBy!="bottomTop")?f:(i+(V/2)>aj)?aj/2-V/2:Math.max(i-(V/2),0),zIndex:W.data("thisInfo").zIndex});
q.css({zIndex:W.data("thisInfo").zIndex+1})
}ac=p(window).height();
if(a){if(typeof a=="function"){a=a(x)
}s.html(a);
j(C)
}else{if(k){var H=k.length;
s.html(k[0]);
if(H>1){for(var G=1;
G<H;
G++){s.append('<div class="split-body">'+k[G]+"</div>")
}}j(C)
}else{if(!S.local&&h.indexOf("#")!=0){if(/\.(jpe?g|tiff?|gif|png)$/i.test(h)){s.html('<img src="'+h+'" alt="'+d+'" />');
j(C)
}else{if(ak&&S.ajaxCache){s.html(ak);
j(C)
}else{var K=S.ajaxSettings.beforeSend,E=S.ajaxSettings.error,F=S.ajaxSettings.success,D=S.ajaxSettings.complete;
var J={cache:false,url:h,beforeSend:function(L){if(K){K.call(x,L,t,s)
}r.children().empty();
if(S.waitImage){l.css({top:g+20,left:i+20,zIndex:W.data("thisInfo").zIndex-1}).show()
}},error:function(L,M){if(an){if(E){E.call(x,L,M,t,s)
}else{s.html("<i>sorry, the contents could not be loaded</i>")
}}},success:function(L,M){ak=S.ajaxProcess.call(x,L);
if(an){if(F){F.call(x,L,M,t,s)
}s.html(ak)
}},complete:function(L,M){if(D){D.call(x,L,M,t,s)
}n=p("#cluetip-inner img").length;
if(n&&!p.browser.opera){p("#cluetip-inner img").bind("load error",function(){n--;
if(n<1){l.hide();
if(an){j(C)
}}})
}else{l.hide();
if(an){j(C)
}}}};
var A=p.extend(true,{},S.ajaxSettings,J);
p.ajax(A)
}}}else{if(S.local){var I=p(h+(/#\S+$/.test(h)?"":":eq("+e+")")).clone(true).show();
s.html(I);
j(C)
}}}}};
var j=function(F){t.addClass("cluetip-"+ao);
if(S.truncate){var A=s.text().slice(0,S.truncate)+"...";
s.html(A)
}function B(){}d?o.show().html(d):(S.showTitle)?o.show().html("&nbsp;"):o.hide();
if(S.sticky){var E=p('<div id="cluetip-close"><a href="#">'+S.closeText+"</a></div>");
(S.closePosition=="bottom")?E.appendTo(s):(S.closePosition=="title")?E.prependTo(o):E.prependTo(s);
E.bind("click.cluetip",function(){P();
return false
});
if(S.mouseOutClose){if(p.fn.hoverIntent&&S.hoverIntent){t.hoverIntent({over:B,timeout:S.hoverIntent.timeout,out:function(){E.trigger("click.cluetip")
}})
}else{t.hover(B,function(){E.trigger("click.cluetip")
})
}}else{t.unbind("mouseout")
}}var D="";
r.css({zIndex:W.data("thisInfo").zIndex,overflow:Z=="auto"?"visible":"auto",height:Z});
al=Z=="auto"?Math.max(t.outerHeight(),t.height()):parseInt(Z,10);
R=z;
am=ae+ac;
if(S.positionBy=="fixed"){R=z-S.dropShadowSteps+ad
}else{if((f<i&&Math.max(f,0)+V>i)||S.positionBy=="bottomTop"){if(z+al+ad>am&&g-ae>al+ad){R=g-al-ad;
D="top"
}else{R=g+ad;
D="bottom"
}}else{if(z+al+ad>am){R=(al>=ac)?ae:am-al-ad
}else{if(W.css("display")=="block"||x.tagName.toLowerCase()=="area"||S.positionBy=="mouse"){R=F-ad
}else{R=z-S.dropShadowSteps
}}}}if(D==""){f<Q?D="left":D="right"
}t.css({top:R+"px"}).removeClass().addClass("clue-"+D+"-"+ao).addClass(" cluetip-"+ao);
if(S.arrows){var C=(z-R-S.dropShadowSteps);
q.css({top:(/(left|right)/.test(D)&&f>=0&&C>0)?C+"px":/(left|right)/.test(D)?0:""}).show()
}else{q.hide()
}u.hide();
t.hide()[S.fx.open](S.fx.open!="show"&&S.fx.openSpeed);
if(S.dropShadow){u.css({height:al,width:N,zIndex:W.data("thisInfo").zIndex-1}).show()
}if(p.fn.bgiframe){t.bgiframe()
}if(S.delayedClose>0){X=setTimeout(P,S.delayedClose)
}S.onShow.call(x,t,s)
};
var Y=function(A){an=false;
l.hide();
if(!S.sticky||(/click|toggle/).test(S.activation)){P();
clearTimeout(X)
}if(S.hoverClass){W.removeClass(S.hoverClass)
}};
var P=function(){r.parent().hide().removeClass();
S.onHide.call(x,t,s);
W.removeClass("cluetip-clicked");
if(d){W.attr(S.titleAttribute,d)
}W.css("cursor","");
if(S.arrows){q.css({top:""})
}};
p(document).bind("hideCluetip",function(A){P()
});
if((/click|toggle/).test(S.activation)){W.bind("click.cluetip",function(A){if(t.is(":hidden")||!W.is(".cluetip-clicked")){w(A);
p(".cluetip-clicked").removeClass("cluetip-clicked");
W.addClass("cluetip-clicked")
}else{Y(A)
}this.blur();
return false
})
}else{if(S.activation=="focus"){W.bind("focus.cluetip",function(A){w(A)
});
W.bind("blur.cluetip",function(A){Y(A)
})
}else{W.bind("click.cluetip",function(){if(W.attr("href")&&W.attr("href")==h&&!S.clickThrough){return false
}});
var af=function(C){if(S.tracking==true){var B=f-C.pageX;
var A=R?R-C.pageY:z-C.pageY;
W.bind("mousemove.cluetip",function(D){t.css({left:D.pageX+B,top:D.pageY+A})
})
}};
if(p.fn.hoverIntent&&S.hoverIntent){W.hoverIntent({sensitivity:S.hoverIntent.sensitivity,interval:S.hoverIntent.interval,over:function(A){w(A);
af(A)
},timeout:S.hoverIntent.timeout,out:function(A){Y(A);
W.unbind("mousemove.cluetip")
}})
}else{W.bind("mouseenter.cluetip",function(A){w(A);
af(A)
}).bind("mouseleave.cluetip",function(A){Y(A);
W.unbind("mousemove.cluetip")
})
}W.bind("mouseenter.cluetip",function(A){W.attr("title","")
}).bind("mouseleave.cluetip",function(A){W.attr("title",W.data("thisInfo").title)
})
}}})
};
p.fn.cluetip.defaults={width:275,height:"auto",cluezIndex:97,positionBy:"auto",topOffset:15,leftOffset:15,local:false,localPrefix:null,hideLocal:true,attribute:"rel",titleAttribute:"title",splitTitle:"",escapeTitle:false,showTitle:true,cluetipClass:"default",hoverClass:"",waitImage:true,cursor:"help",arrows:false,dropShadow:true,dropShadowSteps:6,sticky:false,mouseOutClose:false,activation:"hover",clickThrough:false,tracking:false,delayedClose:0,closePosition:"top",closeText:"Close",truncate:0,fx:{open:"show",openSpeed:""},hoverIntent:{sensitivity:3,interval:50,timeout:0},onActivate:function(a){return true
},onShow:function(a,b){},onHide:function(a,b){},ajaxCache:true,ajaxProcess:function(a){a=a.replace(/<(script|style|title)[^<]+<\/(script|style|title)>/gm,"").replace(/<(link|meta)[^>]+>/g,"");
return a
},ajaxSettings:{dataType:"html"},debug:false};
var m="appendTo",v="body";
p.cluetip.setup=function(a){if(a&&a.insertionType&&(a.insertionType).match(/appendTo|prependTo|insertBefore|insertAfter/)){m=a.insertionType
}if(a&&a.insertionElement){v=a.insertionElement
}}
})(jQuery);
