/******
 * Tipped: A tooltip plugin for jQuery
 * http://www.augustana.ualberta.ca/tls/help/foss/tipped
 *
 * Copyright 2010, University of Alberta
 *
 * Tipped is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Tipped is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License v2
 * along with Tipped.  If not, see <http://www.gnu.org/licenses/gpl-2.0.html>
 */
(function(a){function h(b,d,c){$tip_content.html(d);k(b,c);$tip.data("showing",true).data("original",b).show()}function k(b){var d=b.data("tipped").settings;$tip.css({left:0,top:0});l(b,d);var c=0,f=0;switch(d.position){case "mouse":c=e.pageX+d.marginX;f=e.pageY+d.marginY;break;case "absolute":c=typeof d.posX=="function"?d.posX(b):d.posX;f=typeof d.posY=="function"?d.posY(b):d.posY;break;default:f=b.offset();c=f.left+b.outerWidth()+d.marginX;f=f.top+b.outerHeight()+d.marginY;break}b=c+$tip.outerWidth(); d=f+$tip.outerHeight();var g=a(window).width()+a(window).scrollLeft()-5,i=a(window).height()+a(window).scrollTop()-5;c=b>g?c-(b-g):c;f=d>i?f-(d-i):f;$tip.css({left:c,top:f})}function l(b,d){$tip_content.css({height:"auto",width:"auto"});$tip.css({height:"auto",width:"auto"});if($tip.outerHeight()>a(window).height()){if(d.oversizeStick){a.fn.tipped.addCloser($elem);$elem.unbind("mouseout")}var c=$tip.outerHeight()-$tip_content.outerHeight(),f=$tip.outerHeight()-$tip.height();$tip.css("height",a(window).height()- f-10);$tip_content.css({height:$tip.outerHeight()-c,overflow:"auto",width:$tip.outerWidth()+20})}if($tip.outerWidth()>a(window).width()){if(d.oversizeStick){a.fn.tipped.addCloser($elem);b.unbind("mouseout")}$tip_content.css({width:a(window).width()-20,overflow:"auto",height:$tip.outerWidth()+20})}}var m={ajaxType:"POST",cache:false,cached:{},closer:"Close",delay:0,marginX:10,marginY:10,mode:"hover",oversizeStick:true,params:{},position:"element",posX:0,posY:0,source:"title",themeroller:false,throbber:"", url:""};window.$tip={};window.$tip_content={};a(document).ready(function(){$tip=a("#tipped").length?a("#tipped"):a('<div id = "tipped"><div id = "tipped_content"></div></div>').appendTo(document.body).data("showing",false);$tip_content=a("#tipped_content")});a.fn.tipped=function(b){this.each(function(){$target=a(this);b=a.extend({},m,b);$target.data("tipped",{settings:b});b.themeroller?$tip.addClass("ui-helper-hidden ui-widget ui-dialog ui-corner-all"):$tip.removeClass("ui-helper-hidden ui-widget ui-dialog ui-corner-all"); if(b.mode=="hover"){var d=undefined;$target.mouseover(function(c){var f=a(this);a.fn.tipped.removeTitle(f);d=setTimeout(function(){a.fn.tipped.initiateShow(f,c)},b.delay)}).mouseout(function(){a.fn.tipped.hideTip(a(this));clearTimeout(d)})}else if(b.mode=="click"){a.fn.tipped.addCloser($target);b.themeroller?a("#tipped-closer").addClass("ui-button ui-state-hover ui-state-default").hover(function(){a(this).addClass("ui-state-hover")},function(){a(this).removeClass("ui-state-hover")}).mousedown(function(){a(this).addClass("ui-state-active")}).mouseup(function(){a(this).removeClass("ui-state-active")}): a("#tipped-closer").removeClass("ui-button ui-state-hover ui-state-default");$target.click(function(){a.fn.tipped.initiateShow(a(this))})}});return this};a.fn.tipped.addCloser=function(b){if(a("#tipped-closer").length==0){$tip.append('<div id = "tipped-closer-wrapper"><span id = "tipped-closer">'+b.data("tipped").settings.closer+"</span>");a("#tipped-closer").click(function(){a.fn.tipped.hideTip(b)})}else a("#tipped-closer-wrapper").show()};a.fn.tipped.removeTitle=function(b){b.data("tipped").title=== undefined&&b.data("tipped",a.extend(b.data("tipped"),{title:b.attr("title")}));b.removeAttr("title").attr("title","")};a.fn.tipped.initiateShow=function(b,d){var c=b.data("tipped").settings,f=$tip.data("cached");c.mode!="click"?a("#tipped-closer-wrapper").hide():a("#tipped-closer-wrapper").show();if(c.source==="url")if(!c.cache||f===undefined||f[c.url]===undefined){var g={};if(typeof c.params=="function")g=c.params(b);else if(typeof c.params=="object")g=c.params;a.ajax({beforeSend:function(){h(b, "<img src = "+c.throbber+' alt = "Loading..." />',d)},data:g,error:function(){h(b,"Unable to retrieve contents",d)},success:function(i){$tip.data("showing")&&h(b,i,d);if(c.cache){var j={};j[c.url]=i;f=a.extend(f,j);$tip.data("cached",f)}},type:c.ajaxType,url:c.url})}else h(b,f[c.url],d);else{g="";if(c.source==="title")g=b.data("tipped").title;else if(typeof c.source=="string")g=c.source;else if(typeof c.source=="function")g=c.source(b);else if(typeof c.source=="object")g=c.source.html();h(b,g,d)}}; a.fn.tipped.hideTip=function(){$tip.data("showing",false).data("original","").hide();$tip_content.html("")};a.extend({getTrigger:function(){return $tip.data("original")}})})(jQuery);
