/*--- BEGIN: preload картинок ---*/
(function($) {
var cache = [];
$.preLoadImages = function() {
var args_len = arguments.length;
for (var i = args_len; i--;) {
var cacheImage = document.createElement('img');
cacheImage.src = arguments[i];
cache.push(cacheImage);
}
}
})(jQuery);
/*--- END:   preload картинок ---*/
/*--- BEGIN: проверка данных формы ---*/
function isEmpty(str) {
for (var j=0; j<str.length; j++) {
if (" " != str.charAt(j)) return false;
}
return true;
}
function checkSiteForm(f){
// проверка на обязательность заполнения
for (var i=0; i<f.elements.length; i++) {
if (null!=f.elements[i].getAttribute("obligatory") && isEmpty(f.elements[i].value)) {
alert('Поле "' + f.elements[i].getAttribute("forcheck") + '" обязательно для заполнения!');
f.elements[i].focus();
return false;
}
}
// проверка по регулярным выражениям
for (var i=0; i<f.elements.length; i++) {
rules = new RegExp(f.elements[i].getAttribute("regexp"));
if (null!=f.elements[i].getAttribute("regexp") && !rules.test(f.elements[i].value)) {
alert('Вы неверно заполнили поле "' + f.elements[i].getAttribute("forcheck") + '"!');
f.elements[i].focus();
return false;
}
}
return true;
}
/*--- END:   проверка данных формы ---*/








function tushimvse(flag) { 
$('#page_content2').css('background-color', '#FFF');
$('#page_content2').css('width', $('#bnew').width()-15);
$('#page_content2').css('height', $('#bnew').height()-75);
$('.p_content').css('border', 'none');
$('.p_content').css('background-color', '#FFF');
$("#page_content2").jScrollPane({showArrows:true, scrollbarWidth: 10,  arrowSize: 16});

if (flag==0)
{
$('#divbnew').css('display','none');
$('#mainnew').css('display','none');
$('.divsnew').css('display','none');
$('.snewtext').css('display','none');
$('.dati').css('display','none');
$('.news').css('display','none');
//$('#divezenews').css('display','none');
$('#ezenews').attr('src','img/source/news_posl_news_off.png');
$('#divezenews').click(function(){
window.location.href='/news'; 
});

$('#allnews').css('display','block');
$('#allnews').css('left', 60*$(window).width()/1440);
$('#allnews').css('top', 20*$(window).width()/1440);
news_main($('#myvibor').val(), $('#year').val(), $('#month').val(), 99);
}


if (flag==1)
{
$('#divbnew').css('display','block');
$('#mainnew').css('display','block');
$('.divsnew').css('display','block');
$('.snewtext').css('display','block');
$('.dati').css('display','block');
$('.news').css('display','block');
$('#divezenews').css('display','block');
$('#allnews').css('display','none');
}



}








function news_vse () {

$('#page_content2').css('background-color', '#FFF');
$('#page_content2').css('width', $('#bnew').width()-15);
$('#page_content2').css('height', $('#bnew').height()-75);
$('.p_content').css('border', 'none');	
$('.p_content').css('background-color', '#FFF');
//$("#page_content2").jScrollPane({showArrows:true, scrollbarWidth: 16, arrowSize: 16});	
	
var odin=0;	
if ($('#vsenews').attr('src')=="img/source/news_vse_news_off.png"&&odin==0) {$('#myvibor').val(3); $('#vsenews').attr('src','img/source/news_vse_news_on.png');$('#runews').attr('src','img/source/news_rutrack_news_off.png');$('#parnews').attr('src','img/source/news_partner_news_off.png');odin=1;news_main(3,$("#year").val(),$("#month").val());}
if ($('#vsenews').attr('src')=="img/source/news_vse_news_on.png"&&odin==0) {$('#vsenews').attr('src','img/source/news_vse_news_on.png');$('#runews').attr('src','img/source/news_rutrack_news_off.png');$('#parnews').attr('src','img/source/news_partner_news_off.png');odin=1;news_main(3,$("#year").val(),$("#month").val());}
}

function news_ru () {
$('#page_content2').css('background-color', '#FFF');
$('#page_content2').css('width', $('#bnew').width()-15);
$('#page_content2').css('height', $('#bnew').height()-75);
$('.p_content').css('border', 'none');	
$('.p_content').css('background-color', '#FFF');
//$("#page_content2").jScrollPane({showArrows:true, scrollbarWidth: 16, arrowSize: 16});
	
var odin=0;	
if ($('#runews').attr('src')=="img/source/news_rutrack_news_off.png"&&odin==0) {$('#myvibor').val(1); $('#runews').attr('src','img/source/news_rutrack_news_on.png');$('#vsenews').attr('src','img/source/news_vse_news_off.png');$('#parnews').attr('src','img/source/news_partner_news_off.png');odin=1;news_main(1,$("#year").val(),$("#month").val());}
if ($('#runews').attr('src')=="img/source/news_rutrack_news_on.png"&&odin==0) {$('#runews').attr('src','img/source/news_rutrack_news_off.png');$('#vsenews').attr('src','img/source/news_vse_news_on.png');$('#parnews').attr('src','img/source/news_partner_news_off.png');odin=1;news_main(3,$("#year").val(),$("#month").val());}
}



function news_par () {
$('#page_content2').css('background-color', '#FFF');
$('#page_content2').css('width', $('#bnew').width()-15);
$('#page_content2').css('height', $('#bnew').height()-75);
$('.p_content').css('border', 'none');	
$('.p_content').css('background-color', '#FFF');
//$("#page_content2").jScrollPane({showArrows:true, scrollbarWidth: 16, arrowSize: 16});
	
var odin=0;	
if ($('#parnews').attr('src')=="img/source/news_partner_news_off.png"&&odin==0) {$('#myvibor').val(2); $('#parnews').attr('src','img/source/news_partner_news_on.png');$('#vsenews').attr('src','img/source/news_vse_news_off.png');$('#runews').attr('src','img/source/news_rutrack_news_off.png');odin=1;news_main(2,$("#year").val(),$("#month").val());}
if ($('#parnews').attr('src')=="img/source/news_partner_news_on.png"&&odin==0) {$('#parnews').attr('src','img/source/news_partner_news_off.png');$('#vsenews').attr('src','img/source/news_vse_news_on.png');$('#runews').attr('src','img/source/news_rutrack_news_off.png');odin=1;news_main(3,$("#year").val(),$("#month").val());}
}


function news_year () {
 $('#page_content2').css('background-color', '#FFF');
$('#page_content2').css('width', $('#bnew').width()-15);
$('#page_content2').css('height', $('#bnew').height()-75);
$('.p_content').css('border', 'none');
$('.p_content').css('background-color', '#FFF');
//$("#page_content2").jScrollPane({showArrows:true, scrollbarWidth: 16, arrowSize: 16});

var odin=0;	
if ($('#yearnews').attr('src')=="img/source/year_plus.png"&&odin==0) {  $('#yearnews').attr('src','');  $('#yearnews').attr('src','img/source/year_minus.png');  $('#yearnews').css('height',310*$(window).height()/990); odin=1; $('#divallyearnews').css('display', 'block');   }
if ($('#yearnews').attr('src')=="img/source/year_minus.png"&&odin==0) {$('#divallyearnews').css('display', 'none');  $('#yearnews').attr('src','');  $('#yearnews').attr('src','img/source/year_plus.png');$('#yearnews').css('height', 30*$(window).height()/990); odin=1;}
}



