var project={scrollOffsetX:0,scrolled:0,is_scroll:0,imageNum:0,images:['car.jpg','car_alt.jpg'],galleryTrans:0,scroll:function(){setInterval(function(){$('#tune p:first-child').each(function(){var t=this;var nm=(parseInt($(t).css('marginLeft'))-1);if(nm==-($(this).width()))
nm=0;$(this).css({marginLeft:nm+'px'})})},20)},slice:function(text,i){return text.length>=i?text.substr(0,i)+'...':text},nextImage:function(){this.imageNum++;if(this.imageNum==this.images.length)this.imageNum=0;return this.images[this.imageNum]},setScroll:function(){var scrX=-(parseInt($('.photos_in div').css('marginLeft')))*$('.photos_in').width()/$('.photos_in div').width();scrX=Math.max(7,Math.min(scrX,$('.scrollbar').width()-7));$('.scrollbar div').css('marginLeft',scrX+'px')},scrollContent:function(content,step,dir,callback){if(this.is_scroll)return;this.is_scroll=1;var prnt=content.parents()[0],func='min',offset=content.width()-$(prnt).width(),val=parseInt(content.css('marginLeft'))
if(dir=='right'){step=-step;offset=-offset;func='max'}else
offset=0;var stp=Math[func](offset,val+step);var off_right=$(prnt).width()+Math.abs(stp)==content.width();if($(prnt).is('.cars-in')){$('.asr a',$(prnt).parents('div')[0])[off_right&&dir=="left"?'addClass':'removeClass']('dis');$('.asl a',$(prnt).parents('div')[0])[stp==0&&dir=="right"?'addClass':'removeClass']('dis');$('.sh_r',$(prnt).parents('div')[0])[off_right&&dir=="left"?'addClass':'removeClass']('dis');$('.sh_l',$(prnt).parents('div')[0])[stp==0&&dir=="right"?'addClass':'removeClass']('dis')}else{$('.sh_r, .asr',$(prnt).parents('div')[0])[off_right&&dir=="left"?'hide':'show']();$('.sh_l, .asl',$(prnt).parents('div')[0])[stp==0&&dir=="right"?'hide':'show']()}
content.animate({marginLeft:stp+'px'},{duration:'slow',complete:function(){if($(prnt).is('.cars-in')){$('.asr a',$(prnt).parents('div')[0])[off_right?'addClass':'removeClass']('dis');$('.asl a',$(prnt).parents('div')[0])[stp==0?'addClass':'removeClass']('dis');$('.sh_r',$(prnt).parents('div')[0])[off_right?'addClass':'removeClass']('dis');$('.sh_l',$(prnt).parents('div')[0])[stp==0?'addClass':'removeClass']('dis')}else{$('.sh_r, .asr',$(prnt).parents('div')[0])[off_right?'hide':'show']();$('.sh_l, .asl',$(prnt).parents('div')[0])[stp==0?'hide':'show']()}
project.is_scroll=0;if(callback)callback()}})},scrollContentV:function(content,step,dir,callback){var prnt=content.parents()[0],func='min',offset=content.height()+30-$(prnt).height(),val=parseInt(content.css('marginTop'))
if(dir=='bottom'){step=-step;offset=-offset;func='max'}else
offset=0;var stp=Math[func](offset,val+step);var off_right=$(prnt).height()+Math.abs(stp)==content.height()+30;content.animate({marginTop:stp+'px'},{duration:'fast',complete:function(){$('.sh_bot',$(prnt).parents('div')[0])[off_right?'hide':'show']();$('.sh_top',$(prnt).parents('div')[0])[stp==0?'hide':'show']();if(callback)callback()}})},imageTrans:function(set,lay1,lay2){var prefix=arguments[3]||'/uploads/models/';lay2.unbind('load');lay2.bind('load',function(){$('.load').hide();lay1.fadeOut(700,function(){project.galleryTrans=0;lay1.attr('src',lay2.attr('src'));lay1.css({'top':lay2.css('top'),'left':lay2.css('left')}).show()})});lay2.attr('src',prefix+set.image).css({'left':-set.offset_x+'px','top':-set.offset_y+'px'})},hideArrows:function(index){$('.ar')[(index==$('#photo_pager a').length-1?'add':'remove')+'Class']('dis');$('.al')[(index==0?'add':'remove')+'Class']('dis')},galleryLoad:function(num){if(this.galleryTrans)return;var set=eval('('+$('#photo_pager a')[num].rel+')'),lay2=$('.gallery .image img:first-child'),lay1=$('.gallery .image img:nth-child(2)');this.galleryTrans=1;$('.load').show();$('.gallery .title span').html(set['sname']);this.imageTrans(set,lay1,lay2);$('#photo_pager a').removeClass('act');$($('#photo_pager a')[num]).addClass('act');this.hideArrows(num)},galleryHandler:function(){project.galleryLoad($('#photo_pager a').index(this));return false},scrollTo:function(scrollX){var scrMax=$('.scrollbar').width()-7-($('.scrollbar div').width()+5);if(scrollX<7)scrollX=7;scrollX=Math.min(scrollX,scrMax);$('.scrollbar div').css('marginLeft',scrollX+'px');var contentPos=$('.photos_in div').width()/$('.photos_in').width()*(scrollX)-11;$('.photos_in div').css('marginLeft',-contentPos+'px');if($('.photos_in div').width()>$('.photos_in').width()){$('.photos .asl')[scrollX==7?'hide':'show']();$('.photos .asr')[scrollX==scrMax?'hide':'show']()}},galleryPageHandler:function(){var spl=this.href.split('/').reverse(),mdl=spl[1],std=spl[0],t=$(this).parents('.photos_in').length;if(!($(this).parents('.photos').length)){if($(this).parents('.drop').length){$('.drop span').not('.edge, .edit, .close').html($('b',this).html());$('[name=study_name]').val(std)}
$('.models_in a, .drop a').each(function(){ })}
if($('.models_in a').index(this)+1)$('.models_in a').removeClass('act');$(this).addClass('act');$('.load').show();$.ajax({url:'http://'+document.domain+'/'+this.href.replace(/http:\/\/[^\/]*\//g,''),type:'GET',dataType:'json',success:function(js){var json=js['model'];$('.load').hide();if(json['count']==0){$('.gallery').fadeOut();return}
if(!($('.gallery:visible').length))$('.gallery').fadeIn();$('.photos_in div').css('width',Math.max(152*json['count'],$('.photos_in').width())+'px');$('.photos_in div a, #photo_pager a').remove();var cnt=0,code='.apply(this); event.stopPropagation?event.stopPropagation():event.cancelBubble = true; return false';$.each(json['mods'],function(i,v){$('<a rel="'+v['id']+'" href="'+v['uri']+'"'+(v['id']==json['mod']['id']?' class="act"':'')+'>'+(/admin/.test(location.href)?'<span class="pager p2 adm_buttons"><span class="corner"></span><span class="edit" onclick="project.workHandler'+code+'">Edit</span><span class="delete" onclick="project.deleteGalleryHandler'+code+'">Delete</span></span>':'')+'<img src="/uploads/models/mini_'+v['image']+'" alt="" /></a>').css({'top':-v['offset_y']+'px','left':-v['offset_x']+'px'}).appendTo('.photos_in div:first-child');cnt++});$('.photos_in div').css('width',cnt*152+'px')
var i=0,ph=$('.photos_in div a.act img');$.each(json['images'],function(j,v){$('<a href="#"></a>').appendTo('#photo_pager')});$.each(json['images'],function(j,v){$('#photo_pager a')[i++].rel=v['set']});$('#pager_out > div').css('width',(i)*14+32+'px')
ph.css({left:parseInt(ph.css('left'))-1+'px',top:parseInt(ph.css('top'))-1+'px',});project.galleryInit(t);project.galleryLoad(0,1)}});$('.drop div').hide();setTimeout(function(){$('.drop div').css('display','')},200);return false},galleryInit:function(){$('.scrollbar div').css('width',Math.min((740/($('.photos_in div').width()/$('.photos_in').width())),$('.scrollbar').width()-14)+'px');$('#photo_pager a').click(this.galleryHandler);$('.photos_in a').click(this.galleryPageHandler);if(!(arguments[0]))this.scrollTo(0)},parseEuro:function(value){return parseFloat(/&nbsp;(.*)$/.exec(value).toString().split(',')[1].replace(/\s*/g,''))},numFormat:function(number){var nums=number.toString().split('.'),thousands=parseInt(nums[0]/1000),other=nums[0].split('').reverse().slice(0,3).reverse().join('');return(thousands?thousands+' ':'')+other+(nums[1]?nums[1].split('').slice(0,2).join(''):'')},changePrice:function(val,sign){var tgt=arguments[2]||$('.sum .price_value div');var tgt_ru=arguments[3]||$('.sum .price_value span');var num=this.parseEuro(val),price=this.parseEuro(tgt.html())+(sign=='+'?num:-num),price_ru=price*euro_course;tgt.html('&nbsp;'+this.numFormat(price)+'&nbsp;&euro;');tgt_ru.html(this.numFormat(price_ru)+' б�.')},selectRow:function(tr,unsel){if(unsel)$('tr',$(tr).parents('table')[0]).addClass('disabled');tr.removeClass('disabled')},addOrderEntry:function(tr){var inp=$('input',tr[0])[0];$('<div class="item" id="feat_'+/\d+/.exec(inp.name)+'"><span>'+$('td.descr div.c',tr[0]).html()+'</span><input type="hidden" name="features[]" value="'+inp.value+'" /><div class="price_value">'+$('.price_value',tr).html()+'</div></div>').appendTo('#features');var price=/&nbsp;.*/.exec($('div.price_value',tr[0]).html());this.changePrice(price,'+');this.changePrice(price,'+',$('.title .price_value b',tr.parents('div.details')[0]),$('.title .price_value span',tr.parents('div.details')[0]))},removeOrderEntry:function(tr,oldprice){var inp=$('input',tr[0])[0];this.changePrice(oldprice,'-');this.changePrice(oldprice,'-',$('.title .price_value b',tr.parents('div.details')[0]),$('.title .price_value span',tr.parents('div.details')[0]));$('#feat_'+/\d+/.exec(inp.name)).remove();$('input[type*=ch]:checked',tr.parents('.details')[0]).parents('tr').each(function(){$(this).addClass('disabled');$('input',this).attr('checked','');project.changePrice(/&nbsp;.*$/.exec($('div.price_value',this).html()),'-');project.changePrice(/&nbsp;.*$/.exec($('div.price_value',this).html()),'-',$('.title .price_value b',tr.parents('div.details')[0]),$('.title .price_value span',tr.parents('div.details')[0]))})},changeOrderEntry:function(tr,oldprice){var price=/&nbsp;.*/.exec($('div.price_value',tr[0]).html()),inp=$('input',tr[0])[0];this.changePrice(oldprice,'-');this.changePrice(oldprice,'-',$('.title .price_value b',tr.parents('div.details')[0]),$('.title .price_value span',tr.parents('div.details')[0]));this.changePrice(price,'+');this.changePrice(price,'+',$('.title .price_value b',tr.parents('div.details')[0]),$('.title .price_value span',tr.parents('div.details')[0]));$('#feat_'+/\d+/.exec(inp.name)+'>span').html($('td.descr div.c',tr[0]).html())},addSubEntry:function(tr){var price=/&nbsp;.*/.exec($('div.price_value',tr[0]).html()),inp=$('input',tr[0])[0];this.changePrice(price,'+');this.changePrice(price,'+',$('.title .price_value b',tr.parents('div.details')[0]),$('.title .price_value span',tr.parents('div.details')[0]));$('<div id="subitem'+inp.value+'" style="margin-top:5px"><span>'+$('td.descr div.c',tr[0]).html()+'</span><input type="hidden" name="features[]" value="'+inp.value+'" /><div class="price_value">'+$('.price_value',tr).html()+'</div></div>').appendTo('#feat_'+/\d+/.exec(inp.name))},removeSubEntry:function(tr){var price=/&nbsp;.*/.exec($('div.price_value',tr[0]).html()),inp=$('input',tr[0])[0];this.changePrice(price,'-');this.changePrice(price,'-',$('.title .price_value b',tr.parents('div.details')[0]),$('.title .price_value span',tr.parents('div.details')[0]));$('#subitem'+inp.value).remove()},makeOrder:function(){if(!($('[name=name]').val())||!($('[name=phone]').val())){$('.error').css('visibility','visible');return}
var post=[];$.each($('form')[0].elements,function(i,v){post.push(v.name+'='+encodeURIComponent(v.value))});$('.error').addClass('success').html(ajax_load).css('viisbility','visible');$('.big_btn').css({'opacity':0.3,'filter':'alpha(opacity=30)','cursor':'default'});$.ajax({url:'order',type:'post',dataType:'json',data:post.join('&'),success:function(json){$('.success').html(json['message']).css('visibility','visible');if(json['status']=='OK')
setTimeout(function(){location='/'},2000)}})},detHandler1:function(){$(this).removeClass('disabled')},detHandler2:function(){$(this).addClass('disabled')},initDetails:function(){$('.details .contain tr').mouseover(this.detHandler1);$('.details .contain tr').mouseout(this.detHandler2);if($('#detail_det_dialog').length&&!$('#prop_dialog').length){$('#det1 tr').click(this.detailHandler);$('.details+.details a').click(this.paramsHandler)}
else if($('#class_dialog').length)
$('.details .contain tr.data').click(this.classHandler);else if($('#disk_size').length)
$('.details .contain tr.data').click(this.diskHandler);else if($('#car_dialog').length)
$('.details .contain tr.data').click(this.carHandler);else{$('.details .contain tr.data').click(this.propHandler);$('td.details a.first+a, td.details a.first+a+a').click(this.detailHandler);$('td.details a.first').click(function(){$('#add_detail_dialog').dialog('open');$('.ui-dialog-title',$('#add_detail_dialog').parents('.ui-dialog')[0]).html(this.innerHTML);$('#add_detail_dialog .button_panel:first-of-type').trigger('click')})}},classHandler:function(){var _new=/bu/.test(this.className),t=this;$('#class_dialog').dialog('open');$('.ui-dialog-title',$('#class_dialog').parents('ui-dialog')[0]).html(add_edit_class);if(_new)
$('#class_dialog form')[0].reset();$.each(['name','uri','brand','id'],function(i,v){$('#class_dialog [name='+v+']').val(_new?'':$('input[name='+v+']',t).val())});if(_new)$('#class_dialog [name=brand]').val($('#logos a.act').attr('rel'))},classDeleteHandler:function(){if(!(confirm(del_confirm)))return false;$('.load').show();$.ajax({url:'admin/classes',type:'post',dataType:'json',data:'act=del_class&csrf_token='+csrf_token+'&id='+$('[name=id]',$(this).parents('td')[0]).val(),success:function(){$('.load').hide();project.loadClasses.apply($('#logos a.act')[0])}});return false},loadClasses:function(){var tpl='<tr class="data disabled"><td>{name}</td><td>{uri}</td><td><a class="close" href="#">'+del_label+'</a>{hiddens}</td></tr>',hiddens='<input type="hidden" name="{name}" value="{value}" />';$('.details .title span').html(this.title);$('#logos a').removeClass('act');$(this).addClass('act');$('.load').show();$.ajax({url:this.href,type:'GET',dataType:'json',success:function(json){$('.load').hide();$('.details .contain table tr.data').remove();var count=0;$.each(json['classes'],function(i,v){var t=tpl,hd='';count++;$.each(['uri','name'],function(s,k){t=t.replace('{'+k+'}',v[k])});$.each(['name','uri','brand','id'],function(s,k){hd+=hiddens.replace('{name}',k).replace('{value}',v[k])});t=t.replace('{hiddens}',hd);$(t).appendTo('.details .contain table')});$('.nodetail')[count?'hide':'show']();project.initDetails();$('.details a.close').click(project.classDeleteHandler)}});return false},loadDetails:function(){var template='<tr class="data disabled"><td class="img"><div><img src="images/features/{image}" style="top:-{offset_y}px; left:-{offset_x}px;" /></div></td><td class="descr"><div class="price_value"><span>{price_ru}</span>{price}</div><div class="c">{name}</div>{hiddens}</td><td><a class="close" href="#">'+$('#det_list a.last').html()+'</a></td></tr>',id=$('#details_list').val().split('|')[0],name=$('#det_list option:selected').text();var param_tpl='<tr><td><input type="text" class="textfield sm" name="name" value="{name}" /><input type="hidden" name="id" value="{id}" /></td><td><input type="text" class="textfield sm" name="ci" value="{ci}" /></td><td><a class="close" href="#">'+del_label+'</a><a class="edit" href="#">'+edit_label+'</a></td></tr>';$('.details .title span').html(name);$('.load').show();$.ajax({url:$('.models_list a.act').attr('href')+'/'+id,type:'GET',dataType:'json',success:function(json){$('.load').hide();$('.details .contain table[class!=head] *').remove();var add=0,count=0;$.each(json['details'],function(i,v){var tpl=template,hd='';count++;$.each(['image','offset_x','offset_y','name','price','price_ru'],function(j,d){tpl=tpl.replace('{'+d+'}',v[d])});$.each(['id','name','price_real','article','group','sub_group','brand','model','year','year_direct','setup_price_real','color_price_real'],function(j,d){hd+='<input type="hidden" name="'+d.replace('_real','')+'" value=\''+v[d]+'\' />'});tpl=tpl.replace('{hiddens}',hd);$(tpl).appendTo('.details .contain table.main')});$('#sub-category option').remove();$.each(json['subs'],function(i,v){$('<option value="'+v['id']+'">'+v['name']+'</option>').appendTo('#sub-category select')})
$('.nodetail')[count?'hide':'show']();$.each(json['params'],function(i,v){var tpl=param_tpl;$.each(['name','id','ci'],function(j,d){tpl=tpl.replace('{'+d+'}',v[d])});$(tpl).appendTo('.details+.details .contain table+table')});project.initDetails();$('#det1 .contain table a').click(project.detailsDeleteHandler);$('.details input.textfield').keyup(project.paramsKeyHandler)}})},loadDisks:function(){var template='<tr class="data disabled"><td class="img"><div><img src="images/disks/{image}" /></div></td><td class="descr"><div class="price_value"><span>{price_ru}</span>{price}</div><div class="c">{name}</div>{hiddens}</td><td><a class="close" href="#">'+$('#size_list a.last').html()+'</a></td></tr>',id=$('#sizes_list').val(),name=$('#size_list option:selected').text();var param_tpl='<tr><td><input type="text" class="textfield sm" name="name" value="{name}" /><input type="hidden" name="id" value="{id}" /></td><td><input type="text" class="textfield sm" name="ci" value="{ci}" /></td><td><a class="close" href="#">'+del_label+'</a><a class="edit" href="#">'+edit_label+'</a></td></tr>';$('.details .title span').html(name);$('.load').show();$.ajax({url:$('.models_list a.act').attr('href')+'/'+id,type:'GET',dataType:'json',success:function(json){$('.load').hide();$('.details .contain table[class!=head] *').remove();var add=0,count=0;$.each(json['disks'],function(i,v){var tpl=template,hd='';count++;$.each(['image','name','price','price_ru'],function(j,d){tpl=tpl.replace('{'+d+'}',v[d])});$.each(['id','price_real','price2_real','price3_real','price4_real','name','article','model','type','size','diam','brand','study','article2','fld1','fld2','without_wheels','without_wheels2','without_wheels1','without_wheels_one','without_wheels_one2'],function(j,d){hd+='<input type="hidden" name="'+d.replace('_real','')+'" value=\''+v[d]+'\' />'});tpl=tpl.replace('{hiddens}',hd);$(tpl).appendTo('.details .contain table.main')});$('.nodetail')[count?'hide':'show']();project.initDetails();$('#disks_list .contain table a').click(project.diskDeleteHandler)}})},formSender:function(e){var frm=$(this).is('form')?$(this):(/ui/.test(this.className)?$('form.ajax',$(this).parents('.ui-dialog')[0]):$(this).parents('form.ajax')),flag=1,form=frm[0];if(e.type=='keyup'&&e.keyCode!=13&&e.keyCode!=10)
return
$('.required',frm[0]).each(function(i,v){if(!(this.value))flag=0});if(!flag){$('.loader',form).html(fill_all);$('.loader',frm.parents('.ui-dialog')).html(fill_all)}
else{if(frm.attr('id')=='news'&&$(this).attr('id')!='news_preview'){frm[0].submit();return false}
$('.loader',form).html('<img src="template/amg/img/ajax-loader.gif" />&nbsp;'+ajax_load);$('.loader',frm.parents('.ui-dialog')).html('<img src="template/amg/img/ajax-loader.gif" />&nbsp;'+ajax_load);frm.ajaxSubmit({url:form.action,type:'POST',dataType:'json',success:function(json){$('.loader',form).html(json['message']);$('.loader',frm.parents('.ui-dialog')).html(json['message']);if(json['status']=='OK'){if(project.callbacks[frm.attr('id')])
project.callbacks[frm.attr('id')](json);if(frm.parents('.dialog').length)
frm.parents('.dialog').dialog('close')}}})}
return false},detailHandler:function(){var frm=$('#detail_det_dialog form')[0],t=this;$('.loader').html('');$('#detail_det_dialog tr.param').remove();project.showTab('l1');project.showTab('l2',1);project.showTab('l3',1);$('#detail_det_dialog').dialog('open');$('.ui-dialog-title',$('#detail_det_dialog').parents('ui-dialog')[0]).html(this.href?this.innerHTML:$('a.right').html());$('#detail_det_dialog form').resetForm();$('select[name*=model] option').attr('selected','');if(this.href){frm.reset();frm.id.value="";frm.image.value="";project.changeModel.apply($('#detail_det_dialog select[name=brand]')[0]);project.changeStudy.apply($('#detail_det_dialog select[name=brand]')[0]);$.each(['brand','group','study'],function(i,v){$('[name='+v+']',frm).val($('[name='+v+'] option',frm)[0].value)})}else{project.changeGroup.apply($('#detail_det_dialog select[name=group]')[0]);project.changeModel.apply($('#detail_det_dialog select[name=brand]')[0]);project.changeStudy.apply($('#detail_det_dialog select[name=brand]')[0]);$.each(['id','name','article','group','sub_group','brand','setup_price','color_price','price','study'],function(i,v){$('[name='+v+']',frm).val($('[name='+v+']',t).val())});project.changeModel.apply($('#detail_det_dialog select[name=brand]')[0]);var models=eval('('+$('[name=model]',t).val()+')');$('#detail_det_dialog [name*=model] option').attr('selected','');$.each(models,function(i,v){$('select[name*=model] [value='+v+']').attr('selected','selected')})}
if($(this).is('.button_panel a')){$.each(['brand','study'],function(i,v){$('#detail_det_dialog [name='+v+']').val($('#prop_dialog [name='+v+']').val())})
project.changeGroup.apply($('#detail_det_dialog select[name=group]')[0]);project.changeModel.apply($('#detail_det_dialog select[name=brand]')[0]);frm.spec.value=$('#prop_dialog [name=id]').val();$('#detail_det_dialog [name*=model] option').attr('selected','');$('#detail_det_dialog [name*=model] option[value='+$('#prop_dialog [name=model]').val()+']').attr('selected','selected')}},diskHandler:function(){var frm=$('#disk_dialog form')[0],t=this;$('.loader').html('');$('#disk_dialog').dialog('open');$('.ui-dialog-title',$('#disk_dialog').parents('ui-dialog')[0]).html(this.href?this.innerHTML:$('a.right').html());$('#disk_dialog form').resetForm();if(this.href){frm.reset();frm.id.value="";frm.image.value="";project.changeModel.apply($('#disk_dialog select[name=brand]')[0]);project.changeStudy.apply($('#disk_dialog select[name=brand]')[0]);$.each(['brand','size','study'],function(i,v){$('[name='+v+']',frm).val($('[name='+v+'] option',frm)[0].value)})}else{project.changeModel.apply($('#disk_dialog select[name=brand]')[0]);project.changeStudy.apply($('#disk_dialog select[name=brand]')[0]);$.each(['id','name','article','size','brand','price','price2','price3','price4','study','article2','fld1','fld2','without_wheels2','without_wheels_one','without_wheels_one2','without_wheels','without_wheels1'],function(i,v){frm.elements[v].value=$('[name='+v+']',t).val()});$('.name-without_wheels',frm).attr('checked',$('[name=without_wheels]',t).val()=='1'?'checked':'');var models=eval('('+$('[name=model]',t).val()+')');$('select[name*=model] option').attr('selected','')
$.each(models,function(i,v){$('select[name*=model] [value='+v+']').attr('selected','selected')})}},paramsHandler:function(){var data='csrf_token='+csrf_token+'&',parent=$(this).parents('tr')[0],act={edit:'add_edit_param',close:'del_param',button:'add_edit_param'}[this.className],input=(this.className=='button'?$('#new_detail'):$('input[name=name]',parent)),inp2=(this.className=='button'?$('#new_ci'):$('input[name=ci]',parent)),t=this;data+='act='+act+'&name='+input.val()+'&ci='+inp2.val()+'&feature='+$('#det_list select').val();if(this.className!='button')
data+='&id='+$('input[name=id]',parent).val();$('.load').show();$.ajax({url:'admin/details',data:data,type:'POST',dataType:'json',success:function(json){$('.load').hide();if(t.className=='button'){input.val('');inp2.val('')}
if(json['status']=='OK')
project.loadDetails()}});return false},paramsKeyHandler:function(e){if(e.keyCode==10||e.keyCode==13)
project.paramsHandler.apply((this.id?$('#add_detail'):$('a.edit',$(this).parents('tr')[0]))[0]);else if(e.keyCode==46&&!(this.id))
project.paramsHandler.apply($('a.close',$(this).parents('tr')[0])[0])},detailsDeleteHandler:function(){var f=/last/.test(this.className),f1=$(this).is('#sub-category a.last'),act=f?(f1?'del_subcat':'del_feature'):'del_detail',id=f?/\d+/.exec(f1?$('#sub-category select').val():$('#det_list select').val()).toString():$('input',$(this).parents('tr')[0]).val();if(!(confirm(del_confirm)))return false;$('.load').show();$.ajax({url:'admin/details',data:'act='+act+'&csrf_token='+csrf_token+'&id='+id,type:'POST',dataType:'json',success:function(json){$('.load').hide();if(f){$((f1?'#sub-category':'#det_list')+' option:selected').remove();$('#detail_det_dialog [name=sub_group] option[value='+id+']').remove()}
project.loadDetails()}});return false},diskDeleteHandler:function(){if(!(confirm(del_confirm)))return false;$('.load').show();$.ajax({url:'admin/disks',data:'act=del_disk&csrf_token='+csrf_token+'&id='+$('[name=id]',$(this).parents('tr')[0]).val(),type:'POST',dataType:'json',success:function(json){$('.load').hide();project.loadDisks()}});return false},carDeleteHandler:function(){if(!(confirm(del_confirm)))return false;$('.load').show();$.ajax({url:'admin/cars',data:'act=del_car&csrf_token='+csrf_token+'&id='+$('[name=id]',$(this).parents('tr')[0]).val(),type:'POST',dataType:'json',success:function(json){$('.load').hide();project.loadCars()}});return false},propHandler:function(){var t=this;$('#prop_dialog').dialog('open');$('.ui-dialog-title').html(add_edit_prop);$('.list_values').hide();$('.multi_list_content').css('marginTop','0');$('.multi_list .sh_top').hide();$('.multi_list .sh_bot').show();$('#prop_dialog form')[0].reset();$.each(['id','study','model','offset_x','offset_y'],function(i,v){$('#prop_dialog [name='+v+']').val('')})
$('td.details option, td.details input').remove();if(/data/.test(this.className)){$.each(['name','uri','descr','price','setup_price','color_price','id','study','model','brand','article','index'],function(i,v){$('#prop_dialog [name='+v+']').val($('input[name='+v+']',t).val())});$('#prop_dialog [name=brand]').val($('#logos a.act').attr('rel'));project.changeModel.apply($('#prop_dialog [name=brand]')[0]);project.changeStudy.apply($('#prop_dialog [name=brand]')[0]);$('#prop_dialog [name=model]').val($('.models_list a.act').attr('rel'));var options=eval('('+$('input[name=options]',t).val()+')'),unique=eval('('+$('input[name=unique_options]',t).val()+')');$.each(options,function(i,v){project.addDetailToKit(v['id'],v['name'])});$.each(unique,function(i,v){$('td.details option[value='+v+']').attr('unique','1')});$('#prop_dialog .button_panel a').not('.first, .last').show();$('#prop_dialog [name=model]').val($('.models_list a.act').attr('rel'))}else{$('#prop_dialog [name=model]').val($('.models_list a.act').attr('rel'));$('#prop_dialog .button_panel a').not('.first, .last').hide();$('#prop_dialog [name=index]').val('9999');$('#prop_dialog [name=brand]').val($('#logos a.act').attr('rel'));project.changeModel.apply($('#prop_dialog [name=brand]')[0]);project.changeStudy.apply($('#prop_dialog [name=brand]')[0]);$('#prop_dialog [name=model]').val($('.models_list a.act').attr('rel'))}},carHandler:function(){var t=this;$('#car_dialog .file_input, #car_dialog .images .photo').not('.images+.file_input').remove();$('#car_dialog').dialog('open');$('.ui-dialog-title').html('&nbsp;');$('#car_dialog form')[0].reset();$.each(['id'],function(i,v){$('#car_dialog [name='+v+']').val('')})
if(/data/.test(this.className)){$.each(['id','name','price','year','mileage','engine','box','rudder','drive','color','body_type','modify','brand','class','model'],function(i,v){$('#car_dialog [name='+v+']').val($('input[name='+v+']',t).val())});var images=eval('('+$('input[name=images]',t).val()+')');$.each(images,function(i,v){$('<div class="photo"><label><img src="images/sale/mini_'+v['image']+'" alt="" style="left:-'+v['offset_x']+'px; top:-'+v['offset_y']+'px" /><span><input type="checkbox" name="del_images[]" value="'+i+'" /></span></label></div>').appendTo('#car_dialog .images')})}else{$('#car_dialog [name=model]').val($('.models_list a.act').attr('rel'));$('#car_dialog .button_panel a').not('.first, .last').hide()}
project.changeClass.apply($('#car_dialog [name=brand]')[0]);if(!(/data/.test(this.className)))
$.each(['brand','class'],function(i,v){$('#car_dialog [name='+v+']').val($('#car_dialog [name='+v+'] option')[0].value)})},showTab:function(id){var tr=$('#'+id).parents('tr').next('tr');while(tr.length&&!($('td.limiter',tr[0]).length)){tr[arguments[1]?'hide':'show']();tr=tr.next()}},loadProps:function(){$('.load').show();$.ajax({url:$('.models_list a.act').attr('href'),type:'GET',dataType:'json',success:function(j){var tpl='<tr class="data disabled"><td class="img"><div><img src="images/props/{image}" style="top:-{offset_y}px; left:-{offset_x}px" alt="" /></div></td><td><div class="prop_name">{name}</div>{descr}{hiddens}</td>{prices}<td style="padding:0 10px"><a class="close" href="#">'+del_label+'</a></td></tr>',input_tpl='<input type="hidden" name="{name}" value="{value}" />',price_tpl='<td><div class="price_value">{price}<br />{price_ru}</div></td>',table_html='';var count=0;$('.details tr.data').remove();$.each(j['data'],function(i,v){var html=tpl,hiddens='',prices='';$.each(['image','offset_x','offset_y','name','descr'],function(k,s){html=html.replace('{'+s+'}',v[s])});$.each(['name','uri','descr','setup_price_real','color_price_real','offset_x','offset_y','id','study','model','article','options','price_real','unique_options','index'],function(k,s){hiddens+=input_tpl.replace('{name}',s.replace('_real','')).replace('{value}',v[s])});html=html.replace('{hiddens}',hiddens);prices+=price_tpl.replace('{price}',v['price']).replace('{price_ru}',v['price_ru']);$.each(['setup','color'],function(k,s){prices+=price_tpl.replace('{price}',v[s+'_price']).replace('{price_ru}',v[s+'_price_ru'])});html=html.replace('{prices}',prices);table_html+=html;count++});$('.details table tbody').html($('.details table tbody').html()+table_html);$('.nodetail')[count?'hide':'show']();$('.load').hide();project.initDetails();$('.details table a.close').click(project.propDeleteHandler)}})},loadCars:function(){$('.load').show();$.ajax({url:$('.models_list a.act').attr('href'),type:'GET',dataType:'json',success:function(j){var tpl='<tr class="data disabled"><td class="img"><div><img src="images/sale/mini_{image}" style="top:-{offset_y}px; left:-{offset_x}px" alt="" /></div></td><td><div class="prop_name">{name}</div>{hiddens}</td>{prices}<td style="padding:0 10px"><a class="close" href="#">'+del_label+'</a></td></tr>',input_tpl='<input type="hidden" name="{name}" value="{value}" />',price_tpl='<td><div class="price_value">{price}<br />{price_ru}</div></td>',table_html='';var count=0;$('.details .title span').html($('.models_list a.act').attr('title'));$('.details tr.data').remove();$.each(j['cars'],function(i,v){var html=tpl,hiddens='',prices='';$.each(['image','offset_x','offset_y','name'],function(k,s){html=html.replace('{'+s+'}',v[s])});$.each(['id','name','price_real','year','mileage_real','engine','box','rudder','drive','color','body_type','modify','brand','class','model','images'],function(k,s){hiddens+=input_tpl.replace('{name}',s.replace('_real','')).replace('{value}',v[s])});html=html.replace('{hiddens}',hiddens);prices+=price_tpl.replace('{price}',v['price']).replace('{price_ru}',v['price_ru']);html=html.replace('{prices}',prices);table_html+=html;count++});$('.details table tbody').html($('.details table tbody').html()+table_html);$('.nodetail')[count?'hide':'show']();$('.load').hide();project.initDetails();$('.details table a.close').click(project.propDeleteHandler)}})},propDeleteHandler:function(){var t=this;if(!(confirm(del_confirm)))return;$('.load').show();$.ajax({url:'admin/proposals',data:'act=del&csrf_token='+csrf_token+'&id='+$('[name=id]',$(this).parents('tr')[0]).val(),type:'POST',dataType:'json',success:function(json){$('.load').hide();$(t).parents('tr').remove()}});return false},modelHandler:function(){$('#model_dialog').dialog('open');$('.ui-dialog-title',$('#model_dialog').parents('.ui-dialog')[0]).html(add_edit_model);if($(this).parents('.models_list').length){$.ajax({url:'admin/'+(/gallery|cars/.exec(location.href).toString())+'/model/'+$(this).parents('a').attr('rel'),type:'GET',dataType:'json',success:function(json){$.each(['name','price','year','brand','uri','id','offset_x','offset_y','basket','volume','year_direct'],function(i,v){$('#model_dialog [name='+v+']').val(json[v])});project.changeClass.apply($('#model_dialog select[name=brand]')[0]);$('#model_dialog [name=class]').val(json['class'])}})}else{$('#model_dialog form').resetForm();$('#model_dialog [name=id], #model_dialog [name=offset_x], #model_dialog [name=offset_y], #model_dialog [name=photo]').val('')}
return false},workHandler:function(){$('#work_dialog').dialog('open');$('.ui-dialog-title',$('#work_dialog').parents('.ui-dialog')[0]).html(add_edit_work);project.showTab('l1');project.showTab('l2',1);$('#work_dialog .images *, #work_dialog .file_input+.file_input').remove();$('#work_dialog form').resetForm();if($(this).parents('.photos').length){$.ajax({url:'admin/gallery/work/'+/\d+$/.exec($(this).parents('a')[0].href),type:'GET',dataType:'json',success:function(json){$.each(['brand','study','id','offset_x','offset_y'],function(i,v){$('#work_dialog [name='+v+']').val(json[v])});project.changeClass.apply($('#work_dialog select[name=brand]')[0]);project.changeStudy.apply($('#work_dialog select[name=brand]')[0]);$('#work_dialog [name=class]').val(json['class']);project.changeModel.apply($('#work_dialog select[name=class]')[0]);$('#work_dialog [name=model]').val(json['model']);$.each(json['images'],function(i,v){$('<div class="photo"><label><img src="/uploads/models/mini_'+v['image']+'" alt="" style="left:-'+v['offset_x']+'px; top:-'+v['offset_y']+'px" /><span><input type="checkbox" name="del_images[]" value="'+i+'" /></span></label></div>').appendTo('#work_dialog .images')});$('<div class="clear"></div>').appendTo('#work_dialog .images')}})}else{$('#work_dialog form').resetForm();$('#work_dialog [name=id], #work_dialog [name=offset_x], #work_dialog [name=offset_y], #work_dialog [type=file]').val('');$('#work_dialog select[name=brand]').val($('#logos a.act').attr('rel'));project.changeClass.apply($('#work_dialog select[name=brand]')[0]);project.changeStudy.apply($('#work_dialog select[name=brand]')[0]);$('#work_dialog select[name=class]').val($('#models a.act').attr('rel'));project.changeModel.apply($('#work_dialog select[name=class]')[0]);$('#work_dialog select[name=model]').val($('.models_list a.act').attr('rel'))}},studyHandler:function(){$('#study_dialog').dialog('open');$('.ui-dialog-title',$('#study_dialog').parents('.ui-dialog')[0]).html('&nbsp;');$('#study_dialog form').resetForm();if($(this).parents('.drop').length){$.ajax({url:'admin/gallery/study/'+$('[name=id]',$(this).parents('a')[0]).val(),type:'GET',dataType:'json',success:function(json){$.each(['brand','name','uri','id'],function(i,v){$('#study_dialog [name='+v+']').val(json[v])})}})}else{$('#study_dialog form').resetForm();$('#study_dialog [name=id]').val('')}
return false},deleteGalleryHandler:function(){var t=this;if(!(confirm(del_confirm)))return false;var cls=$(this).parents('.models_list, .photos, .image')[0].className,act={'models_list':'del_model','photos':'del_work','image':'del_photo',}[cls],id=cls!='image'?$(this).parents('a')[0].rel:$('#photo_pager a').index($('#photo_pager a.act')[0]);$.ajax({url:'admin/'+/gallery|cars/.exec(location.href).toString(),type:'POST',dataType:'json',data:'csrf_token='+csrf_token+'&act='+act+'&id='+id,success:function(json){if(cls!='image'){$(t).parents('a').remove();if(cls=='models_list'){project.resizeModels();project.reloadGallery()}else{project.galleryPageHandler.apply($('.models_list a.act')[0])}}}});return false},changeClass:function(){$('select[name=class] option',$(this).parents('table')[0]).hide();$('select[name=class] option[class='+this.value+']',$(this).parents('table')[0]).show();if($('select[name=class] option:visible',$(this).parents('table')[0]).length)
$('select[name=class]',$(this).parents('table')[0]).val($('select[name=class] option:visible',$(this).parents('table')[0])[0].value);if($('select[name=model]',$(this).parents('table')[0]).length)
project.changeModel.apply($('select[name=class]',$(this).parents('table')[0])[0])},changeModel:function(){$('select[name*=model] option',$(this).parents('table')[0]).hide();$('select[name*=model] option[class='+this.value+']',$(this).parents('table')[0]).show();if($('select[name*=model] option:visible',$(this).parents('table')[0]).length)
$('select[name*=model]',$(this).parents('table')[0]).val($('select[name*=model] option:visible',$(this).parents('table')[0])[0].value)},changeStudy:function(){$('select[name*=study] option',$(this).parents('table')[0]).hide();$('select[name*=study] option[class='+this.value+']',$(this).parents('table')[0]).show();if($('select[name*=study] option:visible',$(this).parents('table')[0]).length)
$('select[name*=study]',$(this).parents('table')[0]).val($('select[name*=study] option:visible',$(this).parents('table')[0])[0].value)},changeGroup:function(){$('select[name=sub_group] option',$(this).parents('table')[0]).hide();$('select[name=sub_group] option[class='+this.value+'], select[name=sub_group] option[class=0]',$(this).parents('table')[0]).show();if($('select[name=sub_group] option:visible',$(this).parents('table')[0]).length)
$('select[name=sub_group]',$(this).parents('table')[0]).val($('select[name=sub_group] option:visible',$(this).parents('table')[0])[0].value);else
$('select[name=sub_group]',$(this).parents('table')[0])[0].selectedIndex=-1},changeModelSub:function(){var t=this;$('select.linked[name!=model][id!=det_list] option',$(this).parents('table')[0]).hide();$('select.linked[name!=model][id!=det_list] option[class='+this.value+']',$(this).parents('table')[0]).show();$('select.linked[name!=model][id!=det_list]',$(this).parents('table')[0]).each(function(){try{$(this).val($('select.linked[name!=model][id!=det_list] option:visible',this)[0].value)}catch(e){}});$('select.linked[name!=model]',$(this).parents('table')[0]).val($('select.linked[name!=model] option:visible',$(this).parents('table')[0])[0].value)},reloadGallery:function(){if(!($('.models_in a').length))
$('.models_list, .gallery').hide();else if(!($('.models_in a.act').length)){$($('.models_in a')[0]).addClass('act');project.galleryPageHandler.apply($('.models_in a')[0])}},resizeModels:function(){$('.models_in > div').css({'width':$('.models_in a').length*165+'px'});var diff=($('.models_in').offset().left+$('.models_in').width())-($('.models_in > div').offset().left+$('.models_in > div').width());if(diff>0)
this.scrollContent($('.models_in > div'),diff,'right')},callbacks:{'car-order':function(){location.replace('/')},login:function(){location.reload()},news:function(json){if($('#news')[0].act.value=='preview'){$('#news_preview_dialog span.date').html(json['date']);$('#news_preview_dialog span.title').html($('#news')[0].title.value);$('#news_preview_dialog span.text:nth-child(3)').html(json['text']);$('#news_preview_dialog span.text:nth-child(4)').html(json['full_text']);$('#news_preview_dialog').dialog('open');$('.ui-dialog-buttonpane button:first-child').hide();return}
if($('#news')[0].id.value){var id=$('#news')[0].id.value;$('a[rel='+id+']  span.title').html(json['title']);$('a[rel='+id+']  span.text').html(json['text']);image=json['image']||'null.jpg';$('.news_img',$('a[rel='+id+'] ').parents('div')[0]).css({backgroundImage:'url(images/news/'+image+')',backgroundPosition:'-'+json['offset_x']+'px -'+json['offset_y']+'px'});var uri=json['trans_title']||id;$('a[rel='+id+']').attr('href',$('a[rel='+id+']').attr('href').replace(/\/[^\/]*$/g,'/'+uri));$('html,body').animate({scrollTop:$('a[rel='+id+'] ').offset().top},500)}else{location='admin/news/page/'+json['page']}},details_category:function(json){if(!($('#details_category')[0].id.value))
$('#det_list select').append('<option value="'+json['id']+'|'+$('#details_category')[0].none_text.value+'">'+$('#details_category')[0].name.value+'</option>');else{$('#det_list option[value^='+$('#details_category')[0].id.value+'|]').val(json['id']+'|'+$('#details_category')[0].none_text.value).text($('#details_category')[0].name.value)}},details_sub_category:function(json){if(!($('#details_sub_category')[0].id.value)){$('#sub-category select, #detail_det_dialog [name=sub_group]').append('<option class="'+$('#details_sub_category')[0].pid.value+'" value="'+json['id']
+'">'+$('#details_sub_category')[0].name.value+'</option>')}
else{$('#sub-category option[value='+$('#details_sub_category')[0].id.value+']').val(json['id']).text($('#details_sub_category')[0].name.value);$('#details_det_dialog [name=sub_group] option[value='+$('#details_sub_category')[0].id.value+']').text($('#details_sub_category')[0].name.value)}},disk_size:function(json){if(!($('#disk_size')[0].id.value))
$('#size_list select').append('<option value="'+json['id']+'">'+$('#disk_size')[0].name.value+'</option>');else{$('#size_list option[value='+$('#disk_size')[0].id.value+']').val(json['id']).text($('#disk_size')[0].name.value)}},details_detail:function(json){if($('#prop_dialog').length){project.addDetailToKit(json['id'],$('#detail_det_dialog [name=name]').val(),1);$('#prop_dialog [name=model]').val($('.models_list a.act').attr('rel'));return}
project.loadDetails()},proposal:function(json){project.loadProps()},add_edit_car:function(json){project.loadCars()},add_edit_model:function(json){var m=$('#model_dialog')[0],a=$('.models_list a[rel='+json['id']+']');if(!($('#models a[rel='+$('[name=class]',m).val()+']').length)){a.remove();project.reloadGallery();return}
if(!(a.length)){var code='event.stopPropagation?event.stopPropagation():event.cancelBubble = true; return false';a=$('<a href="" rel="'+json['id']+'"><span class="date">аДаО 0000 аГ.</span>$200<span class="img"><img src="" alt="" /><span class="adm_buttons pager p2"><span class="corner"></span><span class="edit" onclick="project.modelHandler.apply(this); '+code+'">Edit</span><span class="delete" onclick="project.deleteGalleryHandler.apply(this); '+code+'">Delete</span></span></span></a>').insertBefore('.models_list div.clear');project.resizeModels();if((a.offset().left+a.width())>($('.models_list').offset().left+$('.models_list').width()))
project.scrollContent($('.models_in > div'),(a.offset().left-($('.models_list').offset().left+$('.models_list').width()))+a.width(),'right',null);a.click(project.galleryPageHandler)}
a.attr('href',$('#models a[rel='+$('[name=class]',m).val()+']').attr('href')+'/'+$('[name=uri]',m).val()+'/'+$('[name=study_name]').val());$('span.date',a[0]).html($('span.date',a[0]).html().replace(/\d+/,$('[name=year]',m).val()));a.html(a.html().replace(/\$\d+/,'$'+$('[name=price]',m).val()));if(/str/.test(typeof json['image']))$('img',a[0]).attr('src','images/cars/'+json['image']);else if(!($('img',a[0]).attr('src')))
$('img',a[0]).attr('src','images/cars/model.jpg')},add_edit_work:function(json){project.galleryPageHandler.apply($('.models_list a.act')[0])},add_edit_class:function(){project.loadClasses.apply($('#logos a[rel='+$('#class_dialog [name=brand]').val()+']')[0])},add_edit_disk:function(){project.loadDisks()},add_edit_study:function(j){var l=$('.drop a').length-1;if($('#study_dialog [name=id]').val()){var a=$('.drop-in [value='+$('#study_dialog [name=id]').val()+']').parents('a');if($('#study_dialog [name=brand]').val()!=$('#logos a.act').attr('rel')){a.remove();$('.drop-in img+a+a').addClass('first');project.resizeDrop();return false}
$('b',a[0]).html($('#study_dialog [name=name]').val());$('input',a[0]).html(j['id']);a.attr('href',a.attr('href').replace(/\/[^\/]*$/,$('#study_dialog [name=uri]').val()))}else if($('#study_dialog [name=brand]').val()==$('#logos a.act').attr('rel')){var a=$('.drop a[href*=URI_EMPTY]').clone(true).show();if(!l)a.addClass('first');$('b',a[0]).html($('#study_dialog [name=name]').val());$('input',a[0]).val(j['id']);a.attr('href',a.attr('href').replace('URI_EMPTY',$('#study_dialog [name=uri]').val()));a.appendTo('.drop-in');project.resizeDrop()}}},addDetailToKit:function(id,name){var opt=$('<option value="'+id+'">'+name+'</option>');if(arguments[2])opt.attr('unique','1');opt.appendTo('td.details select');$('<input type="hidden" value="'+id+'" name="options[]" />').appendTo('td.details')},makeTrash:function(){var l=$('.trash .under').not('.slide .under').length-1;$('.trash, .slide')[(l?'remove':'add')+'Class']('empty');var sum=0,sum_ru=0;$('.name [type=checkbox]:checked').parents('.option').each(function(){var local_sum=0,local_sum_ru=0,id=$('.name [type=checkbox]',this).val();var t=this;sum+=(local_sum+=parseInt($('[name=price_real]',this).val()));sum_ru+=(local_sum_ru+=parseInt($('[name=price_real_ru]',this).val()));$.each(['setup','color'],function(i,v){if($('[id*='+v+']',t).attr('checked')!=''){sum+=parseInt($('[name='+v+'_price_real]',t).val());local_sum+=parseInt($('[name='+v+'_price_real]',t).val());sum_ru+=parseInt($('[name='+v+'_price_real_ru]',t).val());local_sum_ru+=parseInt($('[name='+v+'_price_real_ru]',t).val())}})});$('.trash .price b').html(project.numFormat(sum)+' &euro;');$('.trash .price+.price b').html(project.numFormat(sum_ru)+' p.')},changeOption:function(opt){var local_sum=parseInt($('[name=price_real]',opt[0]).val()),local_sum_ru=parseInt($('[name=price_real_ru]',opt[0]).val()),t=opt[0];$.each(['setup','color'],function(i,v){if($('[id*='+v+']',t).attr('checked')!=''||$(t).attr('checked')==''){local_sum+=parseInt($('[name='+v+'_price_real]',t).val());local_sum_ru+=parseInt($('[name='+v+'_price_real_ru]',t).val())}});$('.name  .price_value',t).html(project.numFormat(local_sum)+' &euro;');$('.name .price_value+.price_value',t).html(project.numFormat(local_sum_ru)+' p.')},resizeDrop:function(){var diff=$('.drop div').height()-18;if(diff<0)diff=0;$('.drop div img').css('height',diff+'px')},carDetailsHandler:function(){var p=$(this).parents('.car').click();$('.car-details .title span').html($('.ttl:first-child',p).html());$.each(['id','images'],function(i,v){$('.car-details [name='+v+']').val($('[name='+v+']',p).val())});$.each(['modify','year','mileage','box','engine','drive','rudder','body_type'],function(i,v){$('.car-details .'+v+'_title .price_value').html($('[name='+v+']',p).val())});$('.car-details .price').html($('[name=price]',p).val());$('.car-details .img img').attr('src',$('img',p).attr('src').replace('mini_',''));$('.car-details .price+.price').html($('[name=price_ru]',p).val());var images=eval('('+$('[name=images]',p).val()+')');$('.car-details .pager')[images['0']?'show':'hide']();$('.car-details .pager a').not('.car-details .pager a:first-child').remove();var j=0;$.each(images,function(i,v){j++;$('.car-details .pager a:first-child').clone(true).show()[i==0?'addClass':'removeClass']('act').attr('rel',i).insertBefore('.car-details .pager div')});$('.car-details .pager').css('width',j*14+'px');scrollTo(0,0);$('.all-cars').hide();$('.car-details').show();return false}};$(function(){$('.models_list .arrow_s a, .photos .arrow_s a, .proposals .arrow_s a').click(function(){var t=this;if($(this).is('.dis'))return false;var prnt=$(this).parents('.models_list, .photos, .proposals')[0];if($(prnt).is('.proposals, .cars')){var call=function(){var c_index=$('.prop-pager a').index($('.prop-pager a.act')[0]);$('.prop-pager a').removeClass('act');var margin=Math.abs(parseInt($('[class*=in] > div',prnt).css('marginLeft'))),width=$('[class*=in]',prnt).width(),index=parseInt(margin/width);if(prnt.className=='proposals'){index=c_index;$(t).parents('.asl').length?index--:index++}
$('.prop-pager a')[index].className='act'}}else{var call=function(){}}
project.scrollContent($('[class*=in] > div',prnt),prnt.className=='proposals'?780:$('[class*=in]',prnt).width(),$(this).parents('.asr').length?'right':'left',/ph/.test(prnt.className)?project.setScroll:call)});var first=1;project.galleryInit();$('.viewer a.arrow').click(function(){if(/dis/.test(this.className))return;project.galleryLoad($('#photo_pager a').index($('#photo_pager a.act')[0])+(/al/.test(this.className)?-1:1))});$('.scrollbar div').mousedown(function(e){project.scrollOffsetX=(e.clientX||e.pageX)-$(this).offset().left;project.scrolled=1});$(document).mouseup(function(){project.scrolled=0});$(document).mousemove(function(e){if(project.scrolled){var scrollX=(e.clientX||e.pageX)-project.scrollOffsetX-$('.scrollbar').offset().left;project.scrollTo(scrollX)}});if(/default/.test(module)){setInterval(function(){project.imageTrans({image:project.nextImage(),offset_x:-137,offset_y:-61},$('.imgcar:nth-child(2)'),$('.imgcar:first-child'),'images/')},5000);project.scroll()}
$(($('.gallery').length?'.photos, ':'')+'.models_list').bind('wheel',function(e,delta){if($('[class*=in] div a',this).length>={'big-out':3,'photos':5,'models_list':5,'proposals':4}[this.className.split(' ')[this.className.split(' ').length-1]])
project.scrollContent($('[class*=in]>div',this),$('[class*=in]',this).width(),delta>0?'left':'right',/ph/.test(this.className)?project.setScroll:null);return false});$('.gallery .image').bind('wheel',function(e,delta){var index=$('#photo_pager a').index($('#photo_pager a.act')[0])+(delta>0?-1:1);if(index>=0&&index<$('#photo_pager a').length)
project.galleryLoad(index);return false});if($('.gallery').length){$('.models_in a, .photos_in a, .drop a').click(project.galleryPageHandler)}
$('.buy_me input[type*=ch]').click(function(){$(this).parents('label')[(this.checked?'remove':'add')+'Class']('disabled');project.changePrice(/&nbsp;.*$/.exec($(this).parents('label').next().html()).toString(),this.checked?'+':'-')});if($('.buy_me form').length){$('.buy_me form')[0].reset();$('.details form').each(function(){this.reset()})}
if($('.order').length){$('.details .contain input, .details .contain tr td:not(first-child)').mousedown(function(e){var tr=$(this).parents('tr'),inp=$('input',tr)[0],ch=inp.checked,old;$('tr',$(this).parents('table')[0]).each(function(){if(!(/dis/.test(this.className)))
old=$(this)});if(inp.type=='radio'){inp.checked='checked';project.selectRow(tr,inp.type=='radio');if(!ch){if(inp.value=='0'){project.removeOrderEntry(tr,/&nbsp;.*$/.exec($('div.price_value',old[0]).html()))}else{if($('input',old[0])[0].value!='0'){project.changeOrderEntry(tr,/&nbsp;.*$/.exec($('div.price_value',old[0]).html()))}
else
project.addOrderEntry(tr)}}}
else{if($('input[value=0]',$(this).parents('.details')[0])[0].checked){inp.checked=false;return}
inp.checked=inp.checked?'':'checked';tr[(inp.checked?'remove':'add')+'Class']('disabled');project[(inp.checked?'add':'remove')+'SubEntry'](tr)}})}else{project.initDetails()}
if($('.details-out').length)
$(window).scroll(function(){var diff=$(document).scrollTop()-$('.details-out').offset().top,f=$('.trash').height()>$(window).clientHeight;if($('.trash').height()>$(window).height()){$('.trash').css({'position':'relative','top':'0','left':'auto','overflow':'visible','marginTop':'0'});return}
if(false){$('.trash').animate({'marginTop':(diff>10?diff+10:0)+'px'},10)}
else{$('.trash.slide')[diff>0?'show':'hide']();$('.trash').not('.slide')[diff>0?'hide':'show']()}});$(document).mousemove(function(){if($('.buy_me').offset().top<$('.order').offset().top)
$('.buy_me').css({'position':'relative','left':'auto','top':'auto'})});$('.buy_me a.button').click(function(){$('.buy_me form')[0].submit()});$('.order_form a.big_btn').click(function(){project.makeOrder()});$.each({'form.ajax a.button[rel=save], #login a.button':'click','form.ajax input':'keyup'},function(i,v){$(i)[v](project.formSender)});$('.news .news_btn a:first-child, #addnews').click(function(){var f=/add/.test(this.id);$('.file_input, .images .photo').not('.images+.file_input, [name=image]').remove();$('#news_form input[name=del_img]').parents('tr')[f?'hide':'show']();$('#news_form')[f?'toggle':'show']();$('#news_form [rel=attach]')[f?'hide':'show']();$('form')[0].reset();scrollBy(0,-1024);if(!f){$('#news .loader').html(ajax_load);$.ajax({url:this.href,type:'POST',dataType:'json',success:function(j){$.each(['id','title','trans_title','text','full_text','offset_x','offset_y','number','date','source'],function(i,v){$('form')[0].elements[v].value=j[v]});$('#attachments_dialog img').remove();$.each(j['images'],function(i,v){$('<div class="photo"><label><img src="images/news/mini_'+v['image']+'" alt="" style="left:-'+v['offset_x']+'px; top:-'+v['offset_y']+'px" /><span><input type="checkbox" name="del_images[]" value="'+i+'" /></span></label></div>').appendTo('.images');$('<img src="images/news/mini_'+v['image']+'" alt="" style="left:-'+v['offset_x']+'px; top:-'+v['offset_y']+'px" />').appendTo('#attachments_dialog')});$('#attachments_dialog img').click(function(){tag_add($('textarea')[parseInt($('#attachments_dialog').attr('index'))],'[attach='+$('#attachments_dialog img').index(this)+']','');$('#attachments_dialog').dialog('close');return false});$('#news .loader').html(j['message'])}})}else
$('form')[0].reset();return false});$('.bbcode a').click(function(){var code=/center|left|right/.test(this.rel)?'align='+this.rel.toLowerCase():this.rel.toLowerCase();tag_add($('textarea',$(this).parents('td')[0])[0],'['+code+']','[/'+/\w+/.exec(code)+']')});$('#news_form input[name=title]').change(function(){$('#news_form input[name=trans_title]').val(ru2en.translit(this.value).replace(/[^\w\d]+/gi,'-').toLowerCase())});$('#news_form a[rel=save]').click(function(){$('#news_form input[name=act]').val('news')})
$('#news_preview').click(function(e){$('#news_form input[name=act]').val('preview');project.formSender.apply(this,[e])});$('.news .news_btn a:last-child').click(function(){var t=this;if(confirm(del_confirm)){$('.loader',$(t).parents('div.news')[0]).html(ajax_load);$.ajax({url:this.href,type:'POST',dataType:'json',data:'act=del&id='+/\d+$/.exec(this.href)+'&csrf_token='+csrf_token,success:function(json){if(json['status']=='OK')
$(t).parents('div.news').remove()}})}
return false});$('form').each(function(){this.reset()});if($('.dialog').length){$('.dialog').dialog({autoOpen:false,position:'center',draggable:true,modal:true,width:500,buttons:{'OK':function(){},'Close':function(){$(this).dialog('close');$('#prop_dialog [name=model]').val($('.models_list a.act').attr('rel'))},}});$('#prop_dialog, #disk_dialog, #car_dialog').dialog('option','width',1000);$('#prop_dialog').dialog('option','closeOnEscape',false);$('<div class="loader"></div>').appendTo('.ui-dialog-buttonpane');$('.ui-dialog-buttonpane button:first-child').click(project.formSender)}
if($('#detail_cat_dialog').length){$('#details_main a:first-child, #det_list a.right').click(function(){$('#detail_cat_dialog').dialog('open');$('.ui-dialog-title',$('#detail_cat_dialog').parents('ui-dialog')[0]).html(this.innerHTML);$('.loader').html('');if(/right/.test(this.className)){var frm=$('#detail_cat_dialog form')[0],sel=$('#det_list select')[0];frm.name.value=sel.options[sel.selectedIndex].text;frm.none_text.value=sel.value.split('|')[1];frm.id.value=sel.value.split('|')[0]}else{$('#detail_cat_dialog form')[0].reset()}});$('#details_main a, #sub-category a.right').not('.first, .last').click(function(){$('#detail_subcat_dialog').dialog('open');$('.ui-dialog-title',$('#detail_subcat_dialog').parents('ui-dialog')[0]).html(this.innerHTML);$('.loader').html('');var frm=$('#detail_subcat_dialog form')[0];if(/right/.test(this.className)){var sel=$('#sub-category select')[0];frm.name.value=sel.options[sel.selectedIndex].text;frm.id.value=sel.value.split('|')[0]}else{$('#detail_subcat_dialog form')[0].reset()}
var sel2=$('#det_list select')[0];frm.pid.value=sel2.value.split('|')[0]});$('#details_main a:last-child, #det1 tr').click(project.detailHandler);$('.details+.details a').click(project.paramsHandler);$('#det_list select')[0].onchange=function(){project.loadDetails(this.value.split('|')[0],this.options[this.selectedIndex].text)};$('#det_list a.last, #sub-category a.last, #det1 table a').click(project.detailsDeleteHandler);$('#detail_det_dialog form').resetForm();$('.details input.textfield').keyup(project.paramsKeyHandler)}
if($('.multi_list').length){$('.multi_list input[type=radio], .multi_list input[type=checkbox]').change(function(){var sum=0;$('.multi_list input:checked').each(function(){sum+=parseInt(this.title||'0')});$('#prop_dialog input[name=details_price]').val(sum)});$('.multi_list .shadow_v div a').click(function(){project.scrollContentV($('.multi_list_content'),100,$(this).parents('.sh_top').length?'top':'bottom')});$('.multi_list').bind('wheel',function(e,delta){if(delta<0&&$('.multi_list').height()>$('.multi_list_content').height())return false;project.scrollContentV($('.multi_list_content'),100,delta>0?'top':'bottom');return false});$('.multi_list .list_item').click(function(){$('.multi_list .list_item').not(this).next().slideUp();$(this).next().slideToggle('fast',function(){if(($('.multi_list_content').offset().top+$('.multi_list_content').height())>($('.multi_list').offset().top+$('.multi_list').height()))
$('.multi_list .sh_bot').show();else
$('.multi_list .sh_bot').hide()})});$('.list_values input[type=radio]').click(function(){var chk=$('input[type*=ch]',$(this).parents('.list_values')[0]);if(this.value=='0')chk.attr('checked','');chk.attr('disabled',this.value=='0'?'disabled':'')});$('#prop_dialog input[name=name]').change(function(){$('#prop_dialog input[name=uri]').val(ru2en.translit(this.value).replace(/[^\w\d]+/gi,'-').toLowerCase())})}
$('#addprop').click(project.propHandler);$('#addcar').click(project.carHandler);$('td.limiter div').click(function(){var id=$(this).parents('td').attr('id');$('td.limiter').each(function(){project.showTab(this.id,this.id==id?0:1)})});if($('.adm_det').length){$('.details a.close').click(project.propDeleteHandler)
$('.models_in a').click(function(){$('.models_list a').removeClass('act');$(this).addClass('act');project[$('#car_dialog').length?'loadCars':'loadProps']();return false})}
$('.adm_buttons .edit, .adm_buttons .delete').click(function(){return false});$('#gallery_main a:first-child, .models_list span.edit').click(project.modelHandler);$('#gallery_main a:nth-child(2), .photos_in span.edit').click(project.workHandler);$('#gallery_main a:nth-child(3), .drop span.edit').click(project.studyHandler);$('select[name=brand]').not('#detail_det_dialog select').each(function(){this.onchange=project.changeClass});$('select[name=class]').each(function(){this.onchange=project.changeModel});$('.delete').click(project.deleteGalleryHandler);$('.photo_list a.button').click(function(){var div=$('div.images+div.file_input',$(this).parents('photo_list')[0]).clone(true).insertBefore(this);$('a.close',div[0]).show();$('input',div[0]).val('');return false});$('.photo_list a.close').click(function(){$(this).parents('.file_input').remove();return false});$('a.pass').click(function(){$('#pass_dialog').dialog('open');$('.ui-dialog-title',$('#pass_dialog').parents('ui-dialog')[0]).html(this.innerHTML);$('#pass_dialog form')[0].reset();$('#pass_dialog .loader').html('');return false});if($('.adm_class').length){$('a.button').click(project.classHandler);$('#logos a').click(project.loadClasses);$('.details a.close').click(project.classDeleteHandler)}
$('#detail_det_dialog [name=brand]').bind('change',project.changeModel);$('#detail_det_dialog [name=group]').bind('change',project.changeGroup);$('.dialog input[name=name]').change(function(){$('input[name=uri]',$(this).parents('.dialog')[0]).val(ru2en.translit(this.value).replace(/[^\w\d]+/gi,'-').toLowerCase())});$('#add_detail_dialog .button_panel').click(function(){$('#add_detail_dialog option').hide();var sel=$('#add_detail_dialog option.'+$('input',this).val());sel.show();if(sel.length)
$(sel[0]).attr('selected','selected')});$('#add_detail_dialog a.button').click(function(){var opt=$('#add_detail_dialog :selected');opt.each(function(){project.addDetailToKit($(this).val(),$(this).text())})});$('td.details a.last').click(function(){var opt=$('td.details :selected');if(opt.length){opt.each(function(){$('td.details input[value='+this.value+']').remove()});opt.remove()}});if(/(?:models|disks)\/(?:2|4|5)/.test(location.href)){$('.big a').not('.switch a').hover(function(){if($(this).is('.act'))return
var set=$('.big a').not('.first, .last'),i=set.index(this);if(i==0)
$('.first',$(this).parents('.big')[0]).addClass('hover');if(i==set.length-1)
$('.last',$(this).parents('.big')[0]).addClass('hover');if($(this).is('.first'))
$(this).next().addClass('hover');if($(this).is('.last'))
$(this).prev().addClass('hover')},function(){$('.big a').removeClass('hover')});$('.big a.act').not('.first, .last').each(function(){var set=$('a',$(this).parents('.big')[0]).not('.first, .last'),i=set.index(this);if(i==0)
$('.big .first').not('#prop-switch a').addClass('act');if(i==set.length-1)
$('.big .last').not('#prop-switch a').addClass('act')});if($('#bitch a').length==3)
$('#bitch .last').addClass('act');if(/\/2/.test(location.href)){var set=$('.big a').not('.first, .last'),sum=set.width()*set.length,width=/4/.test(location.href)?490:750;if(sum<width)
$(set[set.length-1]).css('width',set.width()+(width-sum)+'px')}}
$('.switch a').click(function(){if($(this).is('.dis'))return false;$('a',$(this).parents('.switch')[0]).removeClass('act');$(this).addClass('act')});$('#prop-switch a').click(function(){if($(this).is('.dis'))return false;$('.prop-out')[$(this).is('.first')?'show':'hide']();$('.details-out')[$(this).is('.first')?'hide':'show']()});$('.details-config [type=checkbox]').bind('click',function(){$(this).parents('.details-config div')[(this.checked?'remove':'add')+'Class']('uncheck');var sum=parseInt($('.details-config [name=price_real]').val()),sum_ru=parseInt($('.details-config [name=price_real_ru]').val());$.each(['setup','color'],function(i,v){if($('.details-config [id='+v+']').attr('checked')!=''){sum+=parseInt($('.details-config [name='+v+'_price_real]').val());sum_ru+=parseInt($('.details-config [name='+v+'_price_real_ru]').val())}});$('.details-config .pm').html(project.numFormat(sum)+' &euro;');$('.details-config .pm+.pm').html(project.numFormat(sum_ru)+' p.')});$('.proposal a.button').click(function(){$('.proposal').removeClass('act');$(this).parents('.proposal').addClass('act');$.ajax({url:'models/4/'+$('.proposals [name=study]').val()+'/'+this.rel,dataType:'json',success:function(json){var j=json['prop'];$('.prop-details div').remove();$.each(j['options'],function(i,v){$('<div class="option selected"><div class="edge"></div><div class="edge b"></div>'+(v['image']?'<img src="images/features/'+v['image']+'" alt="" />':'')+'<span></span><h1>'+v['name']+'</h1><h1 class="g">'+v['article']+'</h1></div>').appendTo('.prop-details')});$.each({'.conf_info .title span':project.slice(j['name']+'&nbsp;&nbsp;&nbsp;'+j['descr'],82),'.entry .price_value':j['price'],'.entry .price_value+.price_value':j['price_ru'],'.entry+.entry .price_value':j['setup_price'],'.entry+.entry .price_value+.price_value':j['setup_price_ru'],'.entry+.entry+.entry .price_value':j['color_price'],'.entry+.entry+.entry .price_value+.price_value':j['color_price_ru'],'.pm':j['sum'],'.pm+.pm':j['sum_ru'],'[name=prop]':j['id'],'[name=price_real]':j['price_real'],'[name=setup_price_real]':j['setup_price_real'],'[name=color_price_real]':j['color_price_real'],'[name=price_real_ru]':j['price_real_ru'],'[name=setup_price_real_ru]':j['setup_price_real_ru'],'[name=color_price_real_ru]':j['color_price_real_ru']},function(i,v){var f=$(i).is('input');$(i)[f?'val':'html'](v)});$('.conf_info .title span').attr('title',j['descr']);$.each({'.racourse img':'photo1','.racourse.r img':'photo2'},function(i,v){if(j[v]!='')
$(i).attr('src','images/props/'+j[v]).css('visibility','visible');else
$(i).css('visibility','hidden')});$('html,body').animate({scrollTop:$('.conf_info').offset().top},1000)}})});$('.switch-m a').click(function(){var e=$(this).is('.e');$('.switch-m a').removeClass('act');$(this).addClass('act');$('.switch-m')[(e?'remove':'add')+'Class']('switched');$('.price_value, .price').not('.price_value+.price_value, .price+.price, .empty *, .cars .ttl3 *, .car-details .ttl3 *')[e?'show':'hide']();$('.price_value+.price_value, .price+.price').not('.empty *, .cars .ttl3 *, .car-details .ttl3 *')[e?'hide':'show']();$.get('models/money/'+$('.switch-m a').index(this))});$('.switch-m a.act').trigger('click');$('.all-details .big a').click(function(){$('.all-details .big a').removeClass('act');$(this).addClass('act');$('.all-details .big a.first+a.act').prev().addClass('act').removeClass('hover');$('.all-details .big a.act+a.last').addClass('act').removeClass('hover');$('.category').hide();$('.category_'+this.rel).show()});$('.all-details .under [type=checkbox]').not('.selected [type=checkbox]').attr('checked','');$('#bitch a').not('.first, .last').each(function(){var cnt=$('.category_'+this.rel+' .selected').length;$('.cnt',this).html(cnt)[cnt>0?'show':'hide']()})
$('.all-details .button_panel a.first+a, .all-details .button_panel a.first').addClass('act');if(!$.browser.msie){$('.all-details .option').click(function(e){if(project.clicked){return}
var f=($('.name input',this).attr('checked'));$('.name input',this).attr('checked',f?'':'checked');$('.name input',this).trigger($.browser.msie?'click':'change')});$('.all-details .under [type=checkbox], .all-details .under label').hover(function(){project.clicked=true},function(){project.clicked=false})}
$('.all-details .name [type=checkbox]').bind($.browser.msie?'click':'change',function(e){$('.slide').removeClass('trash');var p=$(this).parents('.option')[0],childs=$('[type=checkbox]',$(this).parents('.option')[0]).not('.name [type=checkbox]'),flag=$(this).attr('checked');$(this).parents('.option')[(flag?'add':'remove')+'Class']('selected');var cnt=$('.name :checked',$(this).parents('.category')[0]).length,label=$('a[rel='+/\d+/.exec($(this).parents('.category').attr('class')).toString()+'] .cnt');label[cnt?'show':'hide']().html(cnt);if(!(flag)){childs.attr('checked','').trigger('change');$('#detail_'+$('[name=id]',p).val()).remove()}
else{$('#detail_'+$('[name=id]',p).val()).remove();var html='<div class="under" title="'+$('.name label',p).attr('title')+'" id="detail_'+$('[name=id]',p).val()+'"><div class="price_value">'+$('[name=price2]',p).val()+'</div><div class="price_value" style="display:none">'+$('[name=price_ru2]',p).val()+'</div><span>'+$('label',p).html()+'</span><input type="hidden" name="details[]" value="'+$('[name=id]',p).val()+'" /></div>';$(html).insertBefore('.trash .price.p1')
childs.attr('checked','checked');childs.trigger($.browser.msie?'click':'change');childs.attr('checked','checked')}
if(!childs.length)project.makeTrash();$('.switch-m a.act').trigger('click');var l=$('.trash .under').not('.slide .under').length;$('.trash')[(l?'remove':'add')+'Class']('empty');$('.empty-msg')[l?'hide':'show']();$('.trash .price, .slide .price')[l?'show':'hide']();$('.switch-m a.act').trigger('click');$('.slide')[$('.trash').is('.empty')?'addClass':'removeClass']('empty');$('.slide').html($('.trash').html()).addClass('trash');$('.trash a, .details-config a.big_btn').unbind('click').click(function(){if($(this).is('.empty a'))return false;$(this).parents('form')[0].submit();return false})});$('.all-details .under [type=checkbox]').not('.name [type=checkbox]').bind($.browser.msie?'click':'change',function(e){$('.slide').removeClass('trash');var type=/color|setup/.exec(this.id).toString(),cls='g '+type,p=$(this).parents('.under')[0],p2=$(this).parents('.option')[0],detail=$('#detail_'+$('[name=id]',p2).val()),html='<div class="'+cls+'"><div class="price_value">'+$('[name='+type+'_price2]',p2).val()+'</div><div class="price_value" style="display:none">'+$('[name='+type+'_price_ru2]',p2).val()+'</div><span>'+$('label',p).html()+'</span><input type="hidden" name="'+type+'[]" value="'+$('[name=id]',p2).val()+'" /></div>',flag=$(this).attr('checked');$('label',p)[(flag?'remove':'add')+'Class']('g');$('.price_value',p)[(flag?'remove':'add')+'Class']('un');if(flag){$('.'+type,detail[0]).remove();if(type=='color'||!($('.color',detail[0]).length))
$(html).appendTo($(detail[0]));else
$(html).insertBefore($('.color',detail[0]))}
else
$('.'+type,detail[0]).remove();$('.switch-m a.act').trigger('click');project.changeOption($(this).parents('.option'));project.makeTrash();var l=$('.trash .under').not('.slide .under').length;$('.trash')[(l?'remove':'add')+'Class']('empty');$('.empty-msg')[l?'hide':'show']();$('.trash .price, .slide .price')[l?'show':'hide']();$('.switch-m a.act').trigger('click');$('.slide')[$('.trash').is('.empty')?'addClass':'removeClass']('empty');$('.slide').html($('.trash').html()).addClass('trash');$('.trash a, .details-config a.big_btn').unbind('click').click(function(){if($(this).is('.empty a'))return false;$(this).parents('form')[0].submit();return false})});if(/\/4/.test(location.href)){$('.proposal').each(function(){$('.descr',this).html(project.slice($('.descr',this).html(),80))});$('.conf_info .title span').html(project.slice($('.conf_info .title span').html(),82))}
$('.prop-pager a').click(function(){if($(this).is('.act'))return
var index=$('.prop-pager a').index(this),act_index=$('.prop-pager a').index($('.prop-pager a.act')[0]),diff=index-act_index,prnt=$('.proposals')[0],width=index==0||index==$('.prop-pager a').length-1?800:780;$('.prop-pager a').removeClass('act');$(this).addClass('act');project.scrollContent($('[class*=in] > div',prnt),width*Math.abs(diff),diff>0?'right':'left',function(){})});if($('#detail_det_dialog').length){$('<option value="0" class="0"></option>').prependTo('#detail_det_dialog [name=sub_group]')}
$('#disks_main a:first-child, #size_list a.right').click(function(){$('#disk_size_dialog').dialog('open');$('.ui-dialog-title',$('#disk_size_dialog').parents('ui-dialog')[0]).html(this.innerHTML);$('.loader').html('');if(/right/.test(this.className)){var frm=$('#disk_size_dialog form')[0],sel=$('#size_list select')[0];frm.name.value=sel.options[sel.selectedIndex].text;frm.id.value=sel.value.split('|')[0]}else{$('#disk_size_dialog form')[0].reset()}});$('#size_list a.last').click(function(){if(!(confirm(del_confirm)))return false;$('.load').show();$.ajax({url:'admin/disks',data:'act=del_size&csrf_token='+csrf_token+'&id='+$('#size_list option:selected').val(),type:'POST',dataType:'json',success:function(json){$('.load').hide();$('#size_list option:selected').remove()}})});$('#disks_list .contain table a').click(project.diskDeleteHandler);$('#adm_cars .contain table a').unbind('click').click(project.carDeleteHandler);$('#disks_main a:last-child, #disks_list tr').click(project.diskHandler);$('#sizes_list').bind('change',project.loadDisks);$('#disk_dialog [name=brand]').bind('change',project.changeModel);$('form.ajax').bind('submit',project.formSender);$('.trash a, .details-config a.big_btn').click(function(){if($(this).is('.empty a'))return false;$(this).parents('form')[0].submit();return false});$('.all-disks .button_panel a').click(function(){$('.disk-size').hide();$('.d_'+this.rel).show()});$('.disk-size a').click(function(){var f=$(this).is('.no-disks'),t=this,name=$('[name=name]',this).val()||$(this).html().replace(/<br[^><]*>/,' '),f2=$('[name=without_wheels]',t).val()=='1';$('.disk-size a').removeClass('act');$(this).addClass('act');if(/disks/.test(location.href)){$('.trash')[(f?'add':'remove')+'Class']('empty')}
$('.disk-info .name b').html(name);$('.disk-info .name')[(f?'add':'remove')+'Class']('g');$('.disk-info .under, .disk-info .name span, .disks-summary .name+.usm').not('.name')[f?'hide':'show']();$('.disks-summary .usm+.usm').hide();$('[name=disks]').val(f?'':$('[name=id]',t).val());$('.disks-summary .name span')[(f?'add':'remove')+'Class']('g').html(name);if(!($(this).is('.no-disks'))){$('.disk-info .name+.under+.under, .one+.one').toggle(!f2)}
if(!f){$.each({'.name b':'name','.name+.under .price_value':'price','.name+.under .price_value+.price_value':'price_ru','.name+.under+.under .price_value':'price2','.name+.under+.under .price_value+.price_value':'price2_ru','.clear+.one .price_value':'price3','.clear+.one .price_value+.price_value':'price3_ru','.one+.one .price_value':'price4','.one+.one .price_value+.price_value':'price4_ru','.one input+span+span':'fld1','.one+.one input+span+span':'fld2','.clear+.one input+span+span+span':'article','.one+.one input+span+span+span':'article2','.name+.under label+label':'without_wheels2','.clear+.one input+span span':'without_wheels_one','.clear+.one+.one input+span':'without_wheels_one2'},function(i,v){$('.disk-info '+i).html($('[name='+v+']',t).val())});$('.disk-info .name+.under label').html($('[name=without_wheels2]',t).val())
$('.disk-info .name+.under+.under label').html($('[name=without_wheels1]',t).val())
$('.disk-info .name+.under [type=radio]').trigger('click')[0].click();$('disk-info input').val('1');$('disk-info .one').removeClass('g');$('.money a.act').trigger('click')}else{if(/disks/.test(location.href))
$('.trash .price').hide();$('.trash .price b').html('&nbsp;'+project.numFormat($('[name=prop_sum]').val())+' &euro;');$('.trash .price+.price b').html('&nbsp;'+project.numFormat($('[name=prop_sum_ru]').val())+' p.')}});$('.disk-info [type=radio]').click(function(){var f=$('.disk-size a.act [name=without_wheels]').val()=='1';$('[name=disks_type]').val(this.value);$('.disk-info .under').not('.name').addClass('g');$(this).parents('.under').removeClass('g');$('.disk-info .one input').attr('disabled',$(this).is('#one')?'':'disabled')
if($(this).is('#one')){$('.disk-info .one input').val('1');$('.disk-info .one input')[0].focus();$('.disks-summary .usm+.usm').show();$('.disks-summary .usm span').html($('.clear+.one input+span span:visible').html()+' X <b>1</b>');$('.disks-summary .usm+.usm span').html($('.one+.one input+span').html()+' X <b>1</b>');$('.disks-summary .name+.usm .price_value').removeClass('g').html($('.disk-size a.act [name=price3]').val());$('.disks-summary .usm+.usm .price_value').removeClass('g').html($('.disk-size a.act [name=price4]').val());$('.disks-summary .name+.usm .price_value+.price_value').removeClass('g').html($('.disk-size a.act [name=price3_ru]').val());$('.disks-summary .usm+.usm .price_value+.price_value').removeClass('g').html($('.disk-size a.act [name=price4_ru]').val());$('.trash .price b').html('&nbsp;'+project.numFormat(parseInt($('.disk-size a.act [name=price3_real]').val())+(f?0:parseInt($('.disk-size a.act [name=price4_real]').val()))+parseInt($('[name=prop_sum]').val()))+' &euro;');$('.trash .price+.price b').html('&nbsp;'+project.numFormat(parseInt($('.disk-size a.act [name=price3_real_ru]').val())+(f?0:parseInt($('.disk-size a.act [name=price4_real_ru]').val()))+parseInt($('[name=prop_sum]').val()))+' .p');$('.disks-summary .usm+.usm')[f?'hide':'show']()}
else{$('.disks-summary .name+.under span').html($('label:visible',$(this).parents('.under')[0]).html())
$('.disks-summary .name+.under .price_value').html($('.disk-size a.act [name='+($(this).is('#comp1')?'price':'price2')+']').val());$('.disks-summary .name+.under .price_value+.price_value').html($('.disk-size a.act [name='+($(this).is('#comp1')?'price':'price2')+'_ru]').val());$('.trash .price b').html('&nbsp;'+project.numFormat(parseInt($('.disk-size a.act [name='+($(this).is('#comp1')?'price':'price2')+'_real]').val())+parseInt($('[name=prop_sum]').val()))+' &euro;');$('.trash .price+.price b').html('&nbsp;'+project.numFormat(parseInt($('.disk-size a.act [name='+($(this).is('#comp1')?'price':'price2')+'_real_ru]').val())+parseInt($('[name=prop_sum_ru]').val()))+' p.');$('.disks-summary .usm+.usm').hide()}});$('.disk-info .one input').keyup(function(){var num=parseInt(this.value)||0,cnt,price,price_ru,f=$('.disk-size a.act [name=without_wheels]').val()=='1';;$(this).parents('.one')[(num?'remove':'add')+'Class']('g');if($(this).is('.clear+.one input')){cnt=$('.disks-summary .name+.usm')[0];price=$('.disk-size a.act [name=price3_real]').val();price_ru=$('.disk-size a.act [name=price3_real_ru]').val();$('[name=fwd_count]').val(num)}
else{cnt=$('.disks-summary .usm+.usm')[0];price=$('.disk-size a.act [name=price4_real]').val();price_ru=$('.disk-size a.act [name=price4_real_ru]').val();$('[name=bwd_count]').val(num)}
$('.price_value',cnt)[num?'removeClass':'addClass']('g');$('b',cnt).html(num);$('.price_value',cnt).html(project.numFormat(parseInt(price)*num)+' &euro;');$('.price_value+.price_value',cnt).html(project.numFormat(parseInt(price_ru)*num)+' б�.');$('.trash .price b').html('&nbsp;'+project.numFormat(parseInt($('.disk-size a.act [name=price3_real]').val())*parseInt($('.clear+.one input').val())+(f?0:parseInt($('.disk-size a.act [name=price4_real]').val())*parseInt($('.one+.one input').val()))+parseInt($('[name=prop_sum]').val()))+' &euro;');$('.trash .price+.price b').html('&nbsp;'+project.numFormat(parseInt($('.disk-size a.act [name=price3_real_ru]').val())*parseInt($('.clear+.one input').val())+(f?0:parseInt($('.disk-size a.act [name=price4_real_ru]').val())*parseInt($('.one+.one input').val()))+parseInt($('[name=prop_sum]').val()))+' &euro;')});if($('.disk-info [type=radio]').length){$('.disk-info [type=radio][value=1]').attr('checked','checked');$('.disk-info .one input').val('1')}
$('.trash-wrap .br').prev().css('borderBottom','none');$('.big-model img, .models_list img').each(function(){$(this).css('marginTop',($(this).parents('.img').height()-$(this).height())/2)
$(this).bind('load ready readystatechange',function(){$(this).css('marginTop',($(this).parents('.img').height()-$(this).height())/2)})});project.resizeDrop();$('.drop span.close').click(function(){var t=this;if(confirm(del_confirm))
$.ajax({url:'admin/gallery',type:'POST',dataType:'json',data:'act=del_study&csrf_token='+csrf_token+'&id='+$('input',$(this).parents('a')[0]).val(),success:function(){$(t).parents('a').remove();$('.drop-in img+a+a').addClass('first');project.resizeDrop()}});return false});$('.big a').not('#models a').click(function(){if($(this).is('.dis'))return false;var p=$(this).parents('.big')[0];$('a',p).removeClass('act');$(this).addClass('act');if($(this).is('#prop-switch a, .small a'))return;$('a.first+a.act',p).prev().addClass('act').removeClass('hover');$('a.act+a.last',p).addClass('act').removeClass('hover')});$('.sort1-control .small a').click(function(){var data=$('.car'),sort_type=['name','price_real','engine','year'][$('#sort-type a').index($('#sort-type a.act')[0])],order_type=$('.order a').index($('.order a.act')[0]);data.sort(function(a,b){var sel='[name='+sort_type+']',val1=$(sel,a).val(),val2=$(sel,b).val();if(sort_type=='engine'){val1=/\d+([\.,]\d+)*/.exec(val1).toString();val2=/\d+([\.,]\d+)*/.exec(val2).toString()}
if(sort_type=='name'){val1=val1.toLowerCase();val2=val2.toLowerCase();return order_type?(val2==val1?0:val2>val1?1:-1):(val2==val1?0:val1>val2?1:-1)}
val1=parseFloat(val1);val2=parseFloat(val2);return order_type?val2-val1:val1-val2});$.each(data,function(i,v){$($('.car')[i]).replaceWith($(v).clone(true));$($('.car a')[i]).replaceWith($('a',v).clone().click(project.carDetailsHandler))});var x=0;$('.car').removeClass('last').each(function(){if(++x==3){$(this).addClass('last');x=0}});return false});$('.car a').unbind('click').click(project.carDetailsHandler);$('.return').click(function(){$('.car-details').hide();$('.all-cars').show()});$('.car-details .pager a').unbind('click').click(function(){if($(this).is('act'))return false;$('.car-details .pager a').removeClass('act');$(this).addClass('act');var images=eval('('+$('.car-details [name=images]').val()+')');project.imageTrans({image:images[this.rel]['image'],offset_x:0,offset_y:0},$('.car-details img:first-child'),$('.car-details img:nth-child(2)'),'images/sale/')});$('.car-details .img').bind('wheel',function(e,delta){var index=$('.car-details .pager a:visible').index($('.car-details .pager a.act:visible')[0])+(delta>0?-1:1);if(index>=0&&index<$('.car-details .pager a:visible').length)
$($('.car-details .pager a:visible')[index]).trigger('click');return false});$('.car-details .params a').click(function(){location='sale-order/'+$('.car-details [name=id]').val()});$('.option').each(function(){if(!($('[id*=color], [id*=setup]',this).length))
$('.name',this).css('borderBottom','none')});$('#prop_dialog [name=brand], #detail_det_dialog [name=brand], #disk_dialog [name=brand]').unbind('change').bind('change',function(){project.changeModel.apply(this);project.changeStudy.apply(this)});$('#work_dialog [name=brand]').unbind('change').bind('change',function(){project.changeClass.apply(this);project.changeStudy.apply(this)});$('.named').bind('change',function(){$('[name='+this.className.split('-')[1]+']',$(this).parents('.dialog')[0]).val($(this).attr('checked')!=''?'1':'')});if(($('#details_list').length)||($('#sizes_list').length)){$('.models_list a').click(function(){$('.models_list a').removeClass('act');$(this).addClass('act')});$('.drop-in a, .models_list a').click(function(){var spl=this.href.split('/').reverse(),mdl=spl[1],std=spl[0],t=$(this).parents('.photos_in').length;if($(this).parents('.drop').length)$('.drop span').not('.edge, .edit, .close').html($('b',this).html());$('.models_in a, .drop a').each(function(){var parts=this.href.split('/').reverse(),l=$(this).parents('.drop').length;parts[l?1:0]=l?mdl:std;this.href=parts.reverse().join('/')})
project[$('#details_list').length?'loadDetails':'loadDisks']();return false})}
$('#bitch a').each(function(){if($(this).is('.last, .first'))return;if(!($('span',this).length))
$('<span />').appendTo(this)});$('#sort .last').unbind('click').click(function(){$('.load').show();$('#sort form').ajaxSubmit({dataType:'json',success:function(){$('.load').hide()}})});$('#news_form [rel=attach]').unbind('click').click(function(){$('#attachments_dialog').attr('index',$('textarea').index($('textarea',$(this).parents('td')[0])[0])).dialog('open');return false});$('#attachments_dialog').parents('.ui-dialog').find('.ui-dialog-buttonpane button:first-child').hide();$('.disk-size:first-child .no-disks').addClass('act');$('a[href$=#], a.dis').click(function(){return false});if($.fn.datepicker)$('input[name=date]').datepicker({maxDate:new Date(),dateFormat:'dd/mm/yy'});$('#ui-datepicker-div').hide()
if(!(location.href.match(/news/)))
$('#ui-datepicker-div').remove()})
