  
  
var techno = [];
var menus = [];
var mods = [];

var forms = false;
var comls = [];
var menu_array = [];
var melo;
var timeout; 
var pr_array = [];

var melo = $$('#mods');
function start(){
    menu_array = $$('.act');
    mo = $$('.mo');
   // post = $('post');
    moColor = $$('.mo3');
    moColTr = $$('.mo2');
    moColTeh = $$('.mol li').concat($$('.comls li'));
    slider = $$('h3.slide');  
    
    
    if($('gallery')) lightImg();
    modBik();
    if ($$('.act')) startMenu();
    if ($$('.cw') || $$('.bw')) startBike();
    if ($$('.mo')) startMods();
    if ($$('.act')) startColor();
//	    if ($$('.subdiv')) startColor2();
    if ($$('h3.slide')) actSlide();
    if ($$('.color_panel')) changeBg();
    if ($$('.acc_table')) chngBg();
    if ($$('.mo3')) newSlide();
    if ($$('.mo3')) chngColor();
    if ($$('.mol li') || $$('.comls li')) chngColTech();
    if ($$('.mo2')) moColT();
    if ($('post')) form();
    if ($$('.comNav')) coml();
    if ($('formaz')) actForm();
    if ($$('h3.slide2')) compa();

}  
function coml(){
    $each($$('.comNav'), function(element, i){
        if ($('comls'+i)) {
            comls[i] = new Fx.Slide($('comls'+i), {duration: 300, link: 'cancel'}).hide();
            element.addEvent('click', function(){
                comls[i].toggle();
				
            });
        }
        element.addEvent('mouseenter', function(){
            this.style.backgroundColor = '#ff0000';
			this.childNodes[0].setStyle('color', '#fff');
        });
        element.addEvent('mouseleave', function(){
            this.style.backgroundColor = '';
			this.childNodes[0].setStyle('color', '');
        });
		element.addEvent('click', function(){
				var link = this.childNodes[0].href;
	            document.location.href = link;								   
		});
    });
}
function form(){
    forms = new Fx.Slide($('in_form'), {duration: 300, link: 'cancel'}).hide();  
    if($('post0')) $('post0').addEvent('click', function(){
            var t = true;
            if($('tt').value == 2) t = false;
            $('tt').value = '1';
            $('fzag').innerHTML = 'Дополнительно';      
            if(t) forms.toggle();
        });
        
    if($('post1')) $('post1').addEvent('click', function(){
            var t = true;
            if($('tt').value == 1) t = false;
            
            $('tt').value = '2';
            $('fzag').innerHTML = 'Вопрос';             
            if(t) forms.toggle();
        });
        
    if($('post')) $('post').addEvent('click', function(){
            var t = true;
            if($('tt').value == 2) t = false;
            $('tt').value = '1';   
            if(t) forms.toggle();
        });
       
}
function moColT() {
    $each(moColTr, function(element, i){
        element.onmouseover = function(){
            this.style.background = '#818181';
        };
        element.onmouseout = function(){
            this.style.background = '';
        };
    })
}

function chngColTech(){
    $each(moColTeh, function(element, i){
        element.onmouseover = function(){
            if (!this.hasClass('hd')){
                this.style.background = '#ff0000';
                this.addClass('alk333');
            }
        };
        element.onmouseout = function(){
            this.style.background = '';
            this.removeClass('alk333');
        };
        element.onclick = function(){
            var link = this.childNodes[0].href;
            document.location.href = link;
        };
    });
}
  
function chngColor(){
    $each(moColor, function(element, i){
        element.onmouseover = function(){
            this.style.background = '#ff0000';
            this.addClass('alk333');
        };
        element.onmouseout = function(){
            this.style.background = '';
            this.removeClass('alk333');
        };
    });
}