function news_month () { 
//$("#page_content2").jScrollPane({showArrows:true, scrollbarWidth: 16, arrowSize: 16});
//alert($('#monthnews').attr('src'));


var odin=0;	
if ($('#monthnews').attr('src')=="img/source/month_plus.png"&&odin==0) {  $('#monthnews').attr('src','');   $('#monthnews').attr('src','img/source/month_minus.png'); $('#monthnews').css('height',310*$(window).height()/990);  odin=1; $('#divallmonthnews').css('display', 'block');    }
if ($('#monthnews').attr('src')=="img/source/month_minus.png"&&odin==0) {  $('#divallmonthnews').css('display', 'none');  $('#monthnews').attr('src','');   $('#monthnews').attr('src','img/source/month_plus.png'); $('#monthnews').css('height', 30*$(window).height()/990);  odin=1; }
}






$(window).load(function(){


if ($("#bnew"))
{

var bro_w = $(window).width();
var bro_h = $(window).height();
if (bro_w<=1050) {bro_w=1050;}
if (bro_h<=700) {bro_h=700;}

$('.dati').css('display','block');



$('#bnew').css('width', $('#li2').width()+$('#li7').width()+$('#li3').width());
$('#bnew').css('height', bro_h-$('#mainmenu').height()-60*bro_h/990-$('#podskaz').height());
$('#divbnew').css('left', 60*bro_w/1440);
$('#divbnew').css('top', 20*bro_h/990);
$('#divbnew').css('display', 'block');


$('.divsnew').css('left', $('#bnew').width()+55*bro_w/1440+15);
$('.snew').css('width', $('#li4').width()+$('#li5').width()+$('#li6').width()-20*bro_w/1440);
$('.divsnew').css('display', 'block');




$('#mainnew').css('left', 65*bro_w/1440);
$('#mainnew').css('top', 60);
$('#mainnew').css('width', $('#bnew').width()-20*bro_w/1440);
$('#mainnew').css('display', 'block');



$('#page_content2').css('background-color', '#FFF');
$('#page_content2').css('width', $('#bnew').width()-15);
$('#page_content2').css('height', $('#bnew').height()-65);
$('.p_content').css('border', 'none');
$('.p_content').css('background-color', '#FFF');


$('.snew').css('height', $('#bnew').height()/4-15*bro_h/990);



//$('#div0').css('top', 20*bro_h/990);
$('#div1').css('top', 20*bro_h/990+$('#div0').height()+19*bro_h/990);
$('#div2').css('top', 20*bro_h/990+$('#div0').height()+$('#div1').height()+19*2*bro_h/990);
$('#div3').css('top', 20*bro_h/990+$('#div0').height()+$('#div1').height()+$('#div2').height()+19*3*bro_h/990);



$('.snewtext').css('left', $('#bnew').width()+55*bro_w/1440+22);
$('.snewtext').css('width', $('#li4').width()+$('#li5').width()+$('#li6').width()-40);
$('.snewtext').css('display', 'block');


if($('#div0').css('display')=='block') {
var offset = $('#div0').offset(); 
//$('#divtext0').css('top', 50*bro_w/1440);
$('#divtext0').offset({ top: offset.top+30});
}


if($('#div1').css('display')=='block') {
//$('#divtext1').css('top', 50*bro_w/1440+$('#div0').height()+15);
offset = $('#div1').offset(); 
$('#divtext1').offset({ top: offset.top+30});
}


if($('#div2').css('display')=='block') {
offset = $('#div2').offset(); 
$('#divtext2').offset({ top: offset.top+30});
//$('#divtext2').css('top', 50*bro_w/1440+$('#div0').height()+$('#div1').height()+15*2);
}

if($('#div3').css('display')=='block') {
offset = $('#div3').offset(); 
$('#divtext3').offset({ top: offset.top+30});
//$('#divtext3').css('top', 50*bro_w/1440+$('#div0').height()+$('#div1').height()+$('#div2').height()+15*3);
}


$('#divvsenews').css('left', -140*bro_w/1440);
$('#divvsenews').css('display', 'block');



$('#vsenews').css('width', $('#li2').width());




$('#divrunews').css('left', -140*bro_w/1440);
$('#runews').css('width', $('#li2').width());
$('#divrunews').css('top', $('#divvsenews').height()+30*bro_h/990);
$('#divrunews').css('display', 'block');



$('#divparnews').css('left', -140*bro_w/1440);
$('#parnews').css('width', $('#li2').width());
$('#divparnews').css('top', $('#divvsenews').height()+$('#divrunews').height()+35*bro_h/990);
$('#divparnews').css('display', 'block');


$('#divezenews').css('left', -140*bro_w/1440);
$('#ezenews').css('width', $('#li2').width());
$('#divezenews').css('top', parseInt($('#divbnew').css('top'))+$('#divbnew').height()-$('#ezenews').height()-40);
$('#divezenews').css('display', 'block');



//if ($('#divvsenewslast')) {$('#divvsenewslast').css('top', parseInt($('#divonenew').css('top'))+$('#onenew').height()-$('#divvsenewslast').height());}



//alert (parseInt($('#divbnew').css('top'))+$('#divbnew').height());

//alert($('#vsenews').height());

$('#divyearnews').css('left', -140*bro_w/1440);
$('#yearnews').css('width', $('#li2').width()/2-25*bro_w/1440);
$('#yearnews').css('height', 30*bro_h/990);
$('#divyearnews').css('top', $('#divvsenews').height()+$('#divrunews').height()+$('#divparnews').height()+40*bro_h/990);


$('#divyearnews').css('display', 'block');

$('#divmonthnews').css('left', -55*bro_w/1440);
$('#monthnews').css('width', $('#li2').width()/2+10*bro_w/1440);
$('#monthnews').css('height', 30*bro_h/990);
$('#divmonthnews').css('top', $('#divvsenews').height()+$('#divrunews').height()+$('#divparnews').height()+40*bro_h/990);


$('#divmonthnews').css('display', 'block');


$('#divallmonthnews').css('left', -48*bro_w/1440);
$('#divallmonthnews').css('width', $('#li2').width()/2+8);
$('#divallmonthnews').css('top', $('#divvsenews').height()+$('#divrunews').height()+$('#divparnews').height()+70*bro_h/990);
$('#divallmonthnews').css('font-size', 1*bro_h/990+'em');
$('#divallmonthnews').css('line-height', 19*bro_h/990+'px');




$(".month").click(function () {
$(".month").css("background-color", "");
$(".month").css("border", "none");
$(this).css("background-color", "#eadfdf");
$(this).css("border", "dotted 1px");
//alert ($(this).attr('id'));
$("#month").val($(this).attr('id'));
news_main($('#myvibor').val(),$("#year").val(),$("#month").val());

});



$('#divallyearnews').css('left', -130*bro_w/1440);
$('#divallyearnews').css('width', $('#li2').width()/2-43);
$('#divallyearnews').css('top', $('#divvsenews').height()+$('#divrunews').height()+$('#divparnews').height()+70*bro_h/990);
$('#divallyearnews').css('font-size', 1*bro_h/990+'em');
$('#divallyearnews').css('line-height', 19*bro_h/990+'px');


$(".year").click(function () {
$(".year").css("background-color", "");
$(".year").css("border", "none");
$(this).css("background-color", "#eadfdf");
$(this).css("border", "dotted 1px");
$("#year").val($(this).text());
news_main($('#myvibor').val(),$("#year").val(),$("#month").val());
});









$('#divonenew').css('left', 60*bro_w/1440);



$('#onenew').css('width', $('#li2').width()+$('#li7').width()+$('#li3').width()+$('#li4').width()+$('#li5').width()+$('#li6').width()-40*bro_w/1440);
$('#onenew').css('height', bro_h-$('#mainmenu').height()-60-$('#podskaz').height());



if ($("#divonenewtext"))
{

$('#page_content2').css('background-color', '#FFF');
$('#page_content2').css('width', $('#onenew').width()-45);
$('#page_content2').css('height', $('#onenew').height()-65);
$('.p_content').css('border', 'none');
$('.p_content').css('background-color', '#FFF');
//$("#page_content2").jScrollPane({showArrows:true, scrollbarWidth: 16, arrowSize: 16});
}




$('#divonenewtext').css('top', 70*bro_h/990);
$('#divonenewtext').css('left', 80*bro_w/1440);
$('#divonenewtext').css('width', $('#onenew').width()-50*bro_w/1440);
$('#divonenewtext').css('height', $('#onenew').height()-70*bro_h/990);
$('#divonenewtext').css('display', 'block');
$('#divonenew').css('display', 'block');


$('#divonenewdate').css('top', 30*bro_h/990);
$('#divonenewdate').css('left', 85*bro_w/1440);
$('#divonenewdate').css('display', 'block');



$('#date1').css('left', 440*bro_w/1440);
$('#date1').css('top', $('#divbnew').css('top'));
//$('#date1').css('font-size', '1em');

if ($('#bnew').offset()) {$('#date1').offset({ left: $('#bnew').offset().left+$('#bnew').width()-274});}

//$('#page_content2').css('top', $('#bnew').css('top'));



$('#date2').css('left', 1020*bro_w/1440);
$('#date2').css('top', $('#div0').css('top'));

if ($('#div0').offset()) {$('#date2').offset({ left: $('#div0').offset().left+$('#simg0').width()-182});}
//$('#date2').css('font-size', 1.2*bro_h/990+'em');


$('#date3').css('left', 1020*bro_w/1440);
$('#date3').css('top', $('#div1').css('top'));
if ($('#div1').offset()) {$('#date3').offset({ left: $('#div1').offset().left+$('#simg1').width()-182});}
//$('#date3').css('font-size', 1.2*bro_h/990+'em');

$('#date4').css('left', 1020*bro_w/1440);
$('#date4').css('top', $('#div2').css('top'));
if ($('#div2').offset()) {$('#date4').offset({ left: $('#div2').offset().left+$('#simg2').width()-182});}
//$('#date4').css('font-size', 1.2*bro_h/990+'em');


$('#date5').css('left', 1020*bro_w/1440);
$('#date5').css('top', $('#div3').css('top'));
if ($('#div3').offset()) {$('#date5').offset({ left: $('#div3').offset().left+$('#simg3').width()-182});}
//$('#date5').css('font-size', 1.2*bro_h/990+'em');


$("#page_content2").jScrollPane({showArrows:true, scrollbarWidth: 10,  arrowSize: 16});

//$('.scroll-pane-arrows').jScrollPane(
//					{
//						showArrows: true,
//						horizontalGutter: 10
//					}
//				);
}


if ($("#picturebox1")) {$("#picturebox1").css ({'background-color':'#EEEEEE', 'border':'solid 1px #316ac5'}); }





$('#divvsenewslast').css('left', -140*bro_w/1440);
$('#divvsenewslast').css('top', parseInt($('#divonenew').css('top'))+$('#onenew').height()-$('#vsenews').height()-35);
$('#divvsenewslast').css('display', 'block');
$('#vsenews').css('display', 'block');


});





