var is_show_banner = 1;
var mouse_under = 0; 
var user_look_time = 5000; 
var ban_limit = 0; 
var ban_load = 0; 

function fnShowSubMenu(obj_id, number, is_menu, menu_id, is_sell) {
 /*if (number > 0) {
   if ($("#menu_item_"+ (number - 1) +"").hasClass("menu_item")) {
     $("#menu_item_"+ (number - 1) +"").removeClass("menu_item").addClass("no_border");
   }
 }
 $("#"+obj_id+"").addClass("menu_sell");
 if (is_menu == 1) {
   $("#"+menu_id+"").css({left: ($("#"+obj_id+"").offset().left), top: 79, display: 'block' });
 }

  $("#"+obj_id+"").bind("mouseleave",function() {
    $(".menu_sell").removeClass("menu_sell");
    $(".no_border").removeClass("no_border").addClass("menu_item");
    $(".sub_menu").hide();
  }); */
}

function fnCloseSubMenu() {
//
}

function fnDivOn(id) { 
  $(id).show(); 
  $(id).prev('a').addClass('hov');
}
function fnDivOff(id) { 
  $(id).hide(); 
  $(id).prev('a').removeClass('hov');
}
function fnOff(id) { 
  e = $("#"+id+""); e.hide(); 
}
function fnOn(id, parent, y, x) { 
  if (!y) y = 51; 
  if (!x) x = 0; 
  e = $("#"+id+""); 
  e.css("top", ($(parent).offset().top + y + "px")); 
  e.css("left", ($(parent).offset().left - x + "px")); 
  e.show(); 
}

function fnShowDoc(obj_id) {
  $("#"+obj_id+"").slideToggle("slow");
}

function fnShowMap() {
  var vieWin = window.open('', '_blank', "top=100,left=100,width=546,height=414,status=0,resizable=0,scrollbars=0,titlebar=0,toolbar=0,menubar=1,location=0");
  vieWin.document.clear();
  vieWin.document.writeln('<html>');
  vieWin.document.writeln('<head>');
  vieWin.document.writeln('<title>АЛТЭКС-СОФТ::Схема проезда</title>');
  vieWin.document.writeln('<base href="http://altx-soft.ru/" />');
  vieWin.document.writeln('</head>');
  vieWin.document.writeln('<body bgcolor="#FFFFFF" align="center" style="margin:0px; padding:0px">');
  vieWin.document.writeln('<div style="background:#FFF; width:110px; font:normal 11px Tahoma; position:absolute; border:solid 1px #000; padding:4px; cursor:hand;cursor:pointer;" onClick="this.style.visibility=\'hidden\'; window.print(); window.close();"><img src="image/print.gif" width="24px" height="24px" border="0" align="absmiddle" />&nbsp;&nbsp;<b>напечатать</b></div>');
  vieWin.document.writeln('<img src="image/map.jpg" weight="533" height="419" border="0" vspace="0" />');
  vieWin.document.writeln('</body>');
  vieWin.document.writeln('</html>');
  vieWin.document.close();
return false;
}


jQuery.fn.anchorAnimate = function(settings) {

   settings = jQuery.extend({
    speed : 1100
  }, settings);  
  
  return this.each(function(){
    var caller = this
    $(caller).click(function (event) {  
      event.preventDefault()
      var locationHref = window.location.href
      var elementClick = $(caller).attr("href")
      
      var destination = $(elementClick).offset().top;
      $("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, settings.speed, function() {
        window.location.hash = elementClick
      });
        return false;
    })
  })
}


function fnBanViewInit(limit) {
  ban_limit = limit; 
  $("#bannerslist").slideView({ easeFunc: "easeInOutExpo", easeTime: 500, toolTip: false });
  click_next($('#stripTransmitter0').find("li:eq(0)"), 0);
  fnIsLoadBanners(); 
}