function newSlide(){
    $each($$('.mo3'), function(element, i){
       if($('tech'+i)){
            techno[i] = new Fx.Slide($('tech'+i), {duration:300, link: 'cancel'});
            if (element.hasClass('on33')) {
                techno[i].show();
            } else {
                techno[i].hide();
            }
            element.onclick = function(){                
                techno[i].toggle();
            }
            
            
       }
    });
}

 
function actSlide(){
     var list = $$('h3.slide'); 
            list.each(function(element,i) {
                var id = element.id.substr(6,element.id.length);  
                var mySlide = new Fx.Slide('slider_'+id); 
                
               // alert('a');  
                var img = $('pic_'+id);
                
                if(i) {
                    mySlide.hide(); 
                    img.src = 'img/minus.gif';   
                }else{
                    img.src = 'img/plus.gif'; 
                }
                
               // alert('a');
      
                element.addEvents({
                    'click': function(){
                         mySlide.toggle();
                        var path = 'img/';
                        img.src = img.src.indexOf('plus', 0) < 0 ? path+'plus.gif' : path+'minus.gif';
                    },
                    'mouseover':function(){
                        this.style.backgroundColor = '#a3a3a3';
                    },
                    'mouseleave':function(){
                        this.style.backgroundColor = '#bebebe'; 
                    }
                });
           
            });
   
}

 
     
function startMenu(){
   $each(menu_array, function(element, i){
        if($('nn'+i)){
            menus[i] = new Fx.Slide($('nn'+i),{
                link: 'cancel',
                fps: 1000
            }).hide();
            element.addEvent('mouseenter', function(){
                 if(timeout) clearTimeout(timeout);
                 hideAllS(i);
            });
            element.addEvent('mouseleave', function(){
                 timeout = setTimeout('hideAllS();', 90);
                 
            });
        }
   });
   
   $each($$('.subdiv'), function(element, i){ 
         element.addEvent('mouseenter', function(){
             if(timeout) clearTimeout(timeout);
             hideAllS(i);
             
         });
         element.addEvent('mouseleave', function(){
             timeout = setTimeout('hideAllS();', 90);
             menus[i].slideOut();
         });
             
   });
   
}
function hideAllS(act){
    $each(menu_array, function(element, i){
         obbjj = document.getElementById('navig'+i);
         if($('nn'+i)){  
            if(act !== false && act==i) {
                obbjj.setStyle('background', '#ff0000');
                obbjj.childNodes[0].style.color = '#fff';
                obbjj.childNodes[0].style.textDecoration = 'underline';
                menus[i].slideIn();
            } else {
                obbjj.setStyle('background', '');
                obbjj.childNodes[0].style.color = '';
                obbjj.childNodes[0].style.textDecoration = '';
                menus[i].slideOut();
            } 
        }
    }) 
}
     
function startColor(){
    $each(menu_array, function(element, i){
        element.addEvent('mouseenter', function(){
            this.setStyle('background', '#ff0000');
            this.childNodes[0].style.color = '#fff';
            this.childNodes[0].style.textDecoration = 'underline';
        });
        element.addEvent('mouseleave', function(){
            if(this.id == 'navig0' || this.id == 'navig1' || this.id == 'navig2') {
                this.childNodes[0].style.textDecoration = 'none';
                this.setStyle('background', '#a8a8a8');
            } else {

                this.setStyle('background', '#fff');
                this.childNodes[0].style.color = '#7c7c7c';
                this.childNodes[0].style.textDecoration = 'none';
            }
        });
        element.addEvent('click', function(){   
            var link = this.childNodes[0].href;
            document.location.href = link;
        });
    });
}
    