$(document).ready(function(){

if ($("#bnew"))
{

$('#page_content2').css('background-color', '#FFF');
$('#page_content2').css('width', $('#bnew').width()-15);
$('#page_content2').css('height', $('#bnew').height()-65);
$('.p_content').css('border', 'none');
$('.p_content').css('background-color', '#FFF');
//$("#page_content2").jScrollPane({showArrows:true, scrollbarWidth: 16, arrowSize: 16});
}


 //$('#imglogo').css('width',$('#li2').width()-33);


//Увеличение при наведении 
$("ul.thumb li").hover(function() {

    $(this).css({'z-index' : '15'});
    $(this).find('img').addClass("hover").stop()
    .animate({
    marginTop: '-110px', 
    marginLeft: '-110px', 
    top: '0%', 
    left: '50px', 
    width: '250px', 
    height: '426px',
    padding: '5px' 
    }, 600);
  
    } , function() {
    $(this).css({'z-index' : '10'});
    $(this).find('img').removeClass("hover").stop()
    .animate({
    marginTop: '0', 
    marginLeft: '0',
    top: '0', 
    left: '0', 
    width: '150px', 
    height: '246px', 
    padding: '5px'
    }, 800, "jswing");
    }); 




/* предзагрузка картинок */
/*$.preLoadImages("/site/common/i/object/intro_dealers_arrow.gif", "/site/common/i/object/intro_dealers_lt.gif", "/site/common/i/object/intro_dealers_rt.gif", "/site/common/i/object/intro_dealers_ld.gif", "/site/common/i/object/intro_dealers_rd.gif");
/* BEGIN: upmenu */
var timer_upMenu;
var templiId;
$(".li-pm").mouseover(function () {
var liId = $(this).attr("id");
if (templiId!=liId){$('#'+ templiId +' UL').slideUp(200);}
clearTimeout(timer_upMenu);
timer_upMenu = setTimeout("$('#"+ liId +" UL').slideDown(200)", 100);
});
$(".li-pm").mouseleave(function(){
var liId = $(this).attr("id");
clearTimeout(timer_upMenu);
timer_upMenu = setTimeout("$('#"+ liId +" UL').slideUp(200)", 100);
templiId=liId;
});
/* END: upmenu */
/* BEGIN: выпадающее меню "ДИЛЕРЫ" */
var timer_dealers;
var temp_dealersId;
$(".diler-center").mouseover(function () {
var liId = $(this).attr("id");
if (temp_dealersId!=liId){$('#'+ temp_dealersId +' .intro_dealers').slideUp(0);}
clearTimeout(timer_dealers);
timer_dealers = setTimeout("$('#"+ liId +" .intro_dealers').slideDown(0)", 100);
});
$(".diler-center").mouseleave(function(){
var liId = $(this).attr("id");
clearTimeout(timer_dealers);
timer_dealers = setTimeout("$('#"+ liId +" .intro_dealers').slideUp(0)", 100);
temp_dealersId=liId;
});
/* END:   выпадающее меню "ДИЛЕРЫ" */
/* BEGIN: Preview objects */
var timer_preview;
var flag="no";
var gId=0;
$('li#a1').css('border', '#E4DCBF 4px solid');
$('.cloud-zoom-gallery').click(function(){
var aId = $(this).attr("id");
if (gId!=aId && flag=="no"){
if (aId!='a1'){
$('li#a1').css('border', '#ECE6D1 4px solid');
}
$('li#'+ aId).css('border', '#E4DCBF 4px solid');
}
var name = $("#"+aId+" #goodDescr1").html();
replaceH1(name);
if (gId!=aId && flag=="yes"){
$('li#'+ gId).css('border', '#ECE6D1 4px solid');
$('li#'+ aId).css('border', '#E4DCBF 4px solid');
}
gId=aId;
flag="yes";
})
/* END: Preview objects */
});
/*--- BEGIN: замена H1 ---*/
function replaceH1(text){
text = text.replace(/(О|Г|О2|О3|Г2|Г3|о|г|о2|о3|г2|г3)<(br|BR) \/>/, " \(");
text = text.replace(/(О|Г|О2|О3|Г2|Г3|о|г|о2|о3|г2|г3)<(br|BR)\/>/, " \(");
text = text.replace(/(О|Г|О2|О3|Г2|Г3|о|г|о2|о3|г2|г3)<(br|BR)>/, " \(");
text = text.replace(/<(span|SPAN)>/, "");
text = text.replace(/<\/(span|SPAN)>/, "");
text = text.substr(0,1) + text.substr(1).toLowerCase() + ")";
$("body h1").text(text);
}
/*--- END:   замена H1 ---*/
