if (!Array.indexOf) {
  Array.prototype.indexOf = function (obj, start) {
    for (var i = (start || 0); i < this.length; i++) {
      if (this[i] == obj) {
        return i;
      }
    }
  }
}

function getSizeLite(el){
		return {
			wb:el.offsetWidth||0,
			hb:el.offsetHeight||0
		};
}

function getPositionLite(el)
{
	var x = 0, y = 0;
	while(el) {
		x += el.offsetLeft || 0;
		y += el.offsetTop || 0;
		el = el.offsetParent;
	}
	return { x:x, y:y };
}

var is_scrolling = false;
var scroller,scroller_pos,scroller_size,cont_size;

function changeScrollPos(x) {
  if (x<0)
    x=0;
  if (x>scroller_size.wb-5)
    x = scroller_size.wb-5;
  $(">.track",scroller).css("left",x);
  var items_pos = x/scroller_size.wb*cont_size;
  $("#items")[0].scrollLeft=items_pos;
}

function onScrollerMouseMove(e) {
    if (!is_scrolling)
      return false;
    var evt=window.event;
    var ss = getPositionLite($("#contentcolumn .inner")[0]);
    scroller_pos = ss.x+44;
    var x=(e.pageX==null ? evt.clientX : e.pageX)-scroller_pos-2;
    changeScrollPos(x);
}

function onScrollerMouseUp(e) {
    if (!is_scrolling)
      return false;
    is_scrolling = false;
    $(document.body).unbind("mousemove");
}

function bindScroller() {
  if (!$("ul#items")[0])
    return;
  $("#items").parent().parent().bind("selectstart",function(e ) { return false; });
  $("#items").parent().parent()[0].setAttribute("unselectable", "on");
  scroller = $("#hor-scroller")[0];
  scroller_size = getSizeLite(scroller);
  cont_size = parseInt($("#items li:last").css("left"))+95+40-scroller_size.wb;
  $(scroller).css("visibility","visible").click(function(e) {
    var evt=window.event || e;
    var ss = getPositionLite($("#contentcolumn .inner")[0]);
    scroller_pos = ss.x+44;
    var x=(e.pageX==null ? evt.clientX : e.pageX)-scroller_pos-2;
    changeScrollPos(x);
  });
  $(">.track",scroller).bind("mousedown",function(e) {
    var evt=window.event;
    is_scrolling = true;
    var ss = getPositionLite($("#contentcolumn .inner")[0]);
    scroller_pos = ss.x+44;
    var x=(e.pageX==null ? evt.clientX : e.pageX)-scroller_pos-2;
    changeScrollPos(x);
    $(document.body).bind("mousemove",onScrollerMouseMove).one("mouseup",onScrollerMouseUp);  
  });
  $("#items").bind('mousewheel', function(event, delta) {
    var x= parseInt($(">.track",scroller).css("left"));
    x -= delta*10;
    changeScrollPos(x);
    event.stopPropagation();
    return false;
  });
}  

function bindGalleryKeys() {
  if ($("#items")[0]) {
    $.hotkeys.remove("right");
    $.hotkeys.remove("left");
    $.hotkeys.add("right",{ type:"keydown" },function() {
      var nextimage = $("#items .selected").next()[0];
      if (!nextimage)
        nextimage = $("#items li:first")[0];
      if (nextimage) {
        $("#items")[0].scrollLeft = parseInt($(nextimage).css("left"))-3;
        $("a:first",nextimage).trigger("click");
      }
    });
    $.hotkeys.add("left",{ type:"keydown" },function() {
      var previmage = $("#items .selected").prev()[0];
      if (!previmage)
        previmage = $("#items li:last")[0];
      if (previmage) {
        $("#items")[0].scrollLeft = parseInt($(previmage).css("left"))-3;
        $("a:first",previmage).trigger("click");
      }
  });
  }
}

var att_rounded,fld_rounded;
    var settings = {
      tl: { radius: 8 },
      tr: { radius: 8 },
      bl: { radius: 8 },
      br: { radius: 8 },
      antiAlias: true
    }
    
