
// (C) 2008 Przemysław Wądołowski

var fbboxto;

$(document).ready(init);

function init()
{
  $('#content').each(function(){
    $(this).children(':first').css('margin-top', 0);
    $(this).children(':last').css('margin-bottom', 0);
  });
  
  $('#menu a img').each(function()
  {
    this.srcOrig = this.src;
    this.srcOver = this.src.replace('menu_', 'menu-over_'); 
    var img = new Image();
    img.src = this.srcOver;
  }).mouseover(function()
  {
    this.src = this.srcOver; 
  }).mouseout(function()
  {
    this.src = this.srcOrig; 
  });
  
  //$('#header-home-flash, #header-szkolenia-flash').flash('flash/slogan.swf', 260, 80, { wmode:'transparent' });

	$('#fbbox').mouseover(function()
	{
			clearTimeout(fbboxto);
			$(this).stop().animate({left:0});
	});
  $('#fbbox').mouseout(function()
	{
			fbboxto = setTimeout(FBBoxHide, 200);
	});
  
}

function FBBoxHide()
{
	$('#fbbox').stop().animate({left:-205});
}

var testInterval;
var testStartLimit = 2;

function testStart()
{
  testStartLimit--;
  if ( testStartLimit > 0 )
  {
    $('#test-wstrzymaj').show();
  }
  $('#test-rozpocznij').hide();
  $('#test').show();
  testInterval = setInterval(testTick, 1000);
}

function testStop()
{
  $('#test-wstrzymaj').hide();
  $('#test-rozpocznij a').text('Kontynuuj test');
  $('#test-rozpocznij').show();
  $('#test').hide();
  clearInterval(testInterval);
}

function testInit()
{
  $('#test').hide();
  $('#test-instrukcje').append('<p id="test-rozpocznij"><a href="javascript://" onclick="testStart()" class="btn">Rozpocznij test</a></p><p id="test-wstrzymaj"><a href="javascript://" onclick="testStop()" class="btn">Wstrzymaj test</a> *test można wstrzymać tylko jeden raz</p>')
  $('#test-wstrzymaj').hide();
}

var dodatkowe5minut = false;

function testTick()
{
  var pozostalyCzas = $('#czas').text().split(':');
  var minuty = parseInt(pozostalyCzas[0], 10);
  var sekundy = parseInt(pozostalyCzas[1], 10);
  sekundy--;
  if ( sekundy < 0 )
  {
    sekundy = 59;
    minuty--;
  }
  if ( minuty < 0 )
  {
    if ( dodatkowe5minut )
    {
      clearInterval(testInterval);
      $('#test').attr('onsubmit', '').submit();
      alert('Dodatkowy czas dobiegł końca. Wyślij test.');
    }
    else
    {
      alert('Czas na wypełnienie testu dobiegł końca.\nJeśli nie wypełniłeś całego testu, masz jeszcze dodatkowe 5 minut.');
      $('#czas').text("5:00");
      dodatkowe5minut = true;
    }
    return;
  }
  if ( sekundy < 10 )
  {
    sekundy = '0' + sekundy;
  }
  $('#czas').text(minuty + ":" + sekundy);
}

function testWyslij()
{
  var zaznaczone = $('#test input[type=radio]:checked').size();
  if ( zaznaczone < 100 )
  {
    return confirm('Zaznaczyłeś ' + zaznaczone + ' ze 100 odpowiedzi.\nCzy na pewno chcesz wysłać test?');
  }
  return true;
}









