
/*(function(h){var m=h.scrollTo=function(b,c,g){h(window).scrollTo(b,c,g)};m.defaults={axis:'y',duration:1};m.window=function(b){return h(window).scrollable()};h.fn.scrollable=function(){return this.map(function(){var b=this.parentWindow||this.defaultView,c=this.nodeName=='#document'?b.frameElement||b:this,g=c.contentDocument||(c.contentWindow||c).document,i=c.setInterval;return c.nodeName=='IFRAME'||i&&h.browser.safari?g.body:i?g.documentElement:this})};h.fn.scrollTo=function(r,j,a){if(typeof j=='object'){a=j;j=0}if(typeof a=='function')a={onAfter:a};a=h.extend({},m.defaults,a);j=j||a.speed||a.duration;a.queue=a.queue&&a.axis.length>1;if(a.queue)j/=2;a.offset=n(a.offset);a.over=n(a.over);return this.scrollable().each(function(){var k=this,o=h(k),d=r,l,e={},p=o.is('html,body');switch(typeof d){case'number':case'string':if(/^([+-]=)?\d+(px)?$/.test(d)){d=n(d);break}d=h(d,this);case'object':if(d.is||d.style)l=(d=h(d)).offset()}h.each(a.axis.split(''),function(b,c){var g=c=='x'?'Left':'Top',i=g.toLowerCase(),f='scroll'+g,s=k[f],t=c=='x'?'Width':'Height',v=t.toLowerCase();if(l){e[f]=l[i]+(p?0:s-o.offset()[i]);if(a.margin){e[f]-=parseInt(d.css('margin'+g))||0;e[f]-=parseInt(d.css('border'+g+'Width'))||0}e[f]+=a.offset[i]||0;if(a.over[i])e[f]+=d[v]()*a.over[i]}else e[f]=d[i];if(/^\d+$/.test(e[f]))e[f]=e[f]<=0?0:Math.min(e[f],u(t));if(!b&&a.queue){if(s!=e[f])q(a.onAfterFirst);delete e[f]}});q(a.onAfter);function q(b){o.animate(e,j,a.easing,b&&function(){b.call(this,r,a)})};function u(b){var c='scroll'+b,g=k.ownerDocument;return p?Math.max(g.documentElement[c],g.body[c]):k[c]}}).end()};function n(b){return typeof b=='object'?b:{top:b,left:b}}})(jQuery);

(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:1,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);
*/
var i = 1;
	function loadMap() {
	   var placemark;
   map = new YMaps.Map(document.getElementById("map"));
   map.setCenter(new YMaps.GeoPoint(37.609218,55.753559), 10);
   map.addControl(new YMaps.TypeControl());
   map.addControl(new YMaps.Zoom());
   //map.enableScrollZoom();
s = new YMaps.Style();
s.iconStyle = new YMaps.IconStyle();
s.iconStyle.offset = new YMaps.Point(0, 0);
s.iconStyle.href = "http://www.lideravto.com/i/mapicon.png";
s.iconStyle.size = new YMaps.Point(50,44);

   jQuery('.YMaps-slider').css('top','10px');
   jQuery('.YMaps-logo').html('');
   jQuery('.YMaps-copyrights').html('');
   for(var a=1;a<markers.length;a++){
      placemark=new YMaps.Placemark(new YMaps.GeoPoint(markers[a][0],markers[a][1]),{style:s});
      placemark.name='<span style="color:black">'+markers[a][2]+'</span>';
      placemark.description='<a href="'+markers[a][3]+'">Подробнее</a>';
      map.addOverlay(placemark);
   }
}

function sortContent(order_by){
   jQuery('.content').hide('clip',0,1000,0);
   jQuery('.content').html('<img style="padding-left:40%" src="/loadingAnimation.gif">');
   jQuery('.content').show('clip',0,500,0);
   jQuery.post('/srpc/catalog1/contentView','order='+order_by,function(data){
      if (data){
         jQuery('.content').hide('clip',0,500,0);
         jQuery('.content').html(data);
         jQuery('.content').show('clip',0,1000,0);
      }
   });
}

function documentLoad()
{
	if ($('#map').length)
		loadMap();
	if ($('#search').length) {
/*
		var VIPMOIKA = 'Например,"31331124449" или "бампер bmw"';//Например, «96563503» или «бампер ceed»';
		$("#search").attr('value',VIPMOIKA)
	
		$("#search").css("color","#777777")
	
		$("#search").focus( function()
		{
			if ($(this).attr('value') == VIPMOIKA)
			{
				$(this).attr('value','')
				$(this).css("color", "#000000")
			}
		}
		)
		$("#search").blur( function()
		{
			if (!$(this).attr('value'))
			{
				$(this).attr('value',VIPMOIKA)
				$(this).css("color", "#777777")
			}
		}
		)
*/		
		$('#search').keypress(function()
		{
			clearInterval(i)
			i = setInterval("search()",1000)
		})

	}
	/*if ($('ul.brands').length)
	{
		$('html,body').scrollTo(340)
		// $("ul.brands").height($("ul.brands").height()*1.5)
		$('ul.brands > li').hoverIntent(
			function() {
				if ($($(this).children()[1]).children()[0])
				{
					// $(this).addClass('selected');
					$($(this).children()[1]).slideDown(300);
				}
			},
			function() {
				if ($($(this).children()[1]).children()[0])
				{
					// $(this).removeClass('selected');
					$($(this).children()[1]).slideUp(300);
				}
			}
		)
		$('ul.brands > li > ul > li > a.selected').parent().parent().show()
		$($('ul.brands > li > a.selected').parent().children()[1]).show()
	}*/
}

function search()
{
	clearInterval(i)
	if ($('#search').attr('value').length > 3)
	{
		if ($('#search').attr('value').length < 3) return
		$('.search-indicator').css('display','block');
		$.post('/srpc/catalog1/search','q='+$('#search').attr('value'),function(data){
			if (data)
			{
				$('.search-indicator').css('display','none');
				$('.content').html('')
				$('.content').prepend(data)
			}
		}
		)
	}
}

