$(document).ready(function() {
  
  $('.header .nav li').each(function() {
    if ($(this).find('ul').length) {
      $(this).find('ul').prepend('<li class="sn-top"></li>');
      $(this).find('ul').append('<li class="sn-bot"></li>');
      $(this).hover(function() {
        $(this).addClass('act');
      }, function() {
        $(this).removeClass('act');
      });
    };
  });
  
  if ($.browser.msie) {
    $('.breadcrumbs li:not(:first-child)').each(function() {
      //$(this).prepend('<span style="margin: 0 7px">в†’</span>')
    });
    
    $('.spa-videos li:last-child').addClass('last-child');
    $('.nav li:first-child').addClass('first-child');
  };
  
  if ($('#front').length > 0) {
    if ($.browser.msie) {
      $('.collections .f-col-item:first-child').addClass('first-child');
    };
    
    $.fn.cycle.updateActivePagerLink = function(pager, currSlideIndex) { 
      $(pager).find('li').removeClass('cur') 
        .filter('li:eq('+currSlideIndex+')').addClass('cur'); 
    };
    
    $('.promo-container').cycle({
      cleartype: 1,
      prev: '.prev',
      next: '.next',
      pager: '.promo-tabs',
      pagerAnchorBuilder: function(idx, slide) { 
         return '<li><a href="#">' + $('.promo-block:eq('+idx+')').find('h2').text().replace(/\sбассейн\sспа/g, '') + '</a></li>'
        // console.log(idx);
      }
    });
    
    $('.promo').hover(function() {
      $(this).parent().find('.promo-container').cycle('pause');
    }, function() {
      $(this).parent().find('.promo-container').cycle('resume');
    });
    
  };
  
  if ($('.gallery-scroller').length > 0) {
    $('.gallery-scroller').before('<div class="gallery-controls"><div class="prev"></div><div class="next png"></div></div>');
    $('.gallery-scroller').jCarouselLite({
      visible: 4,
      btnPrev: ".gallery-controls .prev",
      btnNext: ".gallery-controls .next"
    });
    $('.gallery-scroller a').click(function(event) {
      $('.gallery-img img').attr('src', $(this).attr('href'));
      $('.gallery-img p').remove();
      $('.gallery-img').append($(this).parent().next().clone())
      return false;
    });
  };
  
  if ($('.spa-tabs').length > 0) {
    $('.spa-tabs a').each(function() {
      var id = $(this).attr('href');
      $(this).click(function() {
        $(this).parent().parent().parent().parent().find('.cur').removeClass('cur');
        $(this).parent().parent().addClass('cur');
        $(id).addClass('cur');
        return false;
      });
    });
    
    $('.spa-tabs li').append('<i class="l"></i><i class="r"></i><b class="l"></b><b class="r"></b>')
    $('.spa-block').append('<i class="ll"></i><i class="rr"></i><b class="ll"></b><b class="rr"></b>')
    
    $('#c-specs table tr:nth-child(odd)').addClass('odd');
    
    if ($.browser.msie) {
      $('.spa-tabs li:first-child').addClass('first-child');
    };
    
  };
  
  if ($('.b-spa-catalog').length) {
    
    $('.b-spa-catalog dt').each(function(index) {
      $(this).parents('div:first').find('.b-spa-catalog-control')
        .append('<span class="spa_' + (index + 1) + '"></span>');
    });
    
    $('.b-spa-catalog dt')
      .wrapInner('<span></span>')
      .next()
        .hide()
      .end()
      .find('span').click(function() {
        if (!$(this).parent().hasClass('.current')) {
          $(this)
            .parents('div:first')
              .find('.current').removeClass('current');
          $(this)
            .parents('div:first')
              .find('dd:visible').slideUp('fast');
          $(this)
            .parent().addClass('current')
            .next().slideDown('fast');
        };
      });
      
      $('.b-spa-catalog-control span').click(function() {
        $('.b-spa-catalog dl .' + $(this).attr('class') + ' span').trigger('click');
      });
    
  };
  
});

function myForm(e) {

	var error = 0;
	
	if(!$('#o_name').val())      { alert ("Заполните обазятельное поле \"Ваше имя\""); error = 1; }
	else if(!$('#o_phone').val()) { alert ("Заполните обазятельное поле \"Контактный телефон\""); error = 1; }
	
	if(error)
		return false;
	else
		e.submit();
};

