// $.toClipboard 
$.extend({
	toClipboard : function(str){
		var str = str || '';
		function copyToClipboard() {
		  // Create a "hidden" input
		  var aux = document.createElement("input");
		  // Assign it the value of the specified element
		  aux.setAttribute("value", str);
		  // Append it to the body
		  document.body.appendChild(aux);
		  // Highlight its content
		  aux.select();
		  // Copy the highlighted text
		  document.execCommand("copy");
		  // Remove it from the body
		  document.body.removeChild(aux); 
		}
		
		copyToClipboard(); 
	}
});

$(function(){
	$infobulle = $('<div class="wmInfobulle"></div>');
	$infobulle.css({
		color : 'white',
		background : 'rgba(0,0,0,0.96)',
		padding : '6px 12px',
		fontSize : '14px',
		border : '1px solid rgba(255,255,255,0.3)',
		borderRadius : '5px',
		textAlign : 'center',
		transform : 'translateX(-50%) translateY(16px)',
		position : 'absolute',
		left : -100000,
		top : -100000,
		opacity : 0
	});
	
	$infobulle.hover(function(e){ 
		e.preventDefault();
		e.stopPropagation(); 
	},function(e){
		e.preventDefault();
		e.stopPropagation();
	});
	
	$('body').on('mouseout','*[title],*[o-title]', function(e){
		$(this).attr('title', $(this).attr('o-title'));
		$(this).removeAttr('o-title');
		$infobulle.stop();
		$infobulle.detach();
		$infobulle.css({ opacity : 0 });
	});
	
	$('body').mousemove(function(e){
		
		$infobulle.css({  
			left : e.pageX,
			top : e.pageY
		});
	});
	
	$('body').on('click','.setFavorite[setID]', function(e){
		e.preventDefault();
		e.stopPropagation();
		$.ajax({
			url : 'scripts.php?script=setUnsetFavorite&LEVID='+$(this).attr('setID'),
			dataType : 'json',
			success : json => {
				if(json.done)
				{
					switch(parseFloat(json.done))
					{
						case 1:
							$(this).addClass('active');
						break;
						case 2:
							$(this).removeClass('active');
						break;
					}
				} 
			}
		});
	});
	
	$('body').on('click','table tr.level *', function(e){
			$('tr.level.click').removeClass('click');
			$(this).parents('tr.level').addClass('click');
	});
	
	$('body').on('mouseover','*[title]', function(e){
		e.preventDefault();
		e.stopPropagation();
		$(this).attr('o-title', $(this).attr('title'));
		$(this).removeAttr('title');
		$infobulle.appendTo($('body'));
		$infobulle.html($(this).attr('o-title'));
		$infobulle.css({ 
			position : 'absolute',
			left : e.pageX,
			top : e.pageY,
			opacity : 0
		});
		$infobulle.animate({
			opacity : 1
		},300);
		
	});
});