/*    ChillTip Version 1.0
    by Christopher Hill - http://www.chillwebdesigns.co.uk/
    Last Modification: 01/05/10
    
    For more information, visit:
    http://www.chillwebdesigns.co.uk/chilltip.html
    
    Licensed under the Creative Commons Attribution 2.5 License - http://creativecommons.org/licenses/by/2.5/
    - Free for use in both personal and commercial projects
    - Attribution requires leaving author name, author link, and the license info intact
*/

$(document).ready(function(){
                           
// ChillTip Version 1.0 - add class="chillTip" and title="This is a Chilltip" tag to img,a,span attributes. 
                           
$('.chillTip').live('mouseover',function(e){                                  
    var title = $(this).attr("title");
    if(title == "" || title == undefined) return;
    
    $('body').append('<div class="chillTitle"></div>');
    $('.chillTitle').html('<p>' + title + '</p>');
    // Change the value below to change opacity of the ChillTip from 0-100 or 0.0-1.0
    $('.chillTitle').css("filter:","alpha(opacity=85)")
        .css("-moz-opacity","0.92")
        .css("-khtml-opacity", "0.92")
        .css("opacity", "0.92");  
    this.tip = this.title;
    this.title = "";
    setChillPosition('.chillTitle', e);
    $('.chillTitle').show();//fadeIn(50);  //ChillTip fade in time (recommended 500ms)
    if($.browser.msie) 
    {
        //$('.chillTitle').corner();
    } 
    });

$('.chillTip').live('mousemove',function(e)
{
    setChillPosition('.chillTitle', e);
    });

$('.chillTip').live('mouseout',function(){
    //$('.chillTitle').fadeOut(500, function() {$(this).remove()});
    $('.chillTitle').remove();
    this.title = this.tip;
    });

});
function setChillPosition(selector, e)
{
    var border_top = $(window).scrollTop(), 
        border_right = $(window).width(),
        offsetH = -30, 
        offsetV = 15,
        left_pos,
        top_pos;
    if(    border_right - (offsetH *2) >= $(selector).width() + e.pageX)
        {left_pos = e.pageX + offsetV;}
    else
        {left_pos = border_right - $(selector).width() - offsetV;}
    
    if(border_top + (offsetH *2 ) >= e.pageY - $(selector).height())
        {top_pos = border_top + offsetH;}
    else
        {top_pos = e.pageY-$(selector).height( )- offsetH;}    
        
    $(selector).css({left:left_pos, top:top_pos});
}

