$(document).ready(function(){
	var BubblePopupOptions = { 
		themePath: 'jQueryBubblePopup/jquerybubblepopup-theme/',
		themeName: 	'all-ts',
		innerHtmlStyle: { color:'#FFFFFF', 'text-align':'center', background:'rgb(98,169,217)' },
		themeMargins: { total:'20px', difference:'10px' },
		tail: { align:'center', hidden:false },
		distance: '30px',
		align: 'center',
		openingSpeed: 250,
		closingSpeed: 250,
		openingDelay: 0,
		closingDelay: 0,
		dropShadow: false,
		position: 'right',
		//mouseOut: 'show',
		innerHtml: '<img src="img/loading.gif" style="border:0px; vertical-align:middle; margin-right:10px; display:inline;" />ładowanie...'
	};
	
	// dla preView'u
	$('.FotoPreView').CreateBubblePopup(BubblePopupOptions).mouseover(function(e)
	{
		var element = $(this);
		
		//alert(element.attr('rel2'));
		if(element.attr('rel2')!="")
		{
			BubblePopupOptions.position = element.attr('rel2');
			element.SetBubblePopupOptions(BubblePopupOptions);
		}
		
		url = "N_fotoPreView.php?rel="+element.attr('rel');
		$.get(url, function(data) {
			var seconds_to_wait = 2;
			function pause(){
				var timer = setTimeout(function(){
					seconds_to_wait--;
					if(seconds_to_wait > 0){
						pause();
					}else{
						element.SetBubblePopupInnerHtml(data, false); //false -> it shows new innerHtml but doesn't save it, then the script is forced to load everytime the innerHtml... 
					};
				},100);
			};pause();
		});
	})/*.hoverIntent({
		sensitivity: 3, 
		interval: 100, 
		over: function(){	$(this).animate({opacity:0.4},250); },
		timeout: 0, 
		out: function(){ $(this).animate({opacity:1},250); }
	});*/
	
	// dla userow (ranking punktacji)
	$('.UserPoints').CreateBubblePopup(BubblePopupOptions).mouseover(function(e)
	{
		var element = $(this);
		
		//alert(element.attr('rel2'));
		if(element.attr('rel2')!="")
		{
			BubblePopupOptions.position = element.attr('rel2');
			element.SetBubblePopupOptions(BubblePopupOptions);
		}
		//alert(element.attr('rel'));
		url = "N_log_punkty.php?rel="+element.attr('rel');
		$.get(url, function(data) {
			var seconds_to_wait = 2;
			function pause(){
				var timer = setTimeout(function(){
					seconds_to_wait--;
					if(seconds_to_wait > 0){
						pause();
					}else{
						element.SetBubblePopupInnerHtml(data, false); //false -> it shows new innerHtml but doesn't save it, then the script is forced to load everytime the innerHtml... 
					};
				},100);
			};pause();
		});
	})/*.hoverIntent({
		sensitivity: 3, 
		interval: 100, 
		over: function(){	$(this).animate({opacity:0.4},250); },
		timeout: 0, 
		out: function(){ $(this).animate({opacity:1},250); }
	});*/
	
	// dla prezentow za punkty dla zarejestrowanych
	$('.UserPointsFor').CreateBubblePopup(BubblePopupOptions).mouseover(function(e)
	{
		var element = $(this);
		
		//alert(element.attr('rel2'));
		if(element.attr('rel')!="")
		{
			BubblePopupOptions.position = element.attr('rel');
			element.SetBubblePopupOptions(BubblePopupOptions);
		}
		//alert(element.attr('rel'));
		url = "N_log_punktyFor.php";
		$.get(url, function(data) {
			var seconds_to_wait = 2;
			function pause(){
				var timer = setTimeout(function(){
					seconds_to_wait--;
					if(seconds_to_wait > 0){
						pause();
					}else{
						element.SetBubblePopupInnerHtml(data, false); //false -> it shows new innerHtml but doesn't save it, then the script is forced to load everytime the innerHtml... 
					};
				},100);
			};pause();
		});
	})/*.hoverIntent({
		sensitivity: 3, 
		interval: 100, 
		over: function(){	$(this).animate({opacity:0.4},250); },
		timeout: 0, 
		out: function(){ $(this).animate({opacity:1},250); }
	});*/
});