function click_next(obj, d) {
  var current_delay = $('#stripTransmitterface0').find("li:eq("+d+")").attr('delay')*1;
  $(obj).oneTime(current_delay, 'timer1', function(i) {
    var banner_count = $('#stripTransmitter0').find("li").size()-1;
    var current_index = $('#stripTransmitter0').find("li").children("a.current").parents('li').index();
    if (banner_count == current_index) { current_index = 0; } else { current_index++; }
    

    $(obj).stopTime('timer1');
    if (is_show_banner) {
      $('#stripTransmitter0').find("li:eq("+current_index+")").children("a").click(); 
      click_next($('#stripTransmitter0').find("li:eq("+current_index+")"), current_index);
    }
  });      
}

function fnIsLoadBanners() {
  ban_load = ban_load + 1;
  if (ban_load == ban_limit) {
    $('#stripTransmitter0 a').click(function () {
      if (mouse_under == 1) {
        is_show_banner = 0;
        $('#stripTransmitter0 li').stopTime('timer1');
        $('#stripTransmitter0 a').stopTime('timer_is_show_banner');
        var current_index = $(this).parents('li').index();
        current_delay = $('#stripTransmitterface0').find("li:eq("+current_index+")").attr('delay')*1;
        if (current_delay > 15000) { user_look_time = current_delay; 
        } else { user_look_time = 5000; }        
        $(this).oneTime(user_look_time, 'timer_is_show_banner', function() {
          $(this).stopTime('timer_is_show_banner');
          is_show_banner = 1; 
          var banner_count = $('#stripTransmitter0').find("li").size()-1;
          var current_index = $(this).parents('li').index();
          if (banner_count == current_index) { current_index = 0; } else { current_index++; }
          click_next($('#stripTransmitter0').find("li:eq("+current_index+")"), current_index);
        });             
      }
    });  
    $('#stripTransmitter0 a').hover( function () { mouse_under = 1; }, function () { mouse_under = 0; }  );       
  } 
}

/* NEW */
function fnShowProduct(id, obj) {
  var slider = $("#slider");
  $("div.mproduct", $("#mprod_block")).removeClass('sel');
  $("#"+id+"").addClass('sel');
  $("img.bl", slider).show(); $("img.col", slider).hide();
  $("img.bl", $(obj)).hide(); $("img.col", $(obj)).show();
}

/* Фон старт */

function fnCreateOverlay() {
   $('<div id="site_wrap"></div>').appendTo("body");
   $("#site_wrap").prepend('<div id="site_overlay"></div>');
   $("#site_overlay").css({'width': $(window).width(), 'height': $(document).height(), 'opacity': 0.4});
   if ($.browser.msie && $.browser.version == '6') {
    $("#site_wrap").prepend('<iframe id="site_bigIframe" scrolling="no" frameborder="0"></iframe>');
    $("#site_bigIframe").css({'width': $(window).width(), 'height': $(document).height(), 'opacity': 0});
   }
   $("#site_overlay, #site_bigIframe").hide();
}

function fnShowOverlay() {
  $("#site_overlay,#site_bigIframe").fadeIn("fast").show();
}

function fnHideOverlay() {
  $("#site_overlay,#site_bigIframe").fadeOut("fast").hide();
}

function fnCloseOverlay() {
  $("#site_overlay,#site_bigIframe").fadeOut("fast").remove();
}

/* Прокрутка страницы */
function fnHideScroll() {
  $("body").css("overflow", "hidden");
}

function fnShowScroll() {
  $("body").css("overflow", "auto");
}
/* End */

