var timeout; 
var act_tog;
var onDisplay = 0;
function start(){
    if ($('thumbs')) startGal();
    if ($$('.thumbs')) startGal();
    if ($('mods')) startMods();    
    if ($$('.items')) startMorph();
    if ($$('.toggle')) startSlide();
    if ($$('.left_nav_i')) startOver();
    if ($$('.togover')) toggleOver();
    if ($$('.toggle')) slideOver();  
    if ($$('.to')) startTech();
    if ($$('.mod_togle')) modToggle();
    if ($$('.news_ul')) newsOver();
    if ($('scrollbar2')) makeScrollbar( $('content2'), $('scrollbar2'), $('handle2'), true );   
    if ($$('.comp_img')) showText();
    if ($$('.models_list')) startMods2();
    if ($$('.price_table')) price();
    if ($$('.trans_togle')) trToggle();
    if ($$('.gul')) guletOver();
    if ($$('.bazi_table')) startBa();

}

function startGal(){
   $each($$('#thumbs img'), function(element, i){
            element.setStyle('opacity', .5);
            element.addEvent('mouseenter', function(){
                 this.setStyle('opacity', 1);
            });
            element.addEvent('mouseleave', function(){
                 this.setStyle('opacity', .5);  
            });      
   });
   $each($$('.thumbs img'), function(element, i){
            element.setStyle('opacity', .5);
            element.addEvent('mouseenter', function(){
                 this.setStyle('opacity', 1);
            });
            element.addEvent('mouseleave', function(){
                 this.setStyle('opacity', .5);  
            });      
   });
}
function startMods(){
    var list = $$('#mods img');
    var listA = $$('#mods dt a');
    $each(list, function(element, i){
        if (element.parentNode.parentNode.className != 'cur') element.setStyle('opacity', .5);
        element.addEvent('mouseenter', function(){
            $('dt'+i).setStyle('background', 'url(img/arr_cur.gif) left 8px no-repeat'); 
            if ($('dt'+i).className != 'on_list') 
            $('dt'+i).childNodes[0].setStyle('color', '#f7941e');
            this.setStyle('opacity', 1);
        });
            
        element.addEvent('mouseleave', function(){
            if (this.parentNode.parentNode.className != 'cur')
                this.setStyle('opacity', .5);  
            if ($('dt'+i).className != 'on_list') {
                $('dt'+i).setStyle('background', ''); 
                $('dt'+i).childNodes[0].setStyle('color', '');
            }
        });      
    });
   
    $each(listA, function(element, i){
        if ($('img'+i).parentNode.parentNode.className != 'cur')
            $('img'+i).setStyle('opacity', .5);
        element.addEvent('mouseenter', function(){
            this.parentNode.setStyle('background', 'url(img/arr_cur.gif) left 8px no-repeat');
            $('img'+i).setStyle('opacity', 1);
        });
            
        element.addEvent('mouseleave', function(){
        if ($('img'+i).parentNode.parentNode.className != 'cur') $('img'+i).setStyle('opacity', .5);  
            this.parentNode.setStyle('background', '');
        });      
    });
}

function startMorph(){
    var it = $$('.cat th');
    $each(it, function(element, i){
        element.addEvent('mouseenter', function(){
            if (this.className != 'no_th'){
                this.setStyle('background-color', '#e0e0e0');
                this.childNodes[0].setStyle('color', '#436994');
            }
            
        });
        element.addEvent('mouseleave', function(){
            if (this.className != 'no_th'){
                this.setStyle('background-color', '');
                this.childNodes[0].setStyle('color', '');
            }
            
        });
        
    });
    
}

