/*
* jQuery Callout 0.1
* Copyright (c) 2008 David Von Lehman
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

/// <reference path="jquery-1.2.6.js" />

/* Modification : 10.07.2009 by Maxime CORMAU (usage of curvycorner for opera compatibility) */
(function(a){a.fn.callout=function(f){f=a.extend({orient:"above",align:"left",text:"",arrowHeight:4,nudgeHorizontal:0,nudgeVertical:0,arrowInset:10,cornerRadius:3,region:undefined},f||{});f.target=a(this).filter(":first");if(f.target.length===0||f.target.data("__callout")!=null){return}var i=f.content?a(f.content).html():(f.text||"");var h=a("<div/>").css({position:"absolute",visibility:"hidden"}).attr("class",f.className).html(i).prependTo("body");f=a.extend(f,{borderColor:a(h).css("border-top-color"),borderWidth:a(h).pixels("border-top-width"),backColor:a(h).css("background-color"),zIndex:parseInt(a(h).css("z-index"),0),paddingTop:h.pixels("padding-top"),paddingBottom:h.pixels("padding-bottom"),paddingLeft:h.pixels("padding-left"),paddingRight:h.pixels("padding-right")});h.width(f.width-h.pixels("padding-left")-h.pixels("padding-right")-2*f.borderWidth);if(f.zIndex===0||isNaN(f.zIndex)){f.zIndex=9999}f.mainHeight=h.height()+f.paddingTop+f.paddingBottom+2*f.borderWidth;f.height=f.mainHeight+f.arrowHeight+f.borderWidth;a(h).remove();var g=a("<div />").attr("id",a(this).attr("id")+"_callout").css({position:"absolute",display:"none","z-index":f.zIndex,"background-color":f.region?a(f.region).css("background-color"):"transparent"}).prependTo(f.region?f.region:"body");var b=a("<div/>").attr("id","contentBox").attr("class",f.className).css({"z-index":f.zIndex}).width(f.width).appendTo(g);var d=a("<div/>").attr("class",f.className).css({border:"none",width:"auto","margin-top":f.paddingTop+"px","margin-bottom":f.paddingBottom+"px","margin-left":f.paddingLeft+"px","margin-right":f.paddingRight+"px",overflow:"hidden",padding:"0 0 0 0"}).html(i).appendTo(b);if(!a.browser.msie&&!a.browser.chrome){d.height(f.mainHeight-2*f.borderWidth-f.paddingTop-f.paddingBottom)}f.targetOffset=f.target.offset();if(f.align.toLowerCase()=="right"){f.arrowLeft=f.width-f.arrowHeight-f.arrowInset-f.paddingRight;f.offsetLeft=f.targetOffset.left+f.nudgeHorizontal+f.target.width()-f.width}else{f.arrowLeft=f.arrowInset;f.offsetLeft=f.targetOffset.left+f.nudgeHorizontal}var e=a("<div />").css({position:"absolute",width:"0px",height:"0px",left:"0px",top:"0px","border-left-style":"dotted","border-left-color":"transparent","border-right-style":"dotted","border-right-color":"transparent","margin-left":f.arrowLeft+"px","z-index":f.zIndex+2,"border-width":(2*f.borderWidth+f.arrowHeight)+"px"});var c=a("<div />").css({position:"relative",left:-1*f.arrowHeight+"px",height:"0px",width:"0px","border-width":f.arrowHeight+"px","border-left-style":"dotted","border-right-style":"dotted","border-left-color":"transparent","border-right-color":"transparent","z-index":f.zIndex+1}).appendTo(e);if(f.orient.toLowerCase()=="below"){a(e).css({"border-top":"none","border-bottom":"solid "+(f.arrowHeight+2*f.borderWidth)+"px "+f.borderColor,top:-1*(3*f.borderWidth)+"px"}).prependTo(g);a(c).css({"border-top-style":"none",top:2*f.borderWidth+"px","border-bottom":f.arrowHeight+"px solid "+f.backColor});b.css("top",f.arrowHeight+f.borderWidth);f.offsetTop=f.targetOffset.top+f.target.height()+(f.paddingTop+f.paddingBottom+f.arrowHeight)+f.nudgeVertical}else{a(e).css({"border-bottom":"none","border-top-style":"solid","border-top-width":(f.arrowHeight+2*f.borderWidth)+"px","border-top-color":f.borderColor,top:f.mainHeight+(f.paddingTop+f.paddingBottom)-(4*f.borderWidth)+"px"}).appendTo(g);a(c).css({"border-bottom-style":"none",top:-1*(2*f.borderWidth+f.arrowHeight)+"px","border-top":f.arrowHeight+"px solid "+f.backColor});f.offsetTop=f.targetOffset.top-(f.mainHeight+f.arrowHeight)+f.nudgeVertical}a(g).css({left:f.offsetLeft+"px",top:f.offsetTop-(f.paddingTop+f.paddingBottom)+"px"});if(f.cornerRadius>0){a(b).corner({tl:{radius:f.cornerRadius},tr:{radius:f.cornerRadius},bl:{radius:f.cornerRadius},br:{radius:f.cornerRadius}})}if(typeof(f.showCallback)=="function"){f.showCallback.apply(g,[f])}else{g.show()}f.target.data("__callout",g);return this};a.browser.chrome=navigator.userAgent.toLowerCase().indexOf("chrome")>-1;a.fn.pixels=function(c){var d=a(this).css(c);var b=d.indexOf("px");if(b==-1){return 0}return parseFloat(d.substr(0,b))};a.fn.closeCallout=function(){return a(this).each(function(){var b=a(this).data("__callout");if(b==null){return}a.each(b,function(){a(this).remove()});a(this).data("__callout",null)})}})(jQuery);