/**
 * 
 * @author wstuckey
 * 
 * Based on 
 * 		JTip
 * 		By Cody Lindley (http://www.codylindley.com)
 * 		Under an Attribution, Share Alike License
 * 		JTip is built on top of the very light weight jquery library.
 */

(function($){
	
	// create a more jQuery way to initialize the plugin.
	// also provides more flexibility in the anchor selector.
	$.fn.tooltip = function(settings){
		var settings = $.extend({
    			width: 150
    		}, settings);
		return this.bind('mouseover', function(e){
			JT.create(this, settings.width)
			if (!$.browser.safari) {
				$(this).bind("mousemove", function(e){
					JT.show(e);
				});
			} else {
				JT.show(e);
			}			
		}).bind('mouseout', function(){
	        $("#JT").remove();
		}).bind('click', function(){
			return false;
		}).addClass('jTip');
	}
	var JT = {
		create: function (o, width) {
			var hash = o.hash;
			var title = (o.title == false) ? "&nbsp;" : o.title;
			var toolContainer = $("#tc");
			$("<div id='JT' style='width:"+width*1+"px'><div id='JT_arrow_left'></div><div id='JT_copy'><div class='JT_loader'><div></div></div>")
				.appendTo("body")
				.hide();
			$('#JT_copy').html($( hash, toolContainer).html());
		},
		show: function(e) {
			var de = document.documentElement;
			var clickElementy = (e.pageY || e.clientY + de.scrollTop) - 35; //set y position	
			var $jt =  $("#JT");	
			var arrowOffset = 40;
			var clickElementx = e.clientX + arrowOffset; //set x position.
			$jt.css({left: clickElementx+"px", top: clickElementy+"px"})
				.show();
		}
	}
	cookie_set = function(name, value){
        var domain = '; domain=' + window.location.hostname;
        document.cookie = [name, '=', encodeURIComponent(value), "; path=/", domain].join('');
    }
	
})($);