function startBike() {
    
    $each($$('.cw, .bw'), function(element, i){
        element.addEvent('mouseenter', function(){
            this.style.backgroundColor = '#a4a4a4';
            this.style.color = '#fff';
            this.addClass('alk');
            
        });
        element.addEvent('mouseleave', function(){
        
            if (this.parentNode.className == 'car_w' || this.parentNode.className == 'bike_w') {
                this.style.backgroundColor = '#ffffff';
                this.style.color = '#6e6e6e';
                this.removeClass('alk');
            } else {
                this.style.backgroundColor = '#e7e7e7';
                this.style.color = '#6e6e6e';
                this.removeClass('alk');
            }
        });
        element.addEvent('click', function(){
            if (this.parentNode.className == 'car_w' || this.parentNode.className == 'car_g') {
                var link = this.childNodes[4].href;
                document.location.href = link;
            }
        });
    });
    
}

 
function startMods(){
   $each(mo, function(element, i){
        if($('mod'+i)) {
            mods[i] = new Fx.Slide($('mod'+i),{duration: 300, link: 'cancel'});
            if(!$('mod'+i).hasClass('oon')) mods[i].hide();   
            }
                element.addEvent('mouseenter', function(){
                    this.setStyle('background', '#ff0000');
                    this.childNodes[0].setStyle('color', '#ffffff');  
                });
                element.addEvent('mouseleave', function(){
                    if(this.hasClass('on')) {
            			this.setStyle('background', '#ff0000');
                    } else {
                        this.setStyle('background', '#4a4a4a');
                        this.childNodes[0].setStyle('color', '#cccccc');
                    }  
                });
                element.addEvent('click', function(){
                    var link = this.childNodes[0].href;
                    document.location.href = link;  
                });
         
   });
}

function modBik(){
$each($$('#mods li'), function(element, i){
       melo = new Fx.Slide($('mods'),{duration: 300, link: 'cancel'});
       element.addEvent('mouseenter', function(){
            this.addClass('modBg');
        });
        element.addEvent('mouseleave', function(){
            this.removeClass('modBg');
        });
        element.addEvent('click', function(){ 
             var link = this.childNodes[0].href;
             document.location.href = link;   
        });
	   $('tooglelink').addEvent('click', function(){
            melo.toggle();
       });
   });
}

function lightImg(){
    
    $each($$('#gallery img'), function(element, i){
            element.addEvent('mouseenter', function(){
                 this.setStyle('opacity', .7);
            });
            element.addEvent('mouseleave', function(){
                 this.setStyle('opacity', 1);  
            });
      
   });
}

/* 20.11.08 */
function changeBg(){
    $each($$('.color_panel div'), function(element, i){
        element.addEvents({
        'mouseenter': function(){
            this.style.backgroundImage = "url(img/col_over.gif)";
        },
        'mouseleave': function(){
            this.style.backgroundImage = "";
        }
        });
    });
}
function chngBg(){
    $each($$('.acc_table td'), function(element, i){
        element.addEvents({
        'mouseenter': function(){
            //alert('a')
            this.style.background = "#bebebe";
        },
        'mouseleave': function(){
            this.style.background = "#dfdfdf";
        },
        'click': function(){
            var link = this.childNodes[0]
            link.fireEvent('click', link, 0);
        }
        });
    })
}

function checkForm(cl){
   var clean = true;
   $each($$("."+cl), function(element, i){      
        element.setStyles({
            'border-left': '#808080 1px solid',
            'border-top': '#808080 1px solid',
            'border-right': '#fff 1px solid',
            'border-bottom': '#fff 1px solid'
        });
        
        if(element.nodeName == 'INPUT' || element.nodeName == 'input'){        
                if(!element.value){
                    element.setStyle('border', '#FF0000 1px solid');
                    clean = false;
                }
          }else if(element.nodeName == 'SELECT' || element.nodeName == 'select'){
                if(!element.selectedIndex){
                    element.setStyle('border', '#FF0000 1px solid');
                    clean = false;
                }
          }else if(element.nodeName == 'TEXTAREA' || element.nodeName == 'textarea'){
                if(!element.value){
                    element.setStyle('border', '#FF0000 1px solid');
                    clean = false;
                }
          }
   });
 
   if(!clean) alert('Заполните необходимые поля!');
   return clean;
}