function basketChanged() {
  $.post("/basket/get_content/",{ ms:new Date().getTime() },function(result) {
    $("#basket_info .inner").html(result);
  });
}

var ival2 = null;
var ival3 = null;    
    
function changeQuantity(elem,type) {
  var inp = $("input[name='quantity']",$(elem).parent()[0])[0]; 
  var item_id = $(inp).attr("item_id");
  var q = parseInt(inp.value);
  if (isNaN(q)) {
    inp.value='0';
    return;
  }
  var err = "Произошла ошибка во время изменения кол-ва товара в корзине";
  $.ajaxSetup({"error":function(XMLHttpRequest,textStatus, errorThrown) {
      alert(err);   
  }});
  switch (type) {
    case 'up':
      q++;
      break;
    case 'down':
      if (q<=0)
        return;
      q--;
      break;
  }
  $.getJSON("/basket/change/",{ item_id:item_id,quantity:q,ms:new Date().getTime() },function(result) {
    if (!result || result.error) {
      var error = result.error || err;
      alert(error);
      return;
    }
    if (result) {
       inp.value = q;
       $("#basket .total .summ").html(result.total+"&nbsp;руб.");
       basketChanged();        
    }
  },function() {
    alert(err);
  });
}

var ival = null;

function bindBasketFunctions() {
  $("#header .basket").hover(function() {
    if (ival) {
      clearInterval(ival);
      ival = null;
    }
    $("#basket_info").show();  
  },function() {
    if (ival) {
      clearInterval(ival);
      ival = null;
    }
    ival = setInterval(function() {
      $("#basket_info").hide();  
    },1000); 
  });
  $("#basket_info").hover(function() {
    if (ival) {
      clearInterval(ival);
      ival = null;
    }
  },function() {
    if (ival) {
      clearInterval(ival);
      ival = null;
    }
    ival = setInterval(function() {
      $("#basket_info").hide();  
    },1000); 
  });
  
  $("#basket .quantity .arrow-up").click(function() {
    changeQuantity(this,'up');
    return false;
  });
  $("#basket .quantity .arrow-down").click(function() {
    changeQuantity(this,'down');
    return false;
  });
  $("#basket .quantity input[name='quantity']").bind("change",function() {
    changeQuantity(this);
    return false;
  });
  $("#item_info .basket").click(function() {
      var item_id = $(this).attr("item_id");
      var err = "Произошла ошибка во время добавления товара в корзину";
      $.ajaxSetup({"error":function(XMLHttpRequest,textStatus, errorThrown) {
          alert(err);   
      }});
      $.getJSON("/basket/add/",{ item_id:item_id,ms:new Date().getTime() },function(result) {
        if (!result || result.error) {
          var error = result.error || err;
          alert(error);
          return;
        }
        if (result) {
         basketChanged();        
         alert("Товар добавлен в корзину");
        }
      },function() {
        alert(err);
      });
      return false;
  });
}

function checkOrder() {
  if ($("#order-step-1:visible")[0]) {
    $("#order-step-1 .next").triggerHandler("click");
  }
  if ($("#order-step-2:visible")[0]) {
    $("#order-step-2 .next").triggerHandler("click");
  }
  if ($("#order-step-3:visible")[0]) {
    $("#make_order_btn").triggerHandler("click");
  }
  return false;
}

