jQuery(document).ready(
    function(){
        new SubMenu();

        if(window.location.toString().indexOf('shiny')>-1)
        {
            jQuery('#l2').css('background', '#e7eaef');
            jQuery('#l2').css('color', '#525762');
            jQuery('body').find('#sub_nav').html(jQuery('body').find('#sub_tyres').html());
            SubMenu.style();
        }
        else if(window.location.toString().indexOf('motoshiny')>-1)
        {
            jQuery('#l2').css('background', '#e7eaef');
            jQuery('#l2').css('color', '#525762');
            jQuery('body').find('#sub_nav').html(jQuery('body').find('#sub_tyres').html());
            SubMenu.style();
        }
        else if(window.location.toString().indexOf('gruzovie_shiny')>-1)
        {
            jQuery('#l2').css('background', '#e7eaef');
            jQuery('#l2').css('color', '#525762');
            jQuery('body').find('#sub_nav').html(jQuery('body').find('#sub_tyres').html());
            SubMenu.style();
        }
        else if(window.location.toString().indexOf('videoregistratory')>-1)
        {
            jQuery('#l4').css('background', '#e7eaef');
            jQuery('#l4').css('color', '#525762');
            jQuery('body').find('#sub_nav').html(jQuery('body').find('#sub_el').html());
            SubMenu.style();
        }
        else if(window.location.toString().indexOf('navigatory')>-1)
        {
            jQuery('#l4').css('background', '#e7eaef');
            jQuery('#l4').css('color', '#525762');
            jQuery('body').find('#sub_nav').html(jQuery('body').find('#sub_el').html());
            SubMenu.style();
        }
        else if(window.location.toString().indexOf('avtomoiki')>-1)
        {
            jQuery('#l4').css('background', '#e7eaef');
            jQuery('#l4').css('color', '#525762');
            jQuery('body').find('#sub_nav').html(jQuery('body').find('#sub_el').html());
            SubMenu.style();
        }
        else if(window.location.toString() == 'http://carrida.ru/')
        {
            jQuery('#l1').css('background', '#e7eaef');
            jQuery('#l1').css('color', '#525762');
            jQuery('body').find('#sub_nav').html(jQuery('body').find('#sub_m').html());
            SubMenu.style();
        }
        else if(window.location.toString() == 'http://www.carrida.ru/')
        {
            jQuery('#l1').css('background', '#e7eaef');
            jQuery('#l1').css('color', '#525762');
            jQuery('body').find('#sub_nav').html(jQuery('body').find('#sub_m').html());
            SubMenu.style();
        }
        else if(window.location.toString().indexOf('company')>-1)
        {
            jQuery('#l1').css('background', '#e7eaef');
            jQuery('#l1').css('color', '#525762');
            jQuery('body').find('#sub_nav').html(jQuery('body').find('#sub_m').html());
            SubMenu.style();
        }
        else if(window.location.toString().indexOf('payment')>-1)
        {
            jQuery('#l1').css('background', '#e7eaef');
            jQuery('#l1').css('color', '#525762');
            jQuery('body').find('#sub_nav').html(jQuery('body').find('#sub_m').html());
            SubMenu.style();
        }
        else if(window.location.toString().indexOf('delivery')>-1)
        {
            jQuery('#l1').css('background', '#e7eaef');
            jQuery('#l1').css('color', '#525762');
            jQuery('body').find('#sub_nav').html(jQuery('body').find('#sub_m').html());
            SubMenu.style();
        }
        else if(window.location.toString().indexOf('guarantees')>-1)
        {
            jQuery('#l1').css('background', '#e7eaef');
            jQuery('#l1').css('color', '#525762');
            jQuery('body').find('#sub_nav').html(jQuery('body').find('#sub_m').html());
            SubMenu.style();
        }
        else if(window.location.toString().indexOf('wiki')>-1)
        {
            jQuery('#l1').css('background', '#e7eaef');
            jQuery('#l1').css('color', '#525762');
            jQuery('body').find('#sub_nav').html(jQuery('body').find('#sub_m').html());
            SubMenu.style();
        }
        else if(window.location.toString().indexOf('map')>-1)
        {
            jQuery('#l1').css('background', '#e7eaef');
            jQuery('#l1').css('color', '#525762');
            jQuery('body').find('#sub_nav').html(jQuery('body').find('#sub_m').html());
            SubMenu.style();
        }
        else if(window.location.toString().indexOf('sale')>-1)
        {
            jQuery('#l1').css('background', '#e7eaef');
            jQuery('#l1').css('color', '#525762');
            jQuery('body').find('#sub_nav').html(jQuery('body').find('#sub_m').html());
            SubMenu.style();
        }
        else if(window.location.toString().indexOf('litye_diski')>-1)
        {
            jQuery('#l3').css('background', '#e7eaef');
            jQuery('#l3').css('color', '#525762');
            jQuery('body').find('#sub_nav').html(jQuery('body').find('#sub_d').html());
            SubMenu.style();
        }
        else if(window.location.toString().indexOf('replica')>-1)
        {
            jQuery('#l3').css('background', '#e7eaef');
            jQuery('#l3').css('color', '#525762');
            jQuery('body').find('#sub_nav').html(jQuery('body').find('#sub_d').html());
            SubMenu.style();
        }
        else if(window.location.toString().indexOf('avtokresla')>-1)
        {
            jQuery('#l5').css('background', '#e7eaef');
            jQuery('#l5').css('color', '#525762');
            SubMenu.style();
        }
        else if(window.location.toString().indexOf('motornoe_maslo')>-1)
        {
            jQuery('#l6').css('background', '#e7eaef');
            jQuery('#l6').css('color', '#525762');
            SubMenu.style();
        }
    }
    );
        
SubMenu.style= function()
{
    jQuery('body').find('#sub_nav').css('padding', '5px');
    jQuery('body').find('#sub_nav').css('height', '15px');  
}

function SubMenu()
{
    jQuery('body').find('#main_menu').children('li').children('a').click(function(){
        var ul = jQuery(this).attr('rel')
        if(ul != '')
        {
            SubMenu.style();
            jQuery('body').find('#sub_nav').html(jQuery('body').find('#'+ul).html());
            return true;
        }
        jQuery(this).css('background', '#e7eaef');
        return true;
    });
}