function actForm(){
    $('formaz').addEvent('submit', function(e) {
        e.stop();
        if(checkForm('ch_f')){
            this.set('send', {
                onComplete: function(response) { 
                    alert('Ваше сообщение отправлено.');
            }});
            
            this.send();          
        }
    });
}


function compa(){
     var list = $$('td.slide2'); 
            list.each(function(element, i) {
                var id = element.id.substr(6,element.id.length);  
                var mySlide = new Fx.Slide('slider_'+id); 
                var img = $('pic_'+id);    
                
                if(i) {
                    mySlide.hide(); 
                    img.src = 'img/minus.gif';   
                }else{
                    img.src = 'img/plus.gif'; 
                }
                
                
                // if(i) mySlide.hide();
                
                
               element.onclick = function(e){
               
                    e = new Event(e);
                    mySlide.toggle();
                    var path = 'img/';
                    img.src = img.src.indexOf('plus', 0) < 0 ? path+'plus.gif' : path+'minus.gif';
                    e.stop();          
                    
                 }
            });
     
        $each($$('.sll'), function(element, i){
            element.addEvent('mouseenter', function(){
                this.addClass('slt');    
              //  this.setStyle('background', '#a3a3a3');
              //  this.addClass('slt');
                
            });
            element.addEvent('mouseleave', function(){
                //this.setStyle('background', '#bebebe');
                this.removeClass('slt');
                
            });        
        })

     
}

function compareO(){
    var url_str = 'compare/';
    for(i=0; i<3; i++){
        var o = $('csel_'+i);
        if(o.selectedIndex){
             url_str += o.options[o.selectedIndex].value+'/';
        }    
    } 
    
    document.location.href = url_str;
}

function compareM(){
    var url_str = 'compare_moto/';
    for(i=0; i<3; i++){
        var o = $('csel_'+i);
        if(o.selectedIndex){
             url_str += o.options[o.selectedIndex].value+'/';
        }    
    } 
    
    document.location.href = url_str;
}

function getCars(o){
    var ind = o.options[o.selectedIndex].value;
    
    var myRequest = new Request({method: 'post', url: 'mods/a.function.php', evalScripts: true, onSuccess: function (responseText, responseXML){
            $('get_cars').innerHTML = responseText;
            //alert(responseText);
    }});
    myRequest.send('ind='+ind+'&aj=13');
     
}

function getPrice(o){
   if(pr_array[o.selectedIndex]) $('prica').value = pr_array[o.selectedIndex]
}

function gocredit(){
     $('calc_form_h').submit();
}

function printdoc(){  
    var conthtml = '';
    
    
    
    $each($$('.print'), function(element, i){
           conthtml += element.innerHTML + '<br />';  
        });
        
    //alert(conthtml);    
        
    
     var html = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
                + '<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="ru-ru" xml:lang="ru-ru">'
                +'<head>'
                +'<meta http-equiv="content-type" content="text/html; charset=UTF-8" /> '
                + '<style type="text/css">'
                + ' body{ font-family: Times New Roman; font-size: 10pt; color: #000; background: #fff;} '
                + ' h1{ font-size: 18pt;} '
                +'</style>'
                + '<script language="Javascript">'
                + ' function printpage(){ window.focus(); window.print(); }'
                + ' </script> '
                + '</head><body onload="printpage()">'
                //+ head+'<br />'
                + conthtml
                + '</body></html>';
            
    var frame = new Element('iframe', {'id': 'iprint'}).injectInside($('frame'));
        var testFrame = frame;
        var doc = testFrame.contentDocument;
        if (doc == undefined || doc == null)
            doc = testFrame.contentWindow.document;
        doc.open();
        doc.write(html);
        doc.close(); 

}

function chekMinVal(m, ob){
    if(ob.value < m) ob.value = m;
}