function fnShowSteps(id, parent) {
  var el = $("#"+id+""); 
  var e = $("#step_wnd"); 
  var arrow = $("#step_arrow"); 
  var menu = $("#steps");  
  var mitem = $(parent);
  var mx = 0;
  var ex = 0;
  fnShowOverlay();
  
  $("#step_content").empty().html(el.html());
  $(".wndclose a", e).click(function(){  
    mitem.removeClass('msel');
    e.hide();
    arrow.hide();
    fnHideOverlay();
    return false;
  });
  if (e.length > 0) {
    mx = mitem.offset().left + mitem.width() - 8;  
    ex = mx;        
    arrow.css("top", (mitem.offset().top + 34 + "px"));
    arrow.css("left", (mx + "px"));
    e.css("top", (mitem.offset().top - 20 + "px"));
    e.css("left", (ex + "px"));
    e.show();
    arrow.show();
    if (!mitem.hasClass('msel')) {
      mitem.addClass('msel');
    }    
  } 
}


/* Баннеры */

var af_ban_id, af_last_id, af_timerID, af_ban;
var is_show_banner = 1; 
var mouse_under = 0; 
var user_look_time = 15000;

function fnBanRotate() {
  var box = $("#ban_rotate");
  if (box.length > 0) {    
    af_ban_id = $("#bban1").attr("ban")*1;
    af_last_id = $("#bban0").attr("ban")*1;
    click_next($("#ban"+af_ban_id+""), af_ban_id);

    $("#ban_rot_href a").click(function () {
      if (mouse_under == 1) {
        $(this).remove
        is_show_banner = 0;
        $('#ban_rotate div.rban').stopTime('timer1');
        $('#ban_rot_href a').removeClass('active').addClass('none').stopTime('timer_is_show_banner');
        $(this).addClass('active');
        var current_index = $(this).attr("ban")*1;
        current_delay = $('#ban'+current_index+'').attr('delay')*1;
        if (current_delay) { user_look_time = current_delay; }
        
        $("div.show", box).removeClass('show').addClass('hide');
        $('#ban'+current_index+'').removeClass('hide').addClass('show');
        
        $(this).oneTime(user_look_time, 'timer_is_show_banner', function() {
          $(this).stopTime('timer_is_show_banner');
          is_show_banner = 1;
          var banner_count = af_last_id;
          var current_index = $(this).next('a').attr("ban")*1;
          if (!current_index) {
            current_index = af_ban_id;
          }
          click_next($('#ban'+current_index+''), current_index);
        });
      }
      return false;
    });  
    $('#ban_rot_href a').hover( function () { mouse_under = 1; }, function () { mouse_under = 0; }  );    
  }
}

function click_next(obj, d) {
  
  var box = $("#ban_rotate");
  var current_delay = $('#ban'+d+'').attr('delay')*1;
  $("div.show", box).removeClass('show').addClass('hide'); 
  obj.removeClass('hide').addClass('show');
  $('#ban_rot_href a').removeClass('active').addClass('none');
  $('a.ab'+d+'', $("#ban_rot_href")).addClass('active');
  $(obj).oneTime(current_delay, 'timer1', function(i) {
    var banner_count = af_last_id;
    var current_index = $(this).next('div').attr("ban")*1;
    if (!current_index) {
      current_index = af_ban_id;
    }
    
    $(obj).stopTime('timer1');
    if (is_show_banner) {
      //$('#ban_rot_href ').find("li:eq("+current_index+")").children("a").click(); 
      click_next($('#ban'+current_index+''), current_index);
    }
  });
  return false;      
}

function fnSwitchBan(temp_id) {
  if (temp_id > 0) id = temp_id;
  clearTimeout(timerID);
  if (id == 1) {
    id = 2;
    $('#ban1').show();
    $('#ban2').hide();
    $('#dot1').html('<img src="dot2.gif" onClick="fnClick(1)" />');
    $('#dot2').html('<img src="dot1.gif" onClick="fnClick(2)" />');
    timerID = setTimeout("fnClick()", 4000);
  } else {
    id = 1;
    $('#ban2').show();
    $('#ban1').hide();    
    $('#dot1').html('<img src="dot1.gif" onClick="fnClick(1)" />');
    $('#dot2').html('<img src="dot2.gif" onClick="fnClick(2)" />');
    timerID = setTimeout("fnClick()", 7000);
  }  
}
