$(document).ready(function($){

    $(document).pngFix();
    var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);

    $('#filials').load('/index.php?action=default/filials', {}, function(){
        $('#contacts a.button').prepend('<div style="width:2px;height:24px;background:url(/img/r1.gif) left; position: absolute; margin-left: -10px; >margin-top: -5px"></div>');
        $('#contacts a.button').click(function(){
            var el = $(this).next();
            el.css('z-index','300');
            el.show(200, function(){
                $(document).one('click', function(){
                    el.hide();
                })
                })
        })
    });

  

    if (!ie6)
    {
        $('#basketinfo').prepend(
            '<div style="width:3px;height:3px;background:url(/img/r3.gif) top; position: absolute;"></div>'+
            '<div style="width:3px;height:3px;background:url(/img/r3.gif) bottom; position: absolute; margin-top: 67px;"></div>');
        $('#rightpanel .ourprojects').prepend('<div style="width:3px;height:3px;background:url(/img/r3.gif) top; position: absolute; margin-left:-25px; margin-top:-10px;"></div>');
        $('#rightpanel .ourprojects').append('<div style="width:3px;height:3px;background:url(/img/r3.gif) bottom; position: absolute; margin-left:-25px; margin-top: 7px;"></div>');
    }
  

  
    $('#leftpanel .title a.more').click(function(){
        var el = $('#more_caregories');
        el.css('z-index','300');
        el.show(200, function(){
            $(document).one('click', function(){
                el.hide();
            })
            })
    })

    $('#leftpanel .menu > li > a').click(function(){
        $('#leftpanel .menu ul').hide();
        $(this).next().show();
    })
  
    $(".scrollable").scrollable({
        api: true,
        size: 3,
        clickable: false
    });
    var vscroll_api = $(".vscrollable").scrollable({
        api: true,
        size: 3,
        vertical: true
    });
    $(".vscrollable .items .img, .vscrollable .items .name").click(function(){
        $('.selected_name').html($(this).parent().find('.name').html());
        $('.selected_descr').html($(this).parent().find('.descr').html());
        $('.selected_img').html($(this).parent().find('.img_big').html());
    })

    $('.switcher').click(function(){
        $(this).next().toggle();
    })

    $('a.additional_button').click(function(){
        $(this).prev().find('.additional').show();
        $(this).hide();
        return false;
    })

    $('a.oblast').click(function(){
        $(this).next().show();
        $(this).hide();
        return false;
    })

    $('#footer .menu .level1 a').click(function(){
        var id = this.href.match(/#(.+)$/)[1];
        $('#footer .menu .level2').hide();
        $('#footer .menu .level3').hide();
        $('#'+id).show();
        $(this).parent().siblings().removeClass('selected');
        $(this).parent().addClass('selected');
        return false;
    })
    $('#footer .menu .level2 a').click(function(){
        var id = this.href.match(/#(.+)$/)[1];
        $('#footer .menu .level3').hide();
        $('#'+id).show();
        $(this).parent().siblings().removeClass('selected');
        $(this).parent().addClass('selected');
        return false;
    })
    var t = new Date();
    $('#studiomag_foto_text').load('/rand_image.php', {
        cache: t.toGMTString()
        }).removeClass('hidden').addClass('ad');


    $('textarea.tg_rich_news').each(function(t) {
        $(this).tinymce({
            script_url: '/js/tiny_mce/tiny_mce.js',
            theme : "advanced",
            plugins : "phpimage,layer,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,advlist",
            theme_advanced_buttons1 : "cut,copy,paste,pastetext,pasteword,|,undo,redo,|,bold,italic,underline,|,phpimage,|,fullscreen",
            theme_advanced_buttons2 : '',
            theme_advanced_buttons3 : '',
            theme_advanced_buttons4 : '',
            theme_advanced_toolbar_location : "top",
            theme_advanced_toolbar_align : "left",
            theme_advanced_statusbar_location : "bottom",
            theme_advanced_resizing : true,
            content_css : "/css/main.css"
        });
    });

  
})