$(document).ready(function(){
	var ajaxLoadingStr = '<div id="ajaxLoading" style="display:none; width:auto;">Przetwarzanie danych...<br/><br/><img src="/images/ajax-loader.gif" width="32" height="32" alt="Loading..." /></div>';
	ajaxLoadingStr = ajaxLoadingStr + '<div id="greyTransparent" style="display:none;"></div>';
	jQuery("body").append(ajaxLoadingStr);

	prepareTooltip();
	prepareKomentarze();
	prepareNews();
	
   });
var newsSwitcher = [];
var newsActual = 1;
var news2Actual = 1;
var newsAuto = true;
var newsShowTime = 10000;

function prepareTooltip()
{
	if( $(".st").length > 0 )
	{
		//alert('prepare tooltip');
		
		//$("a[id^=ast]").hide();
		//init
		$("div[id^='ast']").tooltip({
			delay: 0,
			track: true,
			showURL: false,
			fade: 250,
			fixPNG: true,
			positionLeft: true,
			bodyHandler: function() {
				id = $(this).attr("id");
				id = '#'+id.substr(1);
				return $(id).html();
			}
		});
		
		
	}
}

function prepareNews()
{
	if( $("#akt1").length > 0 )
	{		
	//alert('istnieje pierwszy artykul');
	for( i=1;i<11;i++ )
	{
		it = i.toString();
		akt = "#akt"+it;
		if( $(akt).length > 0 )
		{
			newsSwitcher[i] = akt;
		}
	}
	if( newsSwitcher.length > 1 )
	{
	setTimeout("autoNewsSwitch()", newsShowTime);
	}
	else
	{
		newsAuto = false;
	}
	}
	
	if( $("#chNews1").length > 0 )
	{
		$("#chNews1").addClass("chNewsActiv");
	}
	if( $("#chNews21").length > 0 )
	{
		$("#chNews21").addClass("chNewsActiv");
	}
}

function changeNews(i)
{
	if( i > 0 && newsSwitcher[i] )
	{
		n2h = '#akt'+newsActual;
		c2h = '#chNews'+newsActual;
		newsActual = i;					
		n2s = newsSwitcher[i];
		c2s = '#chNews'+newsActual;
		$(n2h).hide();				
		$(n2s).show();
		$(c2h).removeClass("chNewsActiv");	
		$(c2s).addClass("chNewsActiv");
		//$('#bigNews').height($(n2s).height());
		//alert($(n2s).height());
		newsAuto = false;
	}
}

function changeNews2(i)
{
		n2h = '#clNews'+news2Actual;
		c2h = '#chNews2'+news2Actual;
		news2Actual = i;					
		n2s = '#clNews'+news2Actual;
		c2s = '#chNews2'+news2Actual;
		$(n2h).hide();				
		$(n2s).show();
		$(c2h).removeClass("chNewsActiv");	
		$(c2s).addClass("chNewsActiv");
		//alert( 'changeNews2 '+i +' '+n2h );
}

function autoNewsSwitch()
{
	//alert('autoNewsSwitch');
	if( newsAuto )
	{
	n2h = '#akt'+newsActual;
	c2h = '#chNews'+newsActual;
	if( newsSwitcher[newsActual+1] )
	{
		newsActual = newsActual + 1;				
	}
	else
	{
		newsActual = 1;
	}
	n2s = newsSwitcher[newsActual];
	c2s = '#chNews'+newsActual;
	//alert(n2s);
	$(n2h).hide();
	$(n2s).show();
	//$('#bigNews').height($(n2s).height());
	
	$(c2h).removeClass("chNewsActiv");	
	$(c2s).addClass("chNewsActiv");
	setTimeout("autoNewsSwitch()", newsShowTime);
	// ponowne uruchmienie za 4 sek.
	} 
}
   
function tmhide(dm, tm)
{
	$("#tm"+dm).removeClass('mw');
	$("#tm"+tm).addClass('mw');
	$("#atm"+dm).removeClass('bmw');
	$("#atm"+tm).addClass('bmw');
}

function tmshow(dm, tm)
{
	$("#tm"+tm).removeClass('mw');
	$("#tm"+dm).addClass('mw');
	$("#atm"+tm).removeClass('bmw');
	$("#atm"+dm).addClass('bmw');
}

function wl( url )
{
	window.location = url;
}
function zl( url )
{
	window.open(url);;
}

function report2moderate(id, url)
{
	//alert('id komentarza: '+id);
	tb_show('komentarz', '/ajax/modKomentarz.php?id='+id+'&url='+url+'&TB_iframe=1&width=300&height=150', false);
}

function prepareKomentarze()
{
	$(".nag").hover(function(e){$(this).find(".mod").show();},function(e){$(this).find(".mod").hide();});	
}
function login()
{	
	msgHide();
	ajaxLoadingImg();
	$.post("/a/login.php",
        {username:$("#username").val(),password:$("#password").val()},function(data){
                ajaxLoadingImgHide();
                eval(data);
        });	
}


$(document).ready(function(){
	var ajaxLoadingStr = '<div id="ajaxLoading" style="display:none; width:auto;">Przetwarzanie danych...<br/><br/><img src="/images/ajax-loader.gif" width="32" height="32" alt="Loading..." /></div>';
	ajaxLoadingStr = ajaxLoadingStr + '<div id="greyTransparent" style="display:none;"></div>';
	jQuery("body").append(ajaxLoadingStr);		
   });


function ajaxLoadingImg()
{	
	//alert($("#ajaxLoading").width());
	var aLIleft = Math.round(($(window).width()-$("#ajaxLoading").width())/2)-40;
	var aLItop = Math.round(($(window).height()-$("#ajaxLoading").height())/2)-150;
	if(aLItop < 100) aLItop = 100;
	//alert(aLItop+' - '+aLIleft);
	$("#ajaxLoading").css("top",aLItop);
	$("#ajaxLoading").css("left",aLIleft);
	$("#greyTransparent").show();
	$("#ajaxLoading").show();	
	//alert($("#ajaxLoading").css("top")+' - '+$("#ajaxLoading").css("left"));
}
function ajaxLoadingImgHide()
{
	setTimeout("ajaxLoadingImgHideDelayed()", 800);
}

function ajaxLoadingImgHideDelayed()
{
	$("#ajaxLoading").hide();
	$("#greyTransparent").hide();
}

function checkMail(x)
{	
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x)) return true;
	return false;
}

function notesError(r)
{
	$("#notesBoxInfoMsg").hide();
	$("#notesBoxErrorMsg").show();
	$("#notesBoxErrorMsg").empty().html(r);
}
function notesInfo(r)
{
	$("#notesBoxErrorMsg").hide();
	$("#notesBoxInfoMsg").show();
	$("#notesBoxInfoMsg").empty().html(r);
}
function msgHide()
{
	$("#notesBoxErrorMsg").hide();
	$("#notesBoxInfoMsg").hide();
}
