function getBrowserInfo() {
var t,v = undefined;
if (window.opera) t = 'Opera';
else if (document.all) {
  t = 'IE';
  var nv = navigator.appVersion;
  var s = nv.indexOf('MSIE')+5;
  v = nv.substring(s,s+1);
}
else if (navigator.appName) t = 'Netscape';
return {type:t,version:v};
}

function bookmark(a){
  var url = 'http://www.profbuh.ru/';
  var title = 'ПБК Главный Бухгалтер';
  var b = getBrowserInfo();
  if (b.type == 'IE') window.external.AddFavorite(url,title);
  else if (b.type == 'Opera') {
    a.href = url;
    a.rel = "sidebar";
    a.title = url+','+title;
    return true;
  }
  else if (b.type == "Netscape") window.sidebar.addPanel(title,url,"");
  else alert("Нажмите CTRL-D, чтобы добавить страницу в закладки.");
  return false;
}

var is_fly = 1;
var fly_order = '';
var fly_calk = '';
var fly = '';
var fly_left = 0;
var fly_top = 0;

function initFly() {
  fly_order = $("#fly_order");
  fly_calk = $("#fly_calk");
  fly = $("#fly_y");
    
  fly_left = $(window).width() - 170;    
  fly_top = fly.offset().top;
  
  fly_order.css({left: fly_left, top: fly_top});  
  fly_calk.css({left: fly_left, top: fly_top + 89});
  
  $("div", fly_order).animate({ marginLeft: "0px" }, 700, function(){
    $("div", fly_calk).animate({ marginLeft: "0px" }, 700, function(){
      $(window).resize(function(){ fly_left = $(window).width() - 170; fly_top = fly.offset().top; fly_order.css({left: fly_left, top: fly_top}); fly_calk.css({left: fly_left, top: fly_top + 89}); });
      set_top();
    });   
  });
}

function set_top() {
  var doc = $(document);
  if (is_fly) {
    if (doc.scrollTop() > fly_top) {
      jqSlideTo('fly_order', fly_left, doc.scrollTop(), 500);
      jqSlideTo('fly_calk', fly_left, doc.scrollTop()+89, 500);
    } else { 
      jqSlideTo('fly_order',fly_left, fly_top, 500); 
      jqSlideTo('fly_calk',fly_left, fly_top + 89, 500);     
    }
  }
}

function fnOC(obj) {
  var e = $(obj).parents('div:eq(0)');
  var em = e.parent();
  if (em.width() > 42) {  
    e.animate({ marginLeft: "128px" }, 300, function(){
     em.css({ left: fly_left + 128 + 'px', width: 42 + 'px' });
     e.css({ 'margin-left': 0 + 'px' });
      if (em.hasClass('forder_open')) {
        em.removeClass('forder_open').addClass('forder_close');
      } else if (em.hasClass('fcalk_open')) {
        em.removeClass('fcalk_open').addClass('fcalk_close');
      }        
     is_fly = 1;  
    });    
  } else {
    is_fly = 1;    
    em.css({ left: fly_left, width: 170 + 'px' });
    e.css({ marginLeft:'128px' });
    e.animate({ marginLeft: "0px" }, 300, function(){
     if (em.hasClass('forder_close')) {
       em.removeClass('forder_close').addClass('forder_open');
     } else if (em.hasClass('fcalk_close')) {
       em.removeClass('fcalk_close').addClass('fcalk_open');
     }        
    });
  }
}

