$(document).ready(function() {
   var sliderActive = false;

   $(window).resize(function (e) {
      var el = $("#SlideList > div.scrollPanel:first");
      var all = $("#SlideList > div.scrollPanel");
      var width = el.width();
      var height = el.height();
      var wndWidth = $(window).width();
      width = wndWidth - 148;
      if (wndWidth - 148 <= 852) width = 852;
      all.css("width", width);
      var sc = $(".scroll")
      sc.css("height", el.outerHeight());
      sc.css("width", el.outerWidth());
      $("#SlideList").css("width", width * (all.length + 1));
   }); $(window).resize();

   var $panels = $('#SlideList > div.scrollPanel');
   var $container = $('#SlideList');

   var horizontal = true;

   if (horizontal) {
     $panels.css({
       'float' : 'left',
       'position' : 'relative' // IE fix to ensure overflow is hidden
     });

     $container.css('width', $panels[0].offsetWidth * $panels.length);
   }

   var $scroll = $('#slider .scroll').css('overflow', 'hidden');

   function trigger(data) {
     var el = $('#slider .navigation .container').find('div[href$="' + data.id + '"]').get(0);
     selectSlide.call(el);
   }

   var offset = parseInt((horizontal ?
     $container.css('paddingTop') :
     $container.css('paddingLeft'))
     || 0) * -1;

   function selectSlide() {
      if (!sliderActive) {
         var scrollOptions = {
           target: $scroll,
           items: $panels,
           navigation: '#SlideControl3 .container .sc_item',
           prev: '#SlideControl1 a:first',
           next: '#SlideControl1 a:last',
           axis: 'xy',
           onAfter: trigger,
           offset: offset,
           duration: 500,
           easing: 'swing'
         };
         $('#slider').serialScroll(scrollOptions);
         $.localScroll(scrollOptions);
         scrollOptions.duration = 1;
         $.localScroll.hash(scrollOptions);
      }
      var list = $("#SlideControl3 .container .sc_item div:first");
      list.removeClass("sc_shadow_active");
      list.removeClass("sc_shadow_preactive");
      list.removeClass("sc_shadow");
      list.addClass("sc_shadow");
      var item = $(".sc_shadow", this);
      item.removeClass("sc_shadow");
      item.addClass("sc_shadow_active");
      if (!$(this).hasClass("last")) {
         var next = $(".sc_shadow", $(this).next().get(0));
         next.removeClass("sc_shadow");
         next.addClass("sc_shadow_preactive");
      }
      $(this)
       .parents('div:first')
         .find('.sc_item')
           .removeClass('selected')
         .end()
       .end()
       .addClass('selected');
   }
   $("#SlideControl3 .container .sc_item").click(selectSlide);

   $("#SlideControl3 .container .sc_item:first").click();
   
   $('.video_button').click(function() {
		switch ($(this).attr('id')) {
			case 'promo_main' : {
				showVideo('http://foyo.ru/site/files/2max_ru.flv');
			} break;
			case 'howto_quick' : {
				showVideo('http://foyo.ru/site/files/umiru_howto.flv ');
			} break;
			default : {
				showVideo('http://foyo.ru/site/files/2max_ru.flv');
			}
		}
   });
   
   $("#sites_examples").jCarouselLite({
        btnNext: ".nextExample",
        btnPrev: ".prevExample",
		auto: 5500,
		speed: 800,
		scroll: 1
    });
	
	var links = [];
	var secI = 0;
	$("ul.links li").each(function() {
		secI++;
		links.push(".links .sec" + secI);
		$(this).mouseenter(function() { 
			$("ul.links li.act").removeClass("act");
			$(this).addClass("act");
			$(this).click();
		});
	});
	$(".descs_wrapper").jCarouselLite({
		visible: 1,
		start: 0,
		speed: 0,
		btnGo: links
	});
    
    $(".tariff_control_block a").click(function(){
        $(".current").removeClass("current");
        $(this).addClass("current");
        $($(this).attr('rel')).addClass("current");
        return false;
	});
    
   
});
