$(function() {
  // Показываем превьюшки услуг, статей
  $(".paw-list li span, .paw-list li a").hover(function() {
    $(".annotation", this.parentNode).show();
  }, function() {
    $(".annotation", this.parentNode).hide();
  });

  // Прокрутка в галерее "до-после"
  $(".double-gallery .double-gallery-content").each(function() {
    this.scroller = new Scroller(this);
  });
  $('.gall a').click(function(){
    $('.gall').removeClass('active');
    $(this).parent().addClass('active');
    var params = {
      _do:'get_gallery',
      node_id:_get_id($(this).parent(),1)};
    GetJson(params,function(data){ show(data) });
    return false;
  });

  // Галерея
  $(".gallery a, .double-gallery a").FBox({
      animation: true,
      imagesList: false,
      imagesListWidth: 80,
      showOverlay: true,
      overlayClickClose : true,
      useLoaderAnim: true,
      loaderParams: {
          animatioLength: 400,
          animationStep: 50,
          animationTime: 100
      },
      navigationButtons: true,
      navigationButtonsHover: true,
      constraints: {
          minWidth: 650,
          minHeight: 450,
          maxWidth: 800,
          maxHeight: 600
      }});

  // Стоимость услуг и т. п.
  $("a[rel='popup']").click(function () {
      if (!this._fbox) {
          this._fbox = new FBox({
              ajax : {
                  url : '/json/',
                  _do : 'get_page',
                  href : this.href
              },
              constraints : {
                  minWidth : 650,
                  minHeight : 450,
                  maxWidth : 800,
                  maxHeight : 600
              },
              animation : true,
              showOverlay : true,
              overlayOpacity : .3,
              overlayClickClose : true,
              useLoaderAnimation : true,
              loaderParams : {
                  animationLength : 60,
                  animationStep : 5
              }
          });
      }
      this._fbox.show();
      return false;
  });  
  var fixSmooth = function() {
    // Top menu
    $("#header .top-menu a.first").append("<ins class='fl fl-lt' /><ins class='fl fl-lb' />");
    $("#header .top-menu a.last").append("<ins class='fl fl-rt' /><ins class='fl fl-rb' />");
    if ($.browser.msie && $.browser.version <= 6) $("#header .top-menu a").hover(function() { $(this).addClass("hover"); }, function() { $(this).removeClass("hover"); });
    // Home page
    $(".hp-content .hp-content-left").append("<ins class='fl fl-lt' /><ins class='fl fl-rt' /><ins class='fl fl-rb' /><ins class='fl fl-lb' />");
    // Persons
    $(".persons .person").append("<ins class='fl fl-lt' /><ins class='fl fl-rt' /><ins class='fl fl-rb' /><ins class='fl fl-lb' />");
    // Questions
    $(".questions .question").append("<ins class='cn cn-lt' /><ins class='cn cn-rt' /><ins class='cn cn-rb' /><ins class='cn cn-lb' />");
  }
  if (($.browser.msie && $.browser.version < 9) || ($.browser.opera && $.browser.version < 10.5)) fixSmooth();
});

function GetJson(data,handler) {
      $.ajax({
      method: 'POST',
      url:'/json/',
      data:data,
      success:handler,
      dataType: 'json'});
};
function _get_id(el,flag) {
    var str;
    var ID;
    if(!flag){
        if ($(el).attr('href')){
           str=$(el).attr('href');
        }
        else
        str = window.location.hash.toString();
    }
    else {
        str=$(el).attr('id')
    };
    ID=str.split('cnt');
    window.location.hash=ID[0].slice(0,ID[0].lenght-2);
    return ID[1];

};
function show(data) {
    $('.gallery').html('');  
    $('.gallery').append(data.html);
    $(".gallery a").FBox({
      animation: true,
      imagesList: false,
      imagesListWidth: 80,
      showOverlay: true,
      overlayClickClose : true,
      useLoaderAnim: true,
      loaderParams: {
          animatioLength: 400,
          animationStep: 50,
          animationTime: 100
      },
      navigationButtons: true,
      navigationButtonsHover: true,
      constraints: {
          minWidth: 650,
          minHeight: 450,
          maxWidth: 800,
          maxHeight: 600
      }});
    return false;
};