function fnMainInit() {
  var bl1h = 0;
  var bl1i = $("div.d_block1");  
  bl1i.each(function(){
    var midblock = $(this).children("div").eq(1);
    if (midblock) {
      if (bl1h < midblock.height()) {
         bl1h = midblock.height();
      }
    }
  });
  bl1i.each(function(){
    var midblock = $(this).children("div").eq(1);
    midblock.height(bl1h);
  });
  
  var bl3h = 0;
  var bl3i = $("div.d_block3");  
  bl3i.each(function(){
    var midblock = $(this).children("div").eq(1);
    if (midblock) {
      if (bl3h < midblock.height()) {
         bl3h = midblock.height();
      }
    }
  });
  bl3i.each(function(){
    var midblock = $(this).children("div").eq(1);
    midblock.height(bl3h);
  });  

  var bl2h = 0;
  var bl2i = $("div.d_block2");  
  bl2i.each(function(){
    var midblock = $(this).children("div").eq(1);
    if (midblock) {
      if (bl2h < midblock.height()) {
         bl2h = midblock.height();
      }
    }
  });
  bl2i.each(function(){
    var midblock = $(this).children("div").eq(1);
    midblock.height(bl2h);
  });  
  
  
  var blocks = $('div.d_block');
  blocks.hover(
    function () {
      var i = $(this).children("div").eq(0).attr("class").substr(2,1);
      for(j=0; j<3; j++) $(this).children("div").eq(j).removeClass("d_"+i+j).addClass("d_"+i+j+"s");
    },
    function () {
      var i = $(this).children("div").eq(0).attr("class").substr(2,1);
      for(j=0; j<3; j++) $(this).children("div").eq(j).removeClass("d_"+i+j+"s").addClass("d_"+i+j);
    }
  );
 
  $(".imiw").mouseenter(function(){
     var id = $(this).attr("item");
     fnShowMIW(id, $(this));
  });
  $(".imiw").mouseleave(function(){
    fnCloseMIW();    
  });
  
  $(".arrow_w").mouseover(function(){
    var id = $(this).attr("item");
    $(this).show();
    $("#miw_"+id+"").show();
  });
  $(".arrow_w").mouseout(function(){
    var id = $(this).attr("item");
    $(this).hide();
    $("#miw_"+id+"").hide();
  });
    
  $(".main_info_wind").mouseover(function(){
    var id = $(this).attr("item");
    $(this).show();
    $("#arrow_w"+id+"").show();
  });  
  $(".main_info_wind").mouseout(function(){
    var id = $(this).attr("item");
    $(this).hide();
    $("#arrow_w"+id+"").hide();
  });  
  
  
  $(".itfly").mouseenter(function(){
     var id = $(this).attr("item");
     fnShowTMIW(id, $(this));
  });
  $(".itfly").mouseleave(function(){
    fnCloseTMIW();    
  });
  
  $(".tfly").mouseover(function(){
    carousel.stopAuto();
    $(this).show();
  });  
  $(".tfly").mouseout(function(){
    carousel.startAuto();
    $(this).hide();
  });   
  
}

function fnShowTMIW(id, obj) {
  var miw = $("#tfly_"+id+"");
  var obj2 = $("#resp_block");
  ttop = obj2.offset().top + 102;
  tleft = obj.offset().left;  
  miw.css("left", (tleft - 94) + "px");
  miw.css("top", (ttop + 8) + "px");  
  miw.show();
}

function fnCloseTMIW() {
  var miw = $(".tfly");
  miw.hide();
}

function fnShowMIW(id, obj) {
  var miw = $("#miw_"+id+"");
  var aw = $("#arrow_w"+id+"");
  ttop = obj.offset().top;
  tleft = obj.offset().left;
  
  var v = fnMIWviewport();

    // check horizontal position
    if (v.x + v.cx < tleft + miw.width()) {
      left -= miw.width() + 20;
      miw.css({left: left + 'px'});
    } else {
      miw.css("left", (tleft + 22) + "px");
      aw.css("left", (tleft + 5) + "px");
    }
    // check vertical position
    if (v.y + v.cy < ttop + 20 + miw.height()) {
      var top = ttop - miw.height() + 120;
      miw.css("top", top+"px");
      aw.css("top", (ttop - 6) + "px");
    } else {
      miw.css("top", (ttop - 55) + "px");
      aw.css("top", (ttop - 6) + "px");
    }    
  miw.show();
  aw.show(); 
}

function fnCloseMIW() {
  var miw = $(".main_info_wind");
  var aw = $(".arrow_w");  
  miw.hide();
  aw.hide(); 
}

function fnMIWviewport() {
  return {
    x: $(window).scrollLeft(),
    y: $(window).scrollTop(),
    cx: $(window).width(),
    cy: $(window).height()
  };
}

/* Photo */

 function change_img (imgtext,imgid,link) {
   document.getElementById('imgimg').src=link;
   $('#imgtitle2').text(imgtext);
   $('#slider li IMG').css('opacity','0.6');
   $('#'+imgid).animate({ opacity:1 }, 200 );
   globalthamb = baseref+link;
 }
 function setactivethumb(obj) { $('#'+obj.id).css('opacity',1); }
 function setnoactivethumb(obj) { if (globalthamb != obj.src.replace('-s','')) $('#'+obj.id).css('opacity','0.6'); }
 
 
 
 /* Carusel */
 var carousel;
 var is_move = 1;
 
function mycarousel_initCallback(carousel2) {
  carousel = carousel2;
  // Pause autoscrolling if the user moves with the cursor over the clip.
  /*carousel.clip.hover(function() {
      carousel.stopAuto();
  }, function() {
     if (is_move) {
       carousel.startAuto();
     }
  });*/
  
  $('#my_next').bind('click', function() {
      carousel.next();
      return false;
  });

  $('#my_prev').bind('click', function() {
      carousel.prev();
      return false;
  });  
  
};