function startSlide(){
    var img_bg0 = new Image;
    var img_bg1 = new Image;
    var img_bg2 = new Image;
    var img_bg3 = new Image;
    var img_bg4 = new Image;
    var img_bg5 = new Image;
    var img_bg6 = new Image;
    img_bg0.src = 'img/t_bgbg0.jpg';
    img_bg1.src = 'img/t_bgbg3.jpg';
    img_bg2.src = 'img/t_bgbg1.jpg';
    img_bg3.src = 'img/t_bgbg2.jpg';
    img_bg4.src = 'img/t_bgbg4.jpg';
    img_bg5.src = 'img/t_bgbg5.jpg';
    img_bg6.src = 'img/t_bgbg6.jpg';
    
    var img_bgg0 = new Image;
    var img_bgg1 = new Image;
    var img_bgg2 = new Image;
    var img_bgg3 = new Image;
    var img_bgg4 = new Image;
    var img_bgg5 = new Image;
    var img_bgg6 = new Image;
    img_bgg0.src = 'img/t_bgbgg0.jpg';
    img_bgg1.src = 'img/t_bgbgg3.jpg';
    img_bgg2.src = 'img/t_bgbgg1.jpg';
    img_bgg3.src = 'img/t_bgbgg2.jpg';
    img_bgg4.src = 'img/t_bgbgg4.jpg';
    img_bgg5.src = 'img/t_bgbgg5.jpg';
    img_bgg6.src = 'img/t_bgbgg6.jpg';
    
    $$('.show').setStyle('opacity', 0);
    $$('.show_in').setStyle('opacity', 0);
   // $$('.main_pic').setStyle('opacity', 0);
    
    
    myAccordion = new Accordion($$('.toggle'), $$('.slide'), {
            onActive: function(toggler, slider){
                var src = eval('img_'+toggler.id);
                act_tog = toggler.id;
                toggler.setStyles({
                    'background': 'url('+src.src+')',
                    'cursor': 'default'
                });
                
                $each($$('.slide'), function(el, z){
                   $('tog'+z).setStyle('opacity', 0);
                    if(el.id == slider.id){
                         (function(){ $('sho'+z).morph({opacity: .85})}).delay(410);
                         (function(){ $('sho_in'+z).morph({opacity: 1})}).delay(410);
                         (function(){ $('mpic'+z).morph({opacity: 1})}).delay(410);
                         
                    } else { 
                        $('sho'+z).morph({opacity: 0});
                        $('tog'+z).setStyle('opacity', 1);
                        $('sho_in'+z).morph({opacity: 0});
                      //  $('mpic'+z).morph({opacity: 0});
                    }
                });
                
            },
            onBackground: function(toggler, slider){
                var src = eval('img_'+slider.id);
                toggler.setStyles({
                    'background': 'url('+src.src+')',
                    'cursor': ''
                });
                //toggler.childNodes[0].setStyle('opacity', 1);
                //toggler.childNodes[0].style.opacity = 1;
                toggler.childNodes[0].style.display = 'block';
                
                
            },
            onComplete: function(){
                
            },

            opacity: 0,
            display: 0,
            alwaysHide: false
    });
}

function startOver(){
    $each($$('.left_nav_i a'), function(element, i){
        $('mpic'+i).setStyle('display', 'none');
        element.addEvent('mouseenter', function(){
            $('mpic'+i).setStyles({
                'display': 'block',
                'top': '20px'
                });
        });
        element.addEvent('mouseleave', function(){
            $('mpic'+i).setStyle('display', 'none');
        });
    });
}

function toggleOver(){
    $each($$('.togover'), function(element, i){
        i=1;
        element.addEvent('mouseover', function(){
            this.setStyle('background', 'url(img/t_bgbgg'+i+'_.gif) left top no-repeat');
        });
        element.addEvent('mouseout', function(){
            this.setStyle('background', '');
        });
        element.addEvent('click', function(){
            var link = this.childNodes[0].href;
            document.location.href = link;
        });
    });
}
function slideOver(){
    $each($$('.toggle'), function(element, i){
        element.addEvent('mouseover', function(){
            if (act_tog != this.id)
            this.setStyle('background', 'url(img/t_bgbgg'+i+'_.gif) left top no-repeat');
        });
        element.addEvent('mouseout', function(){
            if (act_tog != this.id)
            this.setStyle('background', 'url(img/t_bgbgg'+i+'.jpg) left top no-repeat');
        });
    });
}
function startTech(){
    myAccordion = new Accordion($$('.to'), $$('.sl'), {
            onActive: function(toggler, slider){
                
                toggler.setStyles({
                    'background': 'url(img/minus.gif) left 1px no-repeat',
                    'cursor': 'default'
                });
            },
            onBackground: function(toggler, slider){
                
                toggler.setStyles({
                    'background': 'url(img/plus.gif) left 1px no-repeat',
                    'cursor': 'pointer'
                });
            },

            opacity: 0,
            display: 0,
            alwaysHide: false
    });
}

