jQuery(document).ready(function(){

///// вкладки /////

// присваиваем классы
jQuery('h1.pan').each(function(i){ 
  jQuery(this).attr('id', 'p_'+(i+1)).addClass('p_'+(i+1)); //.css('border',(i+1)+'px solid #c00');
  jQuery(this).next().nextAll().not('.pan').attr('class','pc p_'+(i+1)); //.css('border',(i+1)+'px solid #0c0');
  jQuery(this).next().not('.pan').attr('class','pi p_'+(i+1));
});

jQuery('h1.pan').each(function(i){ 
  // контейнер вкладки
  jQuery('.p_'+(i+1)).wrapAll('<div class="b-pan-wrap p_'+(i+1)+'"></div>');
  // аннотация 
  jQuery('.pi.p_'+(i+1)).addClass('b-pan-intro'); //.css('border-left',(i+1)+'px solid #ddd');
  // контент
  jQuery('.pc.p_'+(i+1)).wrapAll('<div class="b-pan-content p_'+(i+1)+'"></div>');
  jQuery(this).before('<a name="p_'+(i+1)+'"></a>'); 
  jQuery(this).wrapInner('<a href="[~[*id*]~]#p_'+(i)+'"></a>'); 
});

// декорация
jQuery('.b-pan-wrap').wrapInner('<div class="t"><div class="b"><div class="c clearfix"></div></div></div>');
jQuery('.b-pan-wrap:eq(0)').addClass('first');

// переключатель
jQuery('.b-pan-content').hide();
jQuery('.pan').click(function(){ 
  jQuery('.b-pan-content:visible').slideUp(200);
  if(!jQuery(this).parents('.b-pan-wrap').hasClass('active')) {
    jQuery(this).parents('.b-pan-wrap').addClass('active1');
    jQuery(this).parents('.b-pan-wrap').find('.b-pan-content').slideDown(200);
  }
  jQuery('.b-pan-wrap').removeClass('active');
  jQuery(this).parents('.active1').removeClass('active1').addClass('active');
//  document.title = jQuery(this).hasClass('active')+' / .pcontent.'+this.id; 
});



///// каталог - навигация /////

//jQuery('.b-nav-cat li ul').hide();

jQuery('.b-nav-cat li.active').addClass('open');
//jQuery('.b-nav-cat li.active ul').show();

jQuery('.b-nav-cat li.l1>a').removeAttr('href').click(function(){ 
  if( jQuery(this).parent().hasClass('open') ){ 
    jQuery(this).parent().find('ul').slideUp(300); 
    jQuery(this).parent().removeClass('open');
  } else {  
    jQuery(this).parent().parent().find('li.l1.open').removeClass('open').children('ul').slideUp(300); 
    jQuery(this).parent().addClass('open');  
    jQuery(this).parent().children('ul').slideDown(300); 
  } 
  promo_cleartimer(); 
});

jQuery('.b-nav-cat li.l2>a').removeAttr('href').click(function(){ 
  if( jQuery(this).parent().hasClass('open') ){ 
    jQuery(this).parent().children('ul').slideUp(300); 
    jQuery(this).parent().removeClass('open');
  } else {  
    jQuery(this).parent().parent().find('li.l2.open').removeClass('open').find('ul').slideUp(300); 
    jQuery(this).parent().addClass('open');  
    jQuery(this).parent().children('ul').slideDown(300); 
  } 
  promo_cleartimer(); 
});

///// партнеры /////

jQuery('#inner_scroll').scrollable({
        size: 5,
        speed: 300,
        loop: true,
        hoverClass: 'hover' 
    });


jQuery('.b-partners img').hover( 
    function(){ jQuery(this).stop().fadeTo(200, 1); }, 
    function(){ jQuery(this).stop().fadeTo(300, 0.7); }
);

///// альтернативная навигация /////

jQuery('ul.b-altnav li:ne(.designer)').hover(
    function(){jQuery(this).stop().animate({marginTop:'-16px',height:'80px'},200);promo_cleartimer();}, 
    function(){jQuery(this).stop().animate({marginTop:'0px',height:'63px'},300);promo_cleartimer();}
);
jQuery('ul.b-altnav li a').hover(
    function(){jQuery(this).stop().animate({paddingTop:'15px'},200);promo_cleartimer();}, 
    function(){jQuery(this).stop().animate({paddingTop:'10px'},300);promo_cleartimer();}
);
jQuery('ul.b-altnav li.designer').hover(
    function(){jQuery(this).stop().animate({marginTop:'-120px',height:'183px'},300);promo_cleartimer();}, 
    function(){jQuery(this).stop().animate({marginTop:'-22px',height:'83px'},400);promo_cleartimer();}
);


///// промо-фотографии /////

var img_count = jQuery('div.b-bgimage').length-1;
var img_index = img_count*0;
function showimage(d)
{
    t = 800;
    img_tag = 'div'; // 'img'
    if(promo_done)
    {
      ii0 = img_index;
      img_index += d;
      if(img_index>img_count) img_index=0;
      if(img_index<0) img_index=img_count;
      jQuery(img_tag+'.b-bgimage').eq(img_index).css('z-index',-2).css('opacity',1).stop().show(); //.animate({marginLeft: '0', opacity: 1}, t); //show();
      jQuery(img_tag+'.b-bgimage').eq(ii0).css('z-index',-1).stop().fadeOut(t); // .animate({marginLeft: '100px', opacity: 0}, t);
    }
    promo_cleartimer();
}

var promo_timer = 0;
var promo_done = 0;

function promo_cleartimer()
{
//  document.title = dd+': '+promo_timer;
    clearInterval(promo_timer);
    promo_timer = setInterval('showimage(1)', 5000);
}


promo_timer = setInterval('showimage(1)', 5000);

jQuery.preloadImages(
	['tpl/i/promo/Alessi_dot_08_08.jpg', 'tpl/i/promo/Seriq_KHROMA.jpg', 'tpl/i/promo/mimo_04.jpg'], 
		function(){
			promo_done = 1; 
			jQuery('.b-promo .b-loader').fadeOut(100); 
			// jQuery('.b-bgimages .b-bgimage:eq(1)').fadeIn(500); 
		}
	);
});


/////
});
