/*
 *  JS Document
 *  @author:  Petr /Peggy/ Sládek
 *  @web:     FotbalekProVas.cz
 */
         
    
var textarea_default = 'Nechte nám vzkaz a kontakt na Vás a my se ozvem';    
var mycarousel_itemList = [
    {url: 'fotos/homepage/01.jpg', title: 'Obrázek 01'},
    {url: 'fotos/homepage/02.jpg', title: 'Obrázek 02'},
    {url: 'fotos/homepage/03.jpg', title: 'Obrázek 03'},
    {url: 'fotos/homepage/04.jpg', title: 'Obrázek 04'},
    {url: 'fotos/homepage/05.jpg', title: 'Obrázek 05'}
];

function initCallback(carousel)
{   
    carousel.startAuto();
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    }); 
};  
function itemVisibleInCallback(carousel, item, i, state, evt)
{
    var idx = carousel.index(i, mycarousel_itemList.length);
    carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[idx - 1]));
};

function itemVisibleOutCallback(carousel, item, i, state, evt)
{
    carousel.remove(i);
};

function mycarousel_getItemHTML(item)
{
    return '<img src="' + item.url + '" width="234" height="178" alt="' + item.title + '" />';
};



$(document).ready(function () {
    $('#mycarousel').jcarousel({
        wrap: 'circular',
        scroll: 1,
        auto: 2,
        animation: 2000,
        initCallback: initCallback,
        buttonNextEvent: null,
        buttonPrevEvent: null,
        itemVisibleInCallback: {onBeforeAnimation: itemVisibleInCallback},
        itemVisibleOutCallback: {onAfterAnimation: itemVisibleOutCallback}      
    });
    
    $("a[rel=gallery]").fancybox({
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'titlePosition' 	: 'over',
				'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
				    return '<span id="fancybox-title-over">' +  (currentIndex + 1) + ' / ' + currentArray.length + '</span>';
				}
			});
			
			$(document).pngFix();

      $('#a-tisk').click(function () {
        window.print();
        return false;
      });
      
      $("#frm-text").text(textarea_default);
      
      $("#frm-text").focus(function() {
       if ($(this).text() == textarea_default) {
         $(this).text('');
        };
      });
      
      $("#frm-text").blur(function() {
        if($(this).text() == '') {
          $(this).text(textarea_default);
        };
      });
      
      
      
      // pravidla

      function viewPravidloId(id) { 
        $("#pravidla-obsah").hide();
        $(".pravidla-div").hide();
        if(id == '' || id == '#') {
          $("#pravidla-obsah").show();
          $('#pravidla-posuvnik').html('');
        }
        else {
          $("#div-"+id.substr(1)).fadeIn();
          generePosuvnik(id,kapitoly);
        }
      }
      
      function generePosuvnik(id,kapitoly) {
        var i = 0;
        var ids = new Array();
        var act = 0;
        $.each($(".pravidla-div"), function() {
          ids[i] = $(this).attr('id').substr(4);
          if(ids[i] == id.substr(1))
            act = i;
          i++;
        });
        
        $('#pravidla-posuvnik').html('');
        var html = '';
        if(act > 0) {
          html += '<a class="back" href="#'+ids[act-1]+'">&lt; '+kapitoly[act-1]+'</a>';
        } 
        html += ' <span>[ <a id="pravidla-a-obsah" href="#">Obsah</a> ]</span> ';
        if(act < kapitoly.length-1) {
            html += '<a class="next" href="#'+ids[act+1]+'">'+kapitoly[act+1]+ '&gt;</a>';
        }
        $('#pravidla-posuvnik').html(html); 
        
        $('#pravidla-posuvnik a').click(function(){
          viewPravidloId($(this).attr("href"));
        }); 
      }
      

      
      $(".pravidla-div").hide();
      var h3 = $(".pravidla-div h3");
      var kapitoly = new Array();
      var i = 0;
      $.each(h3, function() {
        kapitoly[i++] = $(this).text();
      });

      if(location.hash && (location.hash.length > 0)) {
        viewPravidloId(location.hash);   
      }

      $("#pravidla-obsah a").click(function(){
         viewPravidloId($(this).attr("href"));
      });
      
      
       
});