/*  */
function modToggle(){
    myAccordion = new Accordion($$('.mod_togle'), $$('.mod_slide'), {
            onActive: function(toggler, slider){
                // toggler.setStyle('cursor', 'default');
                // f7941e
                if(toggler) toggler.setStyles({'cursor': 'default', 'background': '#f7941e url(img/cur_arr.gif) left 8px no-repeat'});
            },
            onBackground: function(toggler, slider){
              //  toggler.setStyle('cursor', 'pointer');
                if(toggler) toggler.setStyles({'cursor': 'pointer', 'background': '#436994'});
            },

            opacity: 0,
            display: onDisplay,
            alwaysHide: false
    });
    $each($$('.mod_togle'), function(element, i){
        element.addEvent('mouseenter', function(){
            this.setStyle('background-color', '#f7941e');
        });
        element.addEvent('mouseleave', function(){
            this.setStyle('background-color', '#436994');
        });
        element.addEvent('click', function(){
            var link = this.childNodes[0].href;
            document.location.href = link;
        });
    });
}
function newsOver(){
    $each($$('.news_ul li'), function(element, i){
        element.addEvent('mouseenter', function(){
            if (this.className != 'news_on')
                this.setStyle('background-color', '#f7941e');
        });
        element.addEvent('mouseleave', function(){
            if (this.className != 'news_on')
                this.setStyle('background-color', '#436994');
        });
        element.addEvent('click', function(){
            var link = this.childNodes[0].href;
            document.location.href = link;
        });
    });
}
/*  */

function showText(){
    $each($$('.comp_fun'), function(element, i){
        element.addEvent('mouseenter', function(){
            $('clo'+i).setStyle('display', 'block');
            
            var reg = /(.*?)\.gif/;
            $('clos'+i).src = $('clos'+i).src.replace(reg, "$1_.gif");
        });
        element.addEvent('mouseleave', function(){
            $('clo'+i).setStyle('display', 'none');
            
            var reg = /(.*?)\_.gif/;
            $('clos'+i).src = $('clos'+i).src.replace(reg, "$1.gif");
        });
    });
    $each($$('.comp_fun2'), function(element, i){
        element.addEvent('mouseenter', function(){
            $('bron'+i).setStyle('display', 'block');
            
            var reg = /(.*?)\.gif/;
            $('bro'+i).src = $('bro'+i).src.replace(reg, "$1_.gif");
        });
        element.addEvent('mouseleave', function(){
            $('bron'+i).setStyle('display', 'none');
            
            var reg = /(.*?)\_.gif/;
            $('bro'+i).src = $('bro'+i).src.replace(reg, "$1.gif");
        });
    });
}


function makeScrollbar(content,scrollbar,handle,horizontal,ignoreMouse){
    var steps = (horizontal?(content.getScrollSize().x - content.getSize().x):(content.getScrollSize().y - content.getSize().y))
    var slider = new Slider(scrollbar, handle, {    
        steps: steps,
        mode: (horizontal?'horizontal':'vertical'),
        onChange: function(step){
            // Scrolls the content element in x or y direction.
            var x = (horizontal?step:0);
            var y = (horizontal?0:step);
            content.scrollTo(x,y);
        }
    }).set(0);
    if( !(ignoreMouse) ){
        // Scroll the content element when the mousewheel is used within the 
        // content or the scrollbar element.
        $$(content, scrollbar).addEvent('mousewheel', function(e){    
            e = new Event(e).stop();
            var step = slider.step - e.wheel * 30;    
            slider.set(step);                    
        });
    }
    // Stops the handle dragging process when the mouse leaves the document body.
    $(document.body).addEvent('mouseleave',function(){slider.drag.stop()});
}

