/**
 * 
 
function class_main()
{ 

   this.Run = function Run()
   {
      this.ChangeSet('red',1);
      this.ChangeSet('green',1);
      this.ChangeSet('orange',1);
      this.ChangeSet('blue',1);
      var t = setInterval("Change('red', 6)",5000);
      var u = setInterval("Change('green', 4)",5000);
      var u = setInterval("Change('orange', 4)",5000);
   }
   
   this.ChangeSet = function ChangeSet(blok,item)
   {
      //zrusim zvyrazneni
      $('.big_square_'+blok).attr("class",'small_square');
      //nastavim nove
      $("#"+blok+"_"+item).attr('class', 'big_square_'+blok);
   }
} 

function Change(blok, max_items)
{
   var polozka = $('.big_square_'+blok).attr("id");
   var polozka_slices = polozka.split("_");
   
   if(polozka_slices[1] >= max_items)
   {
      polozka_slices[1] = 1; 
   }else{
      polozka_slices[1]++;
   }
   
   //zrus puvodni
   $('.big_square_'+blok).attr("class",'small_square'); 
   
   $("#"+blok+"_"+polozka_slices[1]).attr('class', 'big_square_'+blok);
   
   var txt_popis = $('.big_square_'+blok).attr("title");
   var txt_href = $('.big_square_'+blok).attr("href");
   $("#"+blok+"_button").text(txt_popis);
   $("#"+blok+"_button").attr("href",txt_href);
}
*/
function BannerChange(data){
   $('#index-h').animate({
      opacity: 0
   }, timer_effect, function() {
      $('#index-h').html(data.data.index_h);
      $('#index-h').animate({
         opacity: 1
      }, timer_effect, function() {
                     
         });
   });
   
   $('#index-img').animate({
      opacity: 0
   }, timer_effect, function() {
      $('#index-img').attr('src', data.data.index_img);
      $('#index-img').animate({
         opacity: 1
      }, timer_effect, function() {
                     
         });
   });
   
   $('#index-descr').animate({
      opacity: 0
   }, timer_effect, function() {
      $('#index-descr').html(data.data.index_descr);
      $('#index-descr').animate({
         opacity: 1
      }, timer_effect, function() {
                     
         });
   });
   
   $('#index-btn-bottom').animate({
      opacity: 0
   }, timer_effect, function() {
      $('#index-btn-bottom').html(data.data.index_btn_bottom);
      RestoreSwitch(data);
      $('#index-btn-bottom').animate({
         opacity: 1
      }, timer_effect, function() {
         actual_index++;
         if(actual_index >= count){
            actual_index = 0;
         }   
      });
   });
                              
   
}

function RestoreSwitch(data){
   $('#index-a-'+(actual_index)).attr('href', data.data.index_a_);
   var old_idx =0;
   if(actual_index == 0){
      old_idx = count-1;
      $('#index-a-'+(count-1)).attr('class',"index-switch");
   }else{
      old_idx = actual_index-1;
      
   }
   $('#index-a-'+(old_idx)).attr('class',"index-switch");
   $('#index-a-'+(actual_index)).attr('class',"index-switch-sel");
}

function GenerateSwitch()
{
   var html_fragment = "";

   for(i = 0; i < count; i++){
      //var pom = "adr"+i;
      if((actual_index-1) == i){
         
         html_fragment = html_fragment + '<a id="index-a-'+i+'" href="'+adres[i]+'" class="index-switch-sel">'+(i+1)+'</a>';
      }else{
         html_fragment = html_fragment + '<a id="index-a-'+i+'" href="'+adres[i]+'" class="index-switch">'+(i+1)+'</a>';
      }
      
   }
   $(".index-switch-box").html('<a href="/" class="index-switch-nav"><img src="/zdroje/sipka_vlevo.png" /></a>'+html_fragment+'<a href="/" class="index-switch-nav"><img src="/zdroje/sipka_vpravo.png" /></a>');
}

function BannerLoader(){
   
   if($(".index_area").is("*")){
      $.post("/ajax_promo_banner", {
         request: "get_val",
         index:actual_index
      },
      function (data){

         if(data)
         {
            if(data.err.status == 'true'){
            /* alert("err_msg:"+data.err.msg+" err_status: "+data.err.status);*/
            }
            else
            {
               count = data.count;
               if(count > 1)
                  BannerChange(data);
               
            }  
         }else	{
            alert("Communication Error.");
         }
            
      }, "json");
      
      
      setTimeout("BannerLoader()",timer_change);
   }
}

function BannerInit()
{
   $.post("/ajax_promo_banner", {
      request: "get_count"
   },
   function (data){

      if(data)
      {
         if(data.err.status == 'true'){
         /* alert("err_msg:"+data.err.msg+" err_status: "+data.err.status);*/
         }
         else
         {
            
            count = data.count;
            adres = data.adres;
            if(count > 1)
               GenerateSwitch(data);
            
         }  
      }else	{
         alert("Communication Error.");
      }
            
   }, "json");
}

var actual_index = 1;
var timer_effect = 1000;
var timer_change = 10000;
var count = 1;
var adres = new Array();

$(document).ready(function()
{
   /*   
    *   SKLAD
    *   var ma = new class_main();
   ma.Run();
ma.ChangeSet('red',1);
   
   $("#debugjs").html("index:"+actual_index);
   */
   BannerInit();
   setTimeout("BannerLoader()",timer_change);
});
