    $(document).ready(function(){
      $('.PopupImage').click(function (){
        /* Кастыль */
        var pclass = $(this).parent('div').attr('class')
        if(pclass=='gallerythumb') 
          {
            var rows_id = $(this).parent('div').attr('rowsid')
            $('td.gall'+rows_id+' div.gallerythumb-h').addClass('gallerythumb');
            $('td.gall'+rows_id+' div.gallerythumb-h').removeClass('gallerythumb-h');
            $(this).parent('div').addClass('gallerythumb-h');
          }
        
      
      
        $('#pelena').show();
        
        var ttl = $(this).attr('title');
        if(ttl) {} else {ttl="Просмотр фотографии";}
        $('#PopupImageFrameTitle').html(ttl);
        
        $('#PopupImageFrame').fadeIn('slow');
         allg('#PopupImageFrame');
         //setTimeout("allg('#PopupImageFrame');", 10);
         //setTimeout("allg('#PopupImageFrame');", 1000);
         //setTimeout("allg('#PopupImageFrame');", 2000);
        $('#PopupImageFrame img.PopupImageFrameImg').attr('src',$(this).attr('href'));
        $('#PopupImageFrame img.PopupImageFrameImg').show();
        return false;
      });
      $('.CloseLayer').click(function (){
        $('#pelena').hide();
        $('.BlockLayer').hide();
      });
      $('.OpenLayer').click(function (){
         $('#pelena').show();
         $('.BlockLayer').fadeIn('slow');
         allg('.BlockLayer');
      //   setTimeout("allg('.BlockLayer');", 10);
      //   setTimeout("allg('.BlockLayer');", 1000);
      //   setTimeout("allg('.BlockLayer');", 2000);
        $('.BlockLayer input:first').focus();
      });
      //$('#PopupImageFrame img').click(function (){cloooose();});
      $('tr.SingleCloser td div').click(function (){cloooose();});






      // Универсальная открывалка чего либо
      $('.OpenPopupWindows').click(function(){
          var openclass = $(this).attr('openclass');
          $('#pelena').show();
          $('.'+openclass).show();
          allg('.'+openclass);
      //    setTimeout("allg('."+openclass+"');", 10);
      //    setTimeout("allg('."+openclass+"');", 1000);
      //    setTimeout("allg('."+openclass+"');", 2000);
          $('.'+openclass+' input:first').focus();
          // Дополднительно выполняем для карты яндекс
          if(openclass=='PopupWindowMap')
            {
              $('.BlockLayer').fadeIn('slow');
              YMaps.jQuery(function () {
                var map = new YMaps.Map(YMaps.jQuery("#YMapsID-1538")[0]);
                map.setCenter(new YMaps.GeoPoint(82.992508,54.918433), 15, YMaps.MapType.MAP);
                map.addControl(new YMaps.Zoom());
                map.addControl(new YMaps.ToolBar());
                map.addControl(new YMaps.TypeControl());
                map.openBalloon(new YMaps.GeoPoint(82.99332,54.916079), "630501, Новосибирская область,<br>п.Краснообск, здание СибИМЭ,<br>оф.286, а/я 297");
              });
             }
      });
      
      
      
      
      
      
      
      
      
      
      
      
      // Универсальная закрывалка чего либо
      $('.ClosePopupWindows').click(function(){
          var closeclass = $(this).attr('closeclass');
          $('#pelena').hide();
          $('.'+closeclass).hide();
      });
      $('.PrintPage').click(function(){window.print();});
      // Подсветка Супер инпутов при фокусе
      $('.PopupFormField').focus(function(){$(this).parent('td').parent('tr').parent('tbody').parent('table').addClass('inputstyle-h');});
      $('.PopupFormField').blur(function(){$(this).parent('td').parent('tr').parent('tbody').parent('table').removeClass('inputstyle-h');});
      // Кнопка ховер
      $('.KnopaStatic').hover(function(){$(this).addClass('KnopaStatic-h');},function(){$(this).removeClass('KnopaStatic-h');});
    });



    
    
    function cloooose()
      {
        $('#pelena').hide();
        $('#PopupImageFrame').hide();
        $('#PopupImageFrame img').hide();
        return false;
      }
    function allg(jq_selector)
      {
      /*
           var Leftt = Math.max(40, parseInt($(window).width()/2 - $(jq_selector).width()/2)) + 'px';
           var Topp  = Math.max(40, parseInt($(window).height()/2 - $(jq_selector).height()/2)) + 'px';
           
           $(jq_selector).css('position', 'fixed');
           $(jq_selector).css('top',  Topp);
           $(jq_selector).css('left', Leftt);
           
*/
           var ofs = $(jq_selector).offset();
           $(jq_selector).css('position', 'absolute');
           $(jq_selector).css('top',  ofs.top+'px');
           $(jq_selector).css('left', ofs.left+'px');

           
           //$(jq_selector).draggable({ appendTo: 'body' });
           //$(jq_selector).draggable({ cancel: 'button' });
           $(jq_selector).draggable({ containment: 'document' });
           //$(jq_selector).draggable({ handle: 'tr' });
           $(jq_selector).draggable({ opacity: 0.5 });
           //$(jq_selector).draggable({ grid: [50, 20] });
           
      }
