$(document).ready(function()
{
  $('#intro').pdReferRotator({ 
    rowTimeOut: 6000,
    annotList: annList,
    titleList: titList,
    imageList: imgList,
    linkList: hrefList
  });
});

(function($){

	$.fn.pdReferRotator = function(options)
	{
		  var o = $.extend({
			rowTimeOut: 3000,
      imageList: [],

			titleList: [],
			annotList: []
	  	}, options);
	  	
	  	var titleLength = o.titleList.length;
      var help1=0; 

     // VYTVORENI JS MENU
     $(this).append(
        '<div class=\'js-menu\'><div class=\'prev\'>prev</div><ul></ul><div class=\'next\'>next</div></div>'        
      );
      for(var liNo = 0; liNo < titleLength; liNo++ )
      {
        $('.js-menu ul', this).append('<li>'+liNo+'</li>');
      }
      
      // KLIKNUTI NA POLOZKU 
      $('.js-menu ul li', this).bind('click', function(){
        help1 = $(this).text();
        rotate();
       });
      // POHYB DOPREDU
      $('.js-menu .next', this).bind('click', function(){
        rotate();
       });
      // POHYB DOZADU
      $('.js-menu .prev', this).bind('click', function(){
        if(help1==1){help1=titleLength+1;}
        if(help1==0){help1=titleLength;}
        help1= help1-2;
        //alert(help1);
        
        rotate();
       });
      
     function rotate()
       {
        clearInterval(interval);
        interval = setInterval(function(){rotate();}, o.rowTimeOut);
        $('#intro h2').text(o.titleList[help1]);
        $('#intro .annot').text(o.annotList[help1]);
        $('#intro img').attr({
  					src: o.imageList[help1].file,
  					alt: o.imageList[help1].alt
  				});
        $('#intro .img a').attr({
  					href: o.linkList[help1]
  				});
  			$('#intro .right a').attr({
  					href: o.linkList[help1]
  					
  				});
  			
  			var ob = $('#intro .js-menu li');
  			$('#intro .js-menu li').filter('.active').removeClass('active');
  			$(ob[help1]).addClass('active');
  		
  			var help2 = help1;
  			help2++;
        if(help2<titleLength){	help1++;}
        else{help1=0;}  
      }  
      interval = setInterval(function(){rotate();}, 0);    
	};
  	
})(jQuery);