function bindOrderFunctions() {
  $("#order-step-1 .next").click(function() {
    $("#order-step-1").hide();
    $("#order-step-2").show();
    if (!fld_rounded && !$.browser.opera) {
      curvyCorners(settings, ".field2");
      fld_rounded = true;
    }
    $("#order-steps .active-label-1").removeClass("active-label-1").addClass("label-1");     
    $("#order-steps .label-2").removeClass("label-2").addClass("active-label-2");     
    return false;
  });
  $("#order-step-2 .next").click(function() {
    var contact_type;
    $("#order-step-2 input[name='contact_type']").each(function() {
      if (this.checked)
        contact_type = this.value;
    });
    var errors = "";
    $("#order-step-2 .form .field_row[ct='"+contact_type+"']").each(function() {
      if ($(".label .star",this)[0]) {
        if ($(".field2 input",this)[0])
          val = $(".field2 input",this).attr("value");
        else
          val = $(".field2 textarea",this).attr("value");
        if (!val)
          errors += (errors!="" ? "<br/>" : "")+"Заполните поле '"+$(".label",this).text().replace("*","")+"'";        
      }
    });
    if (errors) {
      $("#order-step-2 .form .errors div").html(errors);
      $("#order-step-2 .form .errors").show();
      return false;
    } else {
      $("#order-step-2 .form .errors").hide();
    }    
    var tbl =$("#order-step-3 .contact-form")[0]; 
    $(tbl).empty();
    $(tbl).append(
      $("<tr/>")
        .append( $("<td/>").addClass("label").text( "вид лица" )[0])
        .append( $("<td/>").addClass("value").text( contact_type=="1" ? "Физическое лицо" : "Юридическое лицо" )[0])[0]
    );
    $("#order-step-2 .form .field_row[ct='"+contact_type+"']").each(function() {
      var r = $("<tr/>")[0];
      var val;
      if ($(".field2 input",this)[0])
        val = $(".field2 input",this).attr("value");
      else
        val = $(".field2 textarea",this).attr("value");
      $(r)
        .append( $("<td/>").addClass("label").text( $(".label",this).text().replace("*","") )[0])
        .append( $("<td/>").addClass("value").text( val )[0])
      $(tbl).append(r);      
    });

    $("#order-step-2").hide();
    $("#order-step-3").show();
    if (!att_rounded && !$.browser.opera) {
      curvyCorners(settings, "#order-step-3 .attention");
      att_rounded = true;
    }
    $("#order-steps .active-label-2").removeClass("active-label-2").addClass("label-2");     
    $("#order-steps .label-3").removeClass("label-3").addClass("active-label-3");     
    return false;
  });  
  $("#order-step-2 .back").click(function() {
    $("#order-step-2").hide();
    $("#order-step-1").show();
    $("#order-steps .active-label-2").removeClass("active-label-2").addClass("label-2");     
    $("#order-steps .label-1").removeClass("label-1").addClass("active-label-1");     
    return false;
  });  
  $("#order-step-3 .back").click(function() {
    $("#order-step-3").hide();
    $("#order-step-2").show();
    $("#order-steps .active-label-3").removeClass("active-label-3").addClass("label-3");     
    $("#order-steps .label-2").removeClass("label-2").addClass("active-label-2");     
    return false;
  });
  $("#order-step-2 input[name='contact_type']").click(function() {
    var type = this.value;
  });
  $("#make_order_btn").click(function() {
    $("#order-form").submit();
    return false;
  });  
}

function makeCurvyCorners() {
  if ($.browser.opera)
    return;
  curvyCorners(settings, ".field");
  curvyCorners(settings, ".round");
  curvyCorners({
      tl: { radius: 8 },
      bl: { radius: 8 },
      antiAlias: true
    }, ".rounded-l");
}

var pival = null;

function bindPoints() {
  $("#points .point").hover(function() {
    if (pival) {
      clearInterval(pival);
      pival = null;
    }
    $("#points .point_desc:visible").stop(true,true).fadeOut(300);
    $(this).next().stop(true,true).fadeIn(300);
    if (!$(this).next().is(".rounded") && !$.browser.opera) {
      curvyCorners(settings,$(this).next().find("span:first")[0]);
      $(this).next().addClass("rounded");
    }    
  },function() {
    if (pival) {
      clearInterval(pival);
      pival = null;
    }
    var el=this;
    pival = setInterval(function() {
      $(el).next().stop(true,true).fadeOut(300);    
    },1000); 
  });
  $("#points .point_desc").hover(function() {
    if (pival) {
      clearInterval(pival);
      pival = null;
    }
  },function() {
    if (pival) {
      clearInterval(pival);
      pival = null;
    }
    var el=this;
    pival = setInterval(function() {
      $("#points .point_desc:visible").stop(true,true).fadeOut(300);
    },1000); 
  });
}

