/* Sticky Tooltip script (v1.0)
* Created: Nov 25th, 2009. This notice must stay intact for usage
* Author: Dynamic Drive at http://www.dynamicdrive.com/
* Visit http://www.dynamicdrive.com/ for full source code
*/


var stickytooltip={
        tooltipoffsets: [-500, 30], //additional x and y offset from mouse cursor for tooltips
        fadeinspeed: 200, //duration of fade effect in milliseconds
        stickybordercolors: ["black", "darkred"], //border color of tooltip depending on sticky state

        //***** NO NEED TO EDIT BEYOND HERE

        isdocked: false,

        positiontooltip:function($, $tooltip, e){
                var x=e.pageX+this.tooltipoffsets[0], y=e.pageY+this.tooltipoffsets[1]
                var tipw=$tooltip.outerWidth(), tiph=$tooltip.outerHeight(),
                x=(x+tipw>$(document).scrollLeft()+$(window).width())? x-tipw-(stickytooltip.tooltipoffsets[0]*2) : x
                $tooltip.css({left:x, top:y})
        },

        showbox:function($, $tooltip, e){
                $tooltip.fadeIn(this.fadeinspeed)
                this.positiontooltip($, $tooltip, e)
        },

        hidebox:function($, $tooltip){
                        $tooltip.stop(false, true).hide()
        },



        init:function(targetselector, tipid){
                jQuery(document).ready(function($){
                        var $targets=$(targetselector)
                        var $tooltip=$('#'+tipid).appendTo(document.body)
                        if ($targets.length==0)
                                return
                        var $alltips=$tooltip.find('div.atip')
                        stickytooltip.hidebox($, $tooltip)
                        $targets.bind('mouseenter', function(e){
                                $alltips.hide().filter('#'+$(this).attr('data-tooltip')).show()
                                stickytooltip.showbox($, $tooltip, e)
                        })
                        $targets.bind('mouseleave', function(e){
                                stickytooltip.hidebox($, $tooltip)
                        })
                        $targets.bind('mousemove', function(e){
                                        stickytooltip.positiontooltip($, $tooltip, e)
                        })
                        $tooltip.bind("mouseenter", function(){
                                stickytooltip.hidebox($, $tooltip)
                        })
                        $tooltip.bind("click", function(e){
                                e.stopPropagation()
                        })
                }) //end dom ready
        }
}

//stickytooltip.init("targetElementSelector", "tooltipcontainer")
stickytooltip.init("*[data-tooltip]", "mystickytooltip")
