/*function initList() {

   $('#itemsList').fadeIn('normal');
   
   var listDescr = $('#listDescr');
   listDescr.css({opacity:0});

   var itemsListWrapper = $('#itemsListWrapper');
   var listLast = $('#itemsListWrapper li').last();
   var listFirst = $('#itemsListWrapper li').first();



   $('#iRightArrow').hover(function(){
      var l = listLast.offset().left - itemsListWrapper.offset().left - (itemsListWrapper.width() - listLast.width());
      $('#itemsListWrapper ul').stop().animate({left: '-='+l},l*6);
   },function(){
      $('#itemsListWrapper ul').stop();
   });

   $('#ileftArrow').hover(function(){
      var l = itemsListWrapper.offset().left - listFirst.offset().left;
      $('#itemsListWrapper ul').stop().animate({left: '+='+l},l*6);
   },function(){
      $('#itemsListWrapper ul').stop();
   });



   $('#itemsList li img ').each(function(){
      var img = $(this);
      var conteinerH = $('#itemsListWrapper').height();
      this.imgH = img.height();
      this.imgW = img.width();
      this.imgHNew = Math.round(this.imgH*80/100);
      this.descr = img.parent().find('span').html();
      img.css({opacity:.6}).parents('#itemsListWrapper li').width(this.imgW+20);

      img.css({
         height: this.imgHNew,
         marginTop: conteinerH-this.imgHNew
      });
      this.imgMarginHorizontalDiff = Math.round((this.imgW-img.width())/2);

      img.hover(function(){
         img.stop().animate({
            height: this.imgH,
            marginTop: conteinerH-this.imgH,
            opacity: 1
         },200);
         if(listDescr.css('opacity')==='0') {
            listDescr.html(this.descr).stop().animate({opacity:1},200);
         } else {
            listDescr.stop().animate({opacity:0},200, function(){
               listDescr.html(img.get(0).descr);
               listDescr.animate({opacity:1},200);
            })
         }
      }, function(){
         img.stop().animate({
            height: this.imgHNew,
            marginTop: conteinerH-this.imgHNew,
            opacity: .6
         },200);
         //listDescr.stop().animate({opacity:0},200)
      });
   });
}*/

function initCarousel(items, carouselID) {
   var listDescr = $(carouselID+' .descriptionHolder');
   var listDescrWrapper = $(carouselID+' .descriptionHolderWrapper');
   if(listDescrWrapper.length <= 0) {
      listDescrWrapper = listDescr;
   }
   //listDescr.css('opacity',0);
   listDescrWrapper.css('opacity',0);

   var newText = $(carouselID+' .newTextHolder');

   $(carouselID+" .carousel").jCarouselLite({
      btnNext: carouselID+" .next",
      btnPrev: carouselID+" .prev",
      visible: items,
      speed: 300,
      circular: false
   });
   
   $(carouselID+' li img ').each(function(){
      var img = $(this);
      this.orginalHeight = img.height();
      this.smallHeight = Math.round(this.orginalHeight*80/100);
      this.description = img.parent().find('.description').html();
      this.newText = img.parent().find('.newText').html();
      this.marker = img.parents('.itemsCarousel li').find('.marker');
      this.marker.css('opacity',0);
      img.css({opacity:.6});

      img.css({
         height: this.smallHeight
      });

      img.hover(function(){
         img.parents('.itemsCarousel').find('.currentItem').each(function() {
            $(this).stop().animate({
               height: this.smallHeight,
               opacity: .6
            },200);
            this.marker.stop().animate({opacity: 0},200);
            $(this).removeClass('currentItem');
         });
         img.addClass('currentItem');
         img.stop().animate({
            height: this.orginalHeight,
            opacity: 1
         },200);
         this.marker.stop().animate({opacity: 1},200);
         if(listDescrWrapper.css('opacity')==='0') {
            listDescr.html(this.description);
            listDescrWrapper.stop().animate({opacity:1},200);
            if(listDescrWrapper.data('jsp')) {
               listDescrWrapper.data('jsp').reinitialise();
            }
         } else {
            listDescrWrapper.stop().animate({opacity:0},200, function(){
               listDescr.html(img.get(0).description);
               listDescrWrapper.animate({opacity:1},200);
               if(listDescrWrapper.data('jsp')) {
                  listDescrWrapper.data('jsp').reinitialise();
               }
            })
         }
         if(newText.css('opacity')==='0') {
            newText.html(this.newText).stop().animate({opacity:1},200);
         } else {
            newText.stop().animate({opacity:0},200, function(){
               newText.html(img.get(0).newText).animate({opacity:1},200);
            })
         }
      }, function(){
      });
   });
}


$(function(){

   /*$('#itemsList img').preload({
      onFinish: function(info){
         initList();
      }
   });*/

   $('#productsCarousel img').preload({
      onFinish: function(info){
         $('#productsCarousel').fadeIn('normal');
         if(info.total>0) {
            initCarousel(4,'#productsCarousel');
         }
      }
   });

   $('#smallCarousel img').preload({
      onFinish: function(info){
         $('#smallCarousel').fadeIn('normal');
         if(info.total>0) {
            initCarousel(5,'#smallCarousel');
         }
      }
   });
   
/******************************************************************************* banner */
var t = setInterval(rotateBannerRight,5000);

$('#bannerRightArrow').click(function(){
   clearTimeout(t);
   rotateBannerRight();
});

$('#bannerLeftArrow').click(function(){
   clearTimeout(t);
   var item = $('#bannerInner img').last().remove().css({marginLeft: -923});
   $('#bannerInner').prepend(item);
   $('#bannerInner img').first().stop().animate({marginLeft: '+='+932},400);
});

function rotateBannerRight() {
   $('#bannerInner img').first().stop().animate({marginLeft: '-='+932},400, function(){
      var item = $('#bannerInner img').first().remove().css({marginLeft: 0});
      $('#bannerInner').append(item);
   });
}


/******************************************************************************* about photo */
if($('body').hasClass('pageAbout')) {
   $('#arrowRight').click(function(){
      $('#photoInner a').first().stop().animate({marginLeft: '-='+370},400, function(){
         var item = $('#photoInner a').first().remove().css({marginLeft: 0});
         $('#photoInner').append(item);
         item.fancybox({'titlePosition' : 'inside'});
      });
   });

   $('#arrowLeft').click(function(){
      var item = $('#photoInner a').last().remove().css({marginLeft: -370});
      $('#photoInner').prepend(item);
      item.fancybox({'titlePosition' : 'inside'});
      $('#photoInner a').first().stop().animate({marginLeft: '+='+370},400);
   });
}

/******************************************************************************* curvy corners */
//var settings10 = {tl: {radius: 10}, tr: {radius: 10}, bl: {radius: 10}, br: {radius: 10}, antiAlias: true}
//var settings30 = {tl: {radius: 30}, tr: {radius: 30}, bl: {radius: 30}, br: {radius: 30}, antiAlias: true}
//$('.curvy10').corner(settings10);
//$('.curvy30').corner(settings30);

/******************************************************************************* fancy box */
$("a.fancyImage").fancybox({
   'titlePosition' : 'inside'
});

$('.inputFile input').change(function(){
   $('.inputFile span').empty().append(this.value);
})

if($('#productsCarousel .descriptionHolderWrapper').length > 0) {
   $('#productsCarousel .descriptionHolderWrapper')
      .jScrollPane({
         showArrows: true,
         verticalDragMinHeight: 17,
         verticalDragMaxHeight: 17
      }).bind('mousewheel',function(e){
         if($(this).find('.jspVerticalBar').length > 0) {
            e.preventDefault();
         }
      });
}


});