function bindGallerySlider() {
  $("#slider .gallery a").click(function() {
    $("#slider .selected").removeClass("selected");
    $(this).addClass("selected");
  	var fw = 720;
  	var fh = 485;
  	var picw = parseInt($(this).attr("rw"));
  	var pich = parseInt($(this).attr("rh"));
  	if (isNaN(picw) || !pich)
  	 picw = 720;
  	if (isNaN(picw) || !pich)
  	 pich = 485;
  	$("#gallery .loading").hide();
  	var isLoading = false;
  	var ival = setInterval(function() { 
  			$("#gallery .loading").show();
  			isLoading = true;
  			$("#gallery #fullimage").hide();
  			clearInterval(ival); 
  			ival = null; 
  		},500);
  	var is_main = $(this).is(".is_main");
  	$.preload([ $(this).attr("href") ], {
  		onFinish: function(data) {
        if (ival) {  		
    			clearInterval(ival);
    			ival = null;
  			}
  			if (!is_main)
  			 $("#points").hide();
  			else
  			 $("#points").show();
  			$("#gallery .loading").hide();
  			var oldwidth = parseInt($("#gallery").css("width"));
  			var oldheight = parseInt($("#gallery").css("height"));
        if (isLoading) {
          $("#gallery #fullimage .active").hide();
        }
        $("#gallery #fullimage").show();
        var imgel = ($("#gallery #fullimage img.first").is(".active") ? $("#gallery #fullimage img.second")[0] : $("#gallery #fullimage img.first")[0]);
        $("#gallery")[0].customAnimate = true;
        $("#gallery")[0].op = 1;
        $("#gallery")[0].params = { isLoading:isLoading,oldwidth:oldwidth,oldheight:oldheight,newwidth:fw+2,oldElem:$("#gallery #fullimage .active")[0],newElem:imgel };
        $(imgel).attr({ "src":data.image }).css({ "marginLeft":(fw-picw)/2,"marginTop":(fh-pich)/2 }).show();
  			$("#gallery").stop().animate({ width:fw+2,height:fh+2,op:0 },{
          duration: 1000,complete:function() {
            $("#gallery #fullimage .active").removeClass("active").css({ "left":1,"marginLeft":0,"marginTop":0 });
            $(imgel).addClass("active");
            $("#gallery")[0].params = null;
          } });          
  		}
  	})

    return false;
  });
}

function closeGallery() {
	$("#fullimage2 .loading").stop();
	$("#fullimage2").stop().css({ width:2,height:150,"margin-left":-1,"margin-top":-1 }).hide();
	$("#fullimage2 > img.full").hide();
	$("#fullimage2").stop();
	$("#overlay").fadeOut(500);
	return false;
};

function setImageHeight(w,h,isAnimated) {
	if (w>0 && h>0) {
		var fh = h;
		var fw = w;
		$("#fullimage2 .loading").css({
		  left:45,
			height:Math.round(fh)+10,
			width:Math.round(fw)
		});
		$("#fullimage2").css({ height:Math.round(fh)-1,"margin-top":Math.round(-fh/2-20) }).show();
 		if ($.browser.safari || !isAnimated)
  		  $("#fullimage2").css({ 
  			marginLeft:Math.round(-fw/2),
  			width:Math.round(fw)
  		});
		else 
		  $("#fullimage2").animate({ 
			marginLeft:Math.round(-fw/2),
			width:Math.round(fw)
		}, 500 );
		$("#fullimage2 .loading img").css({ "margin-top":Math.round((fh-1))/2-10 });
	}
}


