$(document).ready(function(){
        $promoBlock = $('.promo-block');
        $obj = null;
        speedAnimate = 1000;
        step = 100 + 'px';
        easyMethod = 'easeOutBack';
        var intervalChange;
        if ($promoBlock.length){
                $promoTabs = $('.promo-tabs > li');
                $promoContent = $('.promo-tab > li');
                
                changeImage = function(){
                        $currentContent = $promoBlock.find('.promo-tab > li.active');
                        $currentImg = $currentContent.find('img.active').hide();
                        $showImg = $currentContent.find('img:not(.active)').hide().fadeIn(speedAnimate/2).addClass('active');
                        $currentImg.removeClass('active');
                }
                changeSlide = function(){
                        if ($obj.hasClass('active')) return false;
                        $promoTabs.removeClass('active');
                        $obj.addClass('active');
                        clickedIndex = $promoTabs.index($obj);
                        $promoContent.stop(false,true).hide().removeClass('active');
                        $currentContent = $promoContent.eq(clickedIndex);
                        $currentContent.find('.promo-text').stop(false,true).hide().fadeIn(speedAnimate,easyMethod);
                        $currentContent.find('.h3').stop(false,true).css({'left':'-'+step}).animate({'left':"0px"},speedAnimate,easyMethod);
                        $currentContent.find('.h2').stop(false,true).css({'left':step}).animate({'left':"0px"},speedAnimate,easyMethod);
                        $currentContent.find('p').stop(false,true).css({'left':'-'+step}).animate({'left':"0px"},speedAnimate,easyMethod);
                        $currentContent.stop(false,true).addClass('active').hide().fadeIn(speedAnimate);
                        clearInterval(intervalChange);
                        intervalChange = setInterval('changeImage()', 7000);
                }

                $promoTabs.click(function(){
                        $obj = $(this);
                        changeSlide();
                });
                $promoTabs.hover(function(){
                        if ($obj == $(this))  return false;
                        $obj = $(this);
                        changeTimeout = setTimeout('changeSlide()',1500);
                }, function(){
                        clearTimeout(changeTimeout);
                });
                
                $obj = $promoTabs.eq(0);
                changeSlide();
        }
        
        imgWidth = 314;
        imgCountShow = 2;
        $('.slider').each(function() {
                var $slider = $(this);
                var $sliderContent = $slider.find('ul');
                var $sliderContentLi = $sliderContent.find('li');
                var imgCount = $sliderContent.find('li').length;
                $sliderContent.css({'width':'20000'+'px'});
                var curPos = 1;
                var $sliderPrev = $slider.find('.prev');
                var $sliderNext = $slider.find('.next');
                
                var checkArrows = function (){
                        if (curPos == 1) $sliderPrev.hide(); else $sliderPrev.show();
                        if (curPos == imgCount-imgCountShow+2) $sliderNext.hide(); else $sliderNext.show();
                }
                
                checkArrows();
                $sliderPrev.click(function(){
                        curPos--;
                        oldHeight = $sliderContentLi.eq(curPos-1).height();
                        newHeight = $sliderContentLi.eq(curPos-1).css({'height':'auto'}).height();
                        $sliderContentLi.eq(curPos-1).css({'height':oldHeight});
                        
                        $sliderContentLi.eq(curPos-1).animate({height:newHeight });
                        $sliderContent.stop(true,true).animate({'left':'+='+$sliderContentLi.eq(curPos-1).outerWidth()},speedAnimate,easyMethod);
                        checkArrows();
                        return false;
                });
                $sliderNext.click(function(){
                        curPos++;
                        newHeight = $sliderContentLi.eq(curPos-1).height();
                        $sliderContentLi.eq(curPos-2).animate({'height':newHeight});
                        $sliderContent.stop(true,true).animate({'left':'-='+$sliderContentLi.eq(curPos-2).outerWidth()},speedAnimate,easyMethod);
                        checkArrows();
                        return false;
                });
        });


        $('.article table.zebra tr:nth-child(odd)').addClass('zebra');
})
