/* tippy plugin modified from tipsy plugin by Baris and Kaan */
(function($) {
    $.fn.showtip = function(opts) {
		
        opts = $.extend({fade: false, position: 'u', text:'', scroll:false }, opts || {});
		
        var tip = null;
		$("#tippy-" + $(this).attr('id')).remove();
        tip = $('<div class="tippy" id="tippy-'+ $(this).attr('id') +'"><div class="tippy-inner">' + opts.text + '</div></div>');
        tip.css({position: 'absolute', zIndex: 5000});

        var pos = $.extend({}, $(this).offset(), {width: $(this).width(), height: $(this).height()});
        tip.css({top: 0, left: 0, visibility: 'hidden', display: 'block'}).appendTo(document.body);

			/*fix for ie6s absent max-width property. fixed to 260px brutally. - Baris*/
			if($.browser.msie && $.browser.version == 6 && tip.width() > 210){tip.width(210)};

        var actualWidth = tip[0].offsetWidth, actualHeight = tip[0].offsetHeight;
            
        switch (opts.position.charAt(0)) {
            case 'd':
                tip.css({top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2}).addClass('tippy-north');
                break;
            case 'u':
                tip.css({top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2}).addClass('tippy-south');
                break;
            case 'l':
                tip.css({top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth}).addClass('tippy-east');
                break;
            case 'r':
                tip.css({top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width}).addClass('tippy-west');
                break;
        }

        if (opts.fade) {
            tip.css({opacity: 0, display: 'block', visibility: 'visible'}).animate({opacity: 1});
        } else {
            tip.css({visibility: 'visible'});
        }
        
        if (opts.scroll) {
			$.scrollTo("#tippy-" + $(this).attr('id'),500);
        }
        

    };
	
    $.fn.removetip = function() {
        $('#tippy-'+$(this).attr('id')).remove();
    };
})(jQuery);