function bindGalleryImages() {
  $("a > img.gallery_image").click(function(e) {
    e.preventDefault();
    fw = 30;
    fh = 30;
    var txt = $(this).parent().attr("title");
    if (txt && txt!="") {
      $("#fullimage2 .fullimagedesc").text(txt).show();
    } else 
      $("#fullimage2 .fullimagedesc").text("").hide();
  	setImageHeight(fw,fh,false);
		$("#overlay").css("opacity",0).show().fadeTo(500,0.6);
  	$("#fullimage2 .loading").hide();
  	$("#fullimage2 .loading img").hide();
  	var full_image  = $("#fullimage2 > img.full")[0];
  	ival = setInterval(function() { 
  			$("#fullimage2 .loading").show();
  			$("#fullimage2 .loading img").show();
  			$(full_image).hide();
  			clearInterval(ival); 
  			ival = null; 
  		},100);
  	$.preload([ $(this).parent().attr("href") ], {
  		onFinish: function(data) {
  			clearInterval(ival);
  			ival = null;
  			$("#fullimage2 > .loading").hide(); 
  			$(full_image).attr({ "src":data.image });//.fadeIn(300);
  			 $(full_image).css({ width:"auto",height:"auto" });
  			fw = $(full_image).width();
  			fh = $(full_image).height();
  			if (fh>400) {
  			 fw = Math.round(400/fh*fw);
  			 fh = 400;
  			 $(full_image).css({ width:fw,height:fh });
        }
        if (txt && txt!="") {
          fh+=30;
        }        
  			$(full_image).fadeIn(300);
  			setImageHeight(fw,fh,true);
      } 
    });
    return false;
  });
}


      
$(document).ready(function() {
	$("#overlay").click(closeGallery);
  bindGalleryKeys();
  bindGalleryImages();  
    var $_fx_step_default = $.fx.step._default;
    $.fx.step._default = function (fx) {
      if (!fx.elem.customAnimate) return $_fx_step_default(fx);
        if (fx.prop=="op" && fx.elem.params) {
          if ($(fx.elem.params.oldElem).css("opacity")>fx.now && !fx.elem.params.isLoading)
            $(fx.elem.params.oldElem).css("opacity",fx.now);
          $(fx.elem.params.newElem).css("opacity",1-fx.now);
        } else {
          if (fx.prop=="width" && fx.elem.params) {
            $(fx.elem.params.oldElem).css("left",1+Math.round(fx.now-fx.elem.params.oldwidth)/2);
            $(fx.elem.params.newElem).css("left",1+Math.round(-fx.elem.params.newwidth/2+fx.now/2));
          }
          fx.elem.style[fx.prop] = fx.now+ fx.unit;
        }
        fx.elem.updated = true;
    };  		

  bindPoints();
  bindBasketFunctions();
  bindOrderFunctions();
  makeCurvyCorners();
  bindGallerySlider();
  
  $("#items a").click(function() {
    $("#slider .selected").removeClass("selected");
    $("#items .selected").removeClass("selected");
    $(this).parent().addClass("selected");
    var newimg = $("img:first",this);
  	var fw = 720; //parseInt($(newimg).attr("rw"));
  	var fh = 485; //parseInt($(newimg).attr("rh"));
  	$("#gallery .loading").hide();
  	var isLoading = false;
  	var ival = setInterval(function() { 
  			$("#gallery .loading").show();
  			isLoading = true;
  			$("#gallery #fullimage").hide();
  			clearInterval(ival); 
  			ival = null; 
  		},500);
  		
    var item_id = $(this).attr("item_id");
    document.location.hash = item_id;
  	$.preload([ $(this).attr("full_href") ], {
  		onFinish: function(data) {  		
      $.ajaxSetup({ async:false });
      var info = null;
    	$.getJSON("/ajax/items/",{ id:item_id,ms:new Date().getTime() },function(obj) {
    		info = obj;
    	});
    	if (!info && !info.id) {
    	 alert("Произошла ошибка во время получения информации о товаре");
      }
      if (info.photos && info.photos.length>0) {
        $("#slider .gallery a").unbind("click").remove();
        if (info.pic)
          $("#slider .gallery").append(
            $("<a/>").addClass("selected").addClass("is_main").attr({ href:"/img/items/"+item_id+"/"+info.pic }).css("top",0).html("<img src=\"/img/items/thumbs/photos/"+item_id+"/"+info.pic+"\"/>")[0]
          )
        for(i=0;i<info.photos.length;i++) {
          var photo = info.photos[i];
          photo.y = parseInt(photo.y);
          $("#slider .gallery").append(
            $("<a/>").attr({ href:"/img/items/"+item_id+"/"+photo.pic,rw:photo.rw,rh:photo.rh }).css("top",photo.y).html("<img src=\"/img/items/thumbs/photos/"+item_id+"/"+photo.pic+"\"/>")[0]
          )
        }
        bindGallerySlider();
        $("#slider").show();
      } else {
        $("#slider .gallery a").unbind("click").remove();
        $("#slider").hide();
      }
      $("#item_info h2").text(info.name);
      $("#item_info .basket").attr("item_id",info.id);
      if (info.old_price && info.old_price!="0") {
        $("#item_info .old_price span").text(info.old_price+" руб.");
        $("#item_info .old_price").show();
      } else
        $("#item_info .old_price").hide();
      if (info.price && info.price!="0") {
        $("#item_info .price").text(info.price+" руб.").show();
      }  else
        $("#item_info .price").hide();
      $("#points").empty().show();
      if (info.texts && info.texts.length>0) {
        for(j=0;j<info.texts.length;j++) {
          var px = parseInt(info.texts[j].x);          
          var py = parseInt(info.texts[j].y);
          var pt = info.texts[j].desc;          
          var p = $("<div/>").addClass("point").css({left:px,top:py})[0];
          var pd =$("<div/>").addClass("point_desc").css({left:px+30,top:py})
            .append( $("<span/>").addClass("round")[0] )       
            .append( $("<div/>").addClass("inner").html(pt)[0] )[0];       
          $("#gallery #fullimage #points").append(p).append(pd);
        }
        bindPoints();
      }                                  
  			clearInterval(ival);
  			ival = null;
  			$("#gallery .loading").hide();
  			var oldwidth = parseInt($("#gallery").css("width"));
  			var oldheight = parseInt($("#gallery").css("height"));
        if (isLoading) {
          $("#gallery #fullimage .active").hide();
        }
        $("#gallery #fullimage").show();
        var imgel = ($("#gallery #fullimage img.first").is(".active") ? $("#gallery #fullimage img.second")[0] : $("#gallery #fullimage img.first")[0]);
        $("#gallery")[0].customAnimate = true;
        $("#gallery")[0].op = 1;
        $("#gallery")[0].params = { isLoading:isLoading,oldwidth:oldwidth,oldheight:oldheight,newwidth:fw+2,oldElem:$("#gallery #fullimage .active")[0],newElem:imgel };
        $(imgel).attr({ "src":data.image }).show();
  			$("#gallery").stop().animate({ width:fw+2,height:fh+2,op:0 },{
          duration: 1000,complete:function() {
            $("#gallery #fullimage .active").removeClass("active").css({ "left":1,"marginLeft":0,"marginTop":0 });
            $(imgel).addClass("active");
            $("#gallery")[0].params = null;
          } });          
  		}
  	})
  	return false;
  
  });
  $("#mainmenu > li").hover(function() {
    if (ival2) {
      clearInterval(ival2);
      ival2 = null;
    }
    $("#mainmenu .submenu").hide();
    $(this).find(".submenu").stop(true,true).fadeIn(300);
  },function() {
    if (ival2) {
      clearInterval(ival2);
      ival2 = null;
    }
    var el = this;
    ival2 = setInterval(function() {
      $(el).find(".submenu").stop(true,true).fadeOut(300);
    },1000); 
  })
  $("#mainmenu .submenu").hover(function() {
    if (ival2) {
      clearInterval(ival2);
      ival2 = null;
    }
  },function() {
    if (ival2) {
      clearInterval(ival2);
      ival2 = null;
    }
    var el=this;
    ival2 = setInterval(function() {
      $(el).stop(true,true).fadeOut(300);
    },1000); 
  });
  $("#order-step-2 input[name='contact_type']").click(function() {
    var ct = this.value;
    $("#order-step-2 .form tr[ct]").hide();
    $("#order-step-2 .form tr[ct='"+ct+"']").show();
  });
  $("#slider").hover(function() {
    $("#slider .inner").css("opacity","").stop().fadeIn(500);
  },function() {
    $("#slider .inner").css("opacity","").stop().fadeOut(500);
  });
  $("#slider #next").click(function() {
    var sc = parseInt($("#slider .gallery")[0].scrollTop);
    $("#slider .gallery")[0].scrollTop = sc+48;
    return false;
  }); 
  $("#slider #prev").click(function() {
    var sc = $("#slider .gallery")[0].scrollTop;
    $("#slider .gallery")[0].scrollTop = sc-48;
    return false;
  });
  jQuery("#arrow-right").click(function() {
    var pos = jQuery("#items")[0].scrollLeft+jQuery("#items")[0].offsetWidth;
    jQuery("#items").animate({ "scrollLeft":pos },500,function() {
      var items_pos = jQuery("#items")[0].scrollLeft; 
      $(">.track",scroller).css("left",Math.round(items_pos*scroller_size.wb/cont_size));
    });
    return false;
  });
  jQuery("#arrow-left").click(function() {
    var pos = jQuery("#items")[0].scrollLeft-jQuery("#items")[0].offsetWidth;
    jQuery("#items").animate({ "scrollLeft":pos },500,function() {
      var items_pos = jQuery("#items")[0].scrollLeft; 
      $(">.track",scroller).css("left",Math.round(items_pos*scroller_size.wb/cont_size));
    });
    return false;
  });
  $("#categories > li > a").hover(function() {
      $("#categories .floating_submenu").hide(); 
      var el = $(this).next().is(".floating_submenu") ? $(this).next()[0] : null;
      if (ival3) {
        clearInterval(ival3);
        ival3 = null;
      }
      if (el) {
        if ($.browser.msie && $.browser.version<7)
          $(this).parent().css("z-index",2);
        $(el).show();
      }      
    },function() {
      if (ival3) {
        clearInterval(ival3);
        ival3 = null;
      }
      var el = $(this).next().is(".floating_submenu") ? $(this).next()[0] : null;
      if (el)
        ival3 = setInterval(function() {
          if ($.browser.msie && $.browser.version<7)
            $(el).parent().css("z-index",1);
          $(el).hide();
        },1000);      
    });
  $("#categories .floating_submenu").hover(function() {
      if (ival3) {
        clearInterval(ival3);
        ival3 = null;
      }
  },function() {
      if (ival3) {
        clearInterval(ival3);
        ival3 = null;
      }
      $(this).hide();
  });
  $("#feedback-form input[name='contact_name']")
    .bind("focus",function() { if (this.value=="Ваше имя") this.value=""; })
    .bind("blur",function() { if (!this.value) this.value="Ваше имя"; });
  $("#feedback-form input[name='contact_email']")
    .bind("focus",function() { if (this.value=="Ваш e-mail") this.value=""; })
    .bind("blur",function() { if (!this.value) this.value="Ваше e-mail"; });
  $("#feedback-form textarea[name='contact_body']")
    .bind("focus",function() { if (this.value=="Ваше сообщение") this.value=""; })
    .bind("blur",function() { if (!this.value) this.value="Ваше сообщение"; });
  $("#feedback-form .submit").click(function() {
    $("#feedback-form").submit();
    return false;  
  });
  if ($("#items .selected")[0]) {
    $("#items")[0].scrollLeft = parseInt($("#items li.selected:first").css("left"))-3;
  }
  bindScroller();
});
			
			