$(document).ready(function() {

   if (!$(".slot").length) return;

   // 320x190
   // 260x155
   //return;
   //var sl_speed=500;
   //var sl_speed=800;
   var sl_speed=slider_settings.speed;
   var sl_timeout=60000;
   var sl_speed_fout=300;
   
   var first_run=true;

   var n = 1;
   $(".slot ul").each(function () {
      $(this).attr("id", "k"+(n++)).addClass('cycle');
   });

   /*
   n = 1;
   $(".slot").each(function () {
      $(this).attr("id", "s"+(n++));
   });
   */

   $("#k1, #k2, #k3").each(function () {
      $(this).html("");
   });
   
   var nn = 1;
   
   $("#slides").children().each(function () {
      $(this).attr("id", "for_sl_"+nn);
      var e=$(this).clone();
      e.find("a").hide();
      e.find("a").html('');
      
      e.attr("id", 'sl_'+nn);
      
      nn++;
      
      e.find("img").attr("width", 320);
      e.find("img").attr("height", 190);
      $("#k2").append(e.clone());
      e.find("img").attr("width", 260);
      e.find("img").attr("height", 155);
      e.find("img").attr("src", e.find("img").attr("src").replace('320x190', '260x155'));
      $("#k1").append(e);
      $("#k3").append(e.clone());
   });

   $("#k1, #k2, #k3").each(function () {
      var n=parseInt($(this).attr('id').substring(1));
      var e=$("#k"+n).children();
      $(e[n-1]).css({
         'z-index': '999',
         'position': 'absolute',
         'left': 0
      });
   });
   
   //alert("?");
   
   //return;
   
   $(".slot .desc").each(function () {
      $(this).css({
         opacity: 0,
         visibility: 'visible'
      });
      $(this).hover(function () {
         if ($.browser.msie)
         {
            $(this).css('opacity', 1);
            this.style.removeAttribute('filter');
            return;
         }
         $(this).animate({
            opacity: 1
         }, {
            duration: 300,
            queue: false,
            complete: function () {
               if ($.browser.msie) this.style.removeAttribute('filter');
            }
         });
      }, function () {
         if ($.browser.msie)
         {
            $(this).css('opacity', 0); return;
         }
         $(this).animate({
            opacity: 0
         }, {
            duration: 300,
            queue: false,
            complete: function () {
               //if ($.browser.msie) this.style.removeAttribute('filter');
            }
         });
      });
   });
   
   //return;
   
   //return;
   
   /*
   alert($("#k1").html());
   alert($("#k2").html());
   alert($("#k3").html());
   */

   //return;

   if ($("#slides").children().length == 1)
   {
      //return;
   }

   //return;
   
   var f_run = 0;

   $(".cycle").each(function () {
      var n=parseInt($(this).attr('id').substring(1));
      //alert(n);
      var st=0;
      if (n==2) st=0;
      if (n==3) st=$(this).find("a").length-1;
      if (n==1) st=1;
      //st++;
      var o={
       w:      320,
       startZindex: 10,
       fx:     'scrollHorz', 
       speed:   sl_speed,
       timeout: 0,
       startingSlide: st,
       //easing: 'easeOutExpo',
       easing: slider_settings.easing,
       selector: '',
       oneAfterAnother: slider_settings.oneAfterAnother,
       //continuous: true,
       fit: false,
       pager: '#slider_dots',
       next: ".right",
       prev: ".left",
       cssAfter: {
         left: 0
       },
       after: function (currSlideElement, nextSlideElement, options) {
         var a=$(nextSlideElement);
         var b=$(currSlideElement);
         a.css({left: 0});
         b.css({left: 0});
       },
       before: function (currSlideElement, nextSlideElement, options, forwardFlag) {
          if (options.nextSlide==options.currSlide && $("#slides").children().length!=1) return;
          var ee = "slot_";
          if (o.second) ee+="center";
          else if (o.third) ee+="right";
          else ee += "left";
          //alert( $(nextSlideElement).attr("id") );
          var hh = $("#for_" + $(nextSlideElement).attr("id")).find("a").html();
          var hhh = $("#for_" + $(nextSlideElement).attr("id")).find("a").attr("href");
          var hht = $("#for_" + $(nextSlideElement).attr("id")).find("h4").text();
          //alert(hh);
          f_run++;
          if (f_run == 4) return;
          //alert(ee+": "+hht);
          $("#"+ee).children(".desc").attr( "href", hhh );
          $("#"+ee).children(".desc").html( hh );
          $("#"+ee).children(".desc").find("h4").html( hht );
          
          if (is_day)
          {
            Cufon('.desc h4', {
               color: '-linear-gradient(#fff, 0.4=#e8eaeb, #b0b5b8)', textShadow: '1px 1px #000'
            });
          }
          else
          {
            Cufon('.desc h4', {
               color: '-linear-gradient(#282828, #1d1d1d)', textShadow: '1px 1px #f0f0f0'
            });
          }
       }
      };
      if (n==2) o.second=1;
      if (n==3) o.third=1;
      $(this).cycle(o);
   });
   $(".cycle:eq(0)").cycle('pager');
   $(".desc").click(function () {
      window.location.href = $(this).attr("href");
      return false;
   });

});

