/* sIFR inicializace */
var ffont = { src: '/images/sifr.swf',ratios: [7,1.32,11,1.31,13,1.24,14,1.25,19,1.23,27,1.2,34,1.19,42,1.18,47,1.17,48,1.18,69,1.17,74,1.16,75,1.17,1.16] };
/**/
//sIFR.delayCSS  = true;
sIFR.activate(ffont);
/**/


var formValues = new Array();

$(function() {
	$('.lightbox a, a.lightbox').lightBox({fixedNavigation:false, txtImage:'Obrázek', txtOf:'z' });
});

/*******************************************
 *
 *  on DOM ready
 *
 ********************************************/
$(document).ready(function()
{

  jQuery.easing.def = 'easeOutCubic';

  // fix eolas
  var objects = document.getElementsByTagName("object");
  for (var i=0; i<objects.length; i++)
  {
    objects[i].outerHTML = objects[i].outerHTML;
  }

  var colors = new Array();
  colors[1] = '#237249';
  colors[2] = '#237249';

  var fonts = new Array();
  fonts[1] = '26px';
	fonts[2] = '18px';
	fonts[3] = '16px';

  /* sIFR replace */
	
  sIFR.replace(ffont,
  {
    selector: 'h2.sifr',
    css:
      [
      '.sIFR-root { font-size: '+fonts[1]+'; font-weight: normal; color: '+colors[1]+'; }',
      'a { color: '+colors[1]+'; text-decoration: none; }',
      'a:link { color: '+colors[1]+'; }',
      'a:visited { color: '+colors[1]+'; }',
      'a:hover { color: '+colors[2]+'; }',
      'a:focus { color: '+colors[2]+'; }',
      'a:active { color: '+colors[2]+'; }'
      ],
    wmode: 'transparent',
    fitExactly: true
  }); 
	
	sIFR.replace(ffont,
  {
    selector: '#aktuality h3.sifr',
    css:
      [
      '.sIFR-root { font-size: '+fonts[3]+'; font-weight: bold; color: '+colors[1]+'; text-transform: uppercase;}',
      'a { color: '+colors[1]+'; text-decoration: none; }',
      'a:link { color: '+colors[1]+'; }',
      'a:visited { color: '+colors[1]+'; }',
      'a:hover { color: '+colors[2]+'; }',
      'a:focus { color: '+colors[2]+'; }',
      'a:active { color: '+colors[2]+'; }'
      ],
    wmode: 'transparent',
    fitExactly: true
  });
	
	sIFR.replace(ffont,
  {
    selector: '#submenu h3.sifr',
    css:
      [
      '.sIFR-root { font-size: '+fonts[3]+'; font-weight: bold; color: '+colors[1]+'; text-transform: uppercase;}',
      'a { color: '+colors[1]+'; text-decoration: none; }',
      'a:link { color: '+colors[1]+'; }',
      'a:visited { color: '+colors[1]+'; }',
      'a:hover { color: '+colors[2]+'; }',
      'a:focus { color: '+colors[2]+'; }',
      'a:active { color: '+colors[2]+'; }'
      ],
    wmode: 'transparent',
    fitExactly: true
  });
	
	sIFR.replace(ffont,
  {
    selector: '#message h3.sifr',
    css:
      [
      '.sIFR-root { font-size: '+fonts[3]+'; font-weight: bold; color: '+colors[1]+'; text-transform: uppercase;}',
      'a { color: '+colors[1]+'; text-decoration: none; }',
      'a:link { color: '+colors[1]+'; }',
      'a:visited { color: '+colors[1]+'; }',
      'a:hover { color: '+colors[2]+'; }',
      'a:focus { color: '+colors[2]+'; }',
      'a:active { color: '+colors[2]+'; }'
      ],
    wmode: 'transparent',
    fitExactly: true
  });
	
	sIFR.replace(ffont,
  {
    selector: 'h3.sifr',
    css:
      [
      '.sIFR-root { font-size: '+fonts[2]+'; font-weight: normal; color: '+colors[1]+'; }',
      'a { color: '+colors[1]+'; text-decoration: none; }',
      'a:link { color: '+colors[1]+'; }',
      'a:visited { color: '+colors[1]+'; }',
      'a:hover { color: '+colors[2]+'; }',
      'a:focus { color: '+colors[2]+'; }',
      'a:active { color: '+colors[2]+'; }'
      ],
    wmode: 'transparent',
    fitExactly: true
  });






  /* slide */
  $('#slideArea').after('<span id="slideRight" class="slider"><a href="#"><!-- --></a></span><span id="slideLeft" class="slider"><a href="#"><!-- --></a></span>');

  var slideMarginLeft    = 0;
  var maxSlideMarginLeft = 0;
  var itemWidth          = parseInt($('#slideArea .item').css('margin-left')) + parseInt($('#slideArea .item').css('margin-right')) +
                           parseInt($('#slideArea .item').css('border-left-width')) + parseInt($('#slideArea .item').css('border-right-width')) +
                           parseInt($('#slideArea .item').css('padding-left')) + parseInt($('#slideArea .item').css('padding-right')) +
                           $('#slideArea .item').width();
  var countItem          = 0;

// TODO: počítat z šířky slideArea a itemWidth počet zobrazených položek

  $('#slideRight a').click(
    function()
    {
      if ( slideMarginLeft > maxSlideMarginLeft )
      {
        slideMarginLeft -= itemWidth;
        $('.items').animate({marginLeft: slideMarginLeft }, slowEffectTime);
//         $('#slideRight').removeClass('hidden');
      }
      if ( slideMarginLeft <= maxSlideMarginLeft )
      {
        $('#slideRight a').fadeOut('normal');
      }
      if ( slideMarginLeft < 0 )
      {
        $('#slideLeft a').fadeIn('normal');
      }
      return false;
    }
  );

  $('#slideLeft a').click(
    function()
    {
      if ( slideMarginLeft < 0 )
      {
        slideMarginLeft += itemWidth;
        $('.items').animate({marginLeft: slideMarginLeft }, slowEffectTime);
      }
      if ( slideMarginLeft >= 0 )
      {
        $('#slideLeft a').fadeOut('normal');
      }
      if ( slideMarginLeft > maxSlideMarginLeft )
      {
        $('#slideRight a').fadeIn('normal');
      }
      return false;
    }
  );

  countItem = $('.item').length;

  maxSlideMarginLeft = ( -itemWidth * ( countItem - 3 ) );

  if ( slideMarginLeft >= 0 )
  {
    $('#slideLeft a').hide();
  }

  if ( maxSlideMarginLeft >= 0 || countItem == 0 )
  {
    $('#slideRight a').hide();
  }

  /* change events */
  $('select').change(
    function()
    {
      $(this).parents('form').submit();
    }
  );

  /* focus events */
  $('#search-string').focus(
    function()
    {
      var itemID = $(this).attr('id');

      if ( formValues[itemID] == null || $(this).val() == formValues[itemID] )
      {
        formValues[itemID] = $(this).val();
        $(this).val('');
      }
    }
  );

  /* onblur events */
  $('#search-string').blur(
    function()
    {
      if( $(this).val() == '' )
      {
        $(this).val(formValues[$(this).attr('id')]);
      }
    }
  );

});

