function showLoader(selector)
{
    $(selector).children().remove();
    $(selector).html('<img id="loader" src="./static/img/loader_medium.gif" width="40" height="40" alt="ładowanie..." />');
}

function hideLoader(selector)
{
    $(selector).children().remove();
}

function loadHtml(link, output_selector)
{
    $.ajax({
	type: "GET",
	url: link,
	timeout: 30000,

	beforeSend: function()
	{
	    showLoader(output_selector);
	},
	error: function()
	{
	    $(output_selector).text('Błąd!');
	},
	success: function(response)
	{
	    hideLoader(output_selector);
	    $(output_selector).html(response);
	}
    });
}

function submitForm(form_selector, output_selector)
{
    var url = $(form_selector).attr('action');
    var method = $(form_selector).attr('method');

    $(form_selector).ajaxSubmit({
	url : url,
	method : method,

	beforeSubmit : function(){
	    showLoader(output_selector);
	},
	error: function(){
	    $(output_selector).text('Błąd!');
	},
	success : function(response)
	{
	    hideLoader(output_selector);
	    $(output_selector).html(response);
	}
    });

    return false;
}

function showInfo(img)
{
    var id_field = "#info_"+$(img).attr('id');
    if ( $(id_field).is(':visible') ) {
	$(id_field).fadeOut('slow');
    }
    else
	$(id_field).fadeIn('slow');
}

(function ($) {
    $.fn.vAlign = function() {
	return this.each(function(i){
	    var ah = $(this).height();
	    var ph = $(this).parent().height();
	    var mh = (ph - ah) / 2;
	    $(this).css('padding-top', mh);
	});
    };
})(jQuery);


/*pixTable[0] = new Array();
pixTable[0]['name'] = 'counter';
pixTable[0]['address'] = 'Narzedzia.html';
pixTable[1] = new Array();
pixTable[1]['name'] = 'book';
pixTable[1]['address'] = 'Narzedzia.html';
pixTable[2] = new Array();
pixTable[2]['name'] = 'survey';
pixTable[2]['address'] = 'Narzedzia.html';
pixTable[3] = new Array();
pixTable[3]['name'] = 'stats';
//pixTable[3]['address'] = 'Statystyki.html'*/

//'counter', 'book', 'stats', 'survey
var iCurrentKey = 0;
var lastChange = '';
$(document).ready(function()
{


	$('#stat24_client:checkbox').click(
	    function()
	    {
			var buff = $('input#email');
			if($(this).is(':checked'))
			{
				$('#email_label').text('Login stat24');
				//nie ma @
				if(buff.val().indexOf('@') === -1 && buff.val() != '')
				{
				buff.val(buff.val() + '@stat24.com');
				}

				buff.change(function()
				{
				//nie ma @
				if($(this).val().indexOf('@') === -1)
				{
					$(this).val($(this).val() + '@stat24.com');
				}
				});
			}
			else
			{
				$('#email_label').text('E-mail');
				if(buff.val().indexOf('@stat24.com') !== -1)
				{
				buff.val(buff.val().replace('@stat24.com', ''));
				}
			}
	    });

    /* główne jsy */

    $(".form_comm_err p").vAlign();
    $(".form_comm_ok p").vAlign();

    $(".example").hide();
    $('#main_menu li').mouseover( function(){
	var div = $(this).attr('id');
	//	$("#main2_right_content").css("text-indent","-9999px");
	$("#main_menu li").removeClass();
	$(this).addClass(div+"_a_active");
	if(typeof lastChange != undefined)
	{
	    if(div == lastChange)
		return false;
	}
	var output_selector = "#main_top";
	var cache = $("#main_"+div).html();
	$(output_selector).fadeOut(0,function(){
	    lastChange = div;
	    $(output_selector).html(cache);
	    $(output_selector).fadeIn(0);
	    sIFR.replace(myriad, {
		selector: '.main_small_top_right_head',
		css: '.sIFR-root { color: #333; font-size: 25px; }',
		wmode: 'transparent'
	    });

	    sIFR.replace(myriad, {
		selector: '.main_top_header',
		css: '.sIFR-root { color: #333; font-size: 20px; }',
		wmode: 'transparent'
	    });
	//	    $("#main2_right_content").css("text-indent","0px");
	});
	return false;
    }).mouseout( function(){
	if(typeof remember != 'undefined' )
	{
	    $("#main_menu li").removeClass();
	    $("#"+remember).addClass(remember+"_a_active");
	}
    });

    $('a.captcha_reload').click(function()
    {
	var c_date = new Date();
	$('#captcha').attr('src', 'captcha.html?' + c_date.getTime());
    });

    // POMOC
    $('img.toggle').click(function() {
	var answer = $(this).attr('rel');

	if($(this).hasClass('collapsed'))
	{
	    $(this).attr('src', './static/img/help_minus.png');
	    $(this).removeClass('collapsed');
	    $(this).addClass('expanded');
	    $("#"+answer).toggle();
	}
	else
	{
	    $(this).attr('src', './static/img/help_plus.png');
	    $(this).removeClass('expanded');
	    $(this).addClass('collapsed');
	    $("#"+answer).toggle();
	}
    });

    $('#coda-slider-2').codaSlider({
	autoSlide: true,
	autoSlideInterval: 10000,
	autoSlideStopWhenClicked: true
    });

    $("#tabs").tabs().addClass('ui-tabs-vertical ui-helper-clearfix');
    $("#tabs li").removeClass('ui-corner-top').addClass('ui-corner-left');

//    $('#main_menu li').mouseover( function(){
//	var div = $(this).attr('id');
//	//	$("#main2_right_content").css("text-indent","-9999px");
//	$("#main_menu li").removeClass();
//	$(this).addClass(div+"_a_active");
//	if(typeof lastChange != undefined)
//	{
//	    if(div == lastChange)
//		return false;
//	}
//	var output_selector = "#main_top";
//	var cache = $("#main_"+div).html();
//	$(output_selector).fadeOut(0,function(){
//	    lastChange = div;
//	    $(output_selector).html(cache);
//	    $(output_selector).fadeIn(0);
//	});
//	return false;
//    }).mouseout( function(){
//	if(typeof remember != 'undefined' )
//	{
//	    $("#main_menu li").removeClass();
//	    $("#"+remember).addClass(remember+"_a_active");
//	}
//    });


	$('.tooltip_help').mouseover(function(e)
	{
		var tip = $(this).attr('title');
		$(this).attr('title','');
		$(this).append('<div id="tooltip"><div class="tipHeader"></div><div class="tipBody">' + tip + '</div><div class="tipFooter"></div></div>');
		$('#tooltip').css('top', e.pageY );
		$('#tooltip').css('left', e.pageX + 25 );
	}).mouseout(function()
	{
		$(this).attr('title',$('.tipBody').html());
		$(this).children('div#tooltip').remove();
	});

        if($.client.os=="Linux"||$.client.os=="Mac"){
            $("#full_main_mail_top_content p,#full_main_shop_top_content p,#full_main_blog_top_content p").css("font-size",9);
        }

});