function startMods2(){
    var list = $$('.models_list img');
    var listA = $$('.models_list dt a');
    $each(list, function(element, i){
        if (element.parentNode.parentNode.className != 'cur') element.setStyle('opacity', .5);
        element.addEvent('mouseenter', function(){
            $('dt'+i).setStyle('background', 'url(img/arr_cur.gif) -2px -1px no-repeat'); 
            if ($('dt'+i).className != 'on_list') 
            $('dt'+i).childNodes[0].setStyle('color', '#f7941e');
            this.setStyle('opacity', 1);
        });
            
        element.addEvent('mouseleave', function(){
            if (this.parentNode.parentNode.className != 'cur')
                this.setStyle('opacity', .5);  
            if ($('dt'+i).className != 'on_list') {
                $('dt'+i).setStyle('background', ''); 
                $('dt'+i).childNodes[0].setStyle('color', '');
            }
        });      
    });
   
    $each(listA, function(element, i){
        if ($('img'+i).parentNode.parentNode.className != 'cur')
            $('img'+i).setStyle('opacity', .5);
        element.addEvent('mouseenter', function(){
            this.parentNode.setStyle('background', 'url(img/arr_cur.gif) -2px -1px no-repeat');
            $('img'+i).setStyle('opacity', 1);
        });
            
        element.addEvent('mouseleave', function(){
        if ($('img'+i).parentNode.parentNode.className != 'cur') $('img'+i).setStyle('opacity', .5);  
            this.parentNode.setStyle('background', '');
        });      
    });
}
/*  */
function price(){
    $each($$('.price_table tr td a'), function(element, i){
        element.addEvent('mouseenter', function(){
            var size = this.getSize();
            var le = size.x;
            //alert(le);
            $('pr_pic'+i).setStyles({'display': 'block', 'left': le+'px', 'margin-left': '5px'});
        });
        element.addEvent('mouseleave', function(){
            $('pr_pic'+i).setStyle('display', 'none');
        });
    });
}
/* classes */
var ZebraTables = new Class({
    //initialization
    initialize: function(table_class) {

        //add table shading
        $$('table.' + table_class + ' tr').each(function(el,i) {

            //do regular shading
            var _class = i % 2 ? 'even' : 'odd'; el.addClass(_class);

            //do mouseover
            el.addEvent('mouseenter',function() { 
                if(!el.hasClass('highlight')) {
                    el.addClass('mo').removeClass(_class);
                } 
            });

            //do mouseout
            el.addEvent('mouseleave',function() { 
                if(!el.hasClass('highlight')) { 
                    el.removeClass('mo').addClass(_class); 
                } 
            });
        });
    }
});

/*  */
function trToggle(){
    myAccordion = new Accordion($$('.trans_togle'), $$('.trans_slide'), {
            onActive: function(toggler, slider){
                toggler.setStyles({'cursor': 'default', 'background': '#f7941e url(img/cur_arr.gif) left 8px no-repeat'});
                // f7941e
            },
            onBackground: function(toggler, slider){
                toggler.setStyles({'cursor': 'pointer', 'background': '#436994'});
            },

            opacity: 0,
            display: onDisplay,
            alwaysHide: false
    });
}

/*  */
function guletOver(){
    $each($$('.gul'), function(element, i){
        element.addEvent('mouseenter', function(){
            this.setStyle('background-color', '#f7941e');
        });
        element.addEvent('mouseleave', function(){
            this.setStyle('background-color', '');
        });
        element.addEvent('click', function(){
            var link = this.childNodes[0].href;
            document.location.href = link;
        });
    });
}

/* 22.03.2009 */
function startBa(){
    myAccordion = new Accordion($$('.bazi_toggle'), $$('.bazi_slide'), {
            onActive: function(toggler, slider){
                
            },
            onBackground: function(toggler, slider){
                
            },

            opacity: 0,
            display: onDisplay,
            alwaysHide: false
    });
}