$(document).ready(function(){
    var w = $("#mid_menu").width();
//    if (w>800) 
//    resizeMenu(w);
//    $(window).resize(function(){
//	resizeMenu($("#mid_menu").width());
//    });
});
function resizeMenu(w){
    var first=$("#mid_menu .first").width();
    var second=$("#mid_menu .second").width();
    var third=$("#mid_menu .third").width();
//    var sum = first + second + third;
    
    razn = w - 20 - first - second - third;
    
//    alert(w+' ' + first +' ' + second+' '+third);
    $("#mid_menu .second").css({marginLeft:razn/3});
    $("#mid_menu .third").css({marginLeft:razn/3});
}
// Добавить в Избранное
function add_favorite(a) {
    dtitle=document.title;
    durl=document.location;
    try {
	// Internet Explorer
	window.external.AddFavorite(durl, dtitle);
    }catch (e) {
	try {
	    // Mozilla
	    window.sidebar.addPanel(dtitle, durl, "");
	}catch (e) {
	    // Opera
	    if (typeof(opera)=="object") {
		a.rel="sidebar";
		a.title=dtitle;
		a.url=durl;
		return true;
	    } else {
		// Unknown
		alert('Нажмите Ctrl-D чтобы добавить страницу в закладки');
	    }
	}
    }
    return false;
}
						   
$(function(){
    $("#lmenu > a[id]").append('<img src="/Images/darrow.gif" class="tmps" align="top">');
    $("#lmenu > a").mouseover(function(){
	    $(this).find("img").hide();
	    var oo = document.getElementById('menuabr');
	    if (oo) $(oo).remove();
	    if ($(this).attr("id").length>0){
		var $el = $("#div"+$(this).attr('id')), offs = $(this).offset(), l = offs.left+$(this).width()-1, t = offs.top;
	    $("body").append('<div id="menuabr"><div class="ppmno">'+$el.html()+'</div></div>').find("#menuabr").hide()
		.css({position:"absolute",
		    left:l,
		    top:t
		}).mouseleave(function(){$(this).remove();}).show('fold');
	    }
    }).mouseout(function(){$(this).find("img").show()});
    
//});
//$(function() {
        $("#dialog-confirm").dialog('destroy');
        $("#dialog-confirm").dialog({
                bgiframe: true,
                resizable: false,
                height:250,
		width:400,
                modal: true,
		autoOpen: false,
                overlay: {
                        backgroundColor: '#000',
                        opacity: 0.7
                },
                buttons: {
			'Отмена': function() {
                                $(this).dialog('close');
                        },
                        'В Избранное': function() {
				$("#hdnFavLink").trigger('click');
                                $(this).dialog('close');
                        },
			'В Яндекс.Закладки': function() {
				Add2Yandex();
                                $(this).dialog('close');
                        }
                }
        });
//});
//$(document).ready(function(){
        $("body").find("a.bigim").each(function(){
        $(this).fancybox({
            padding:0,
            overlayOpacity:0.6,
            frameWidth: "100%",
            frameHeight:"100%",
            zoomSpeedIn: 200,
            zoomSpeedOut: 200,
            hideOnContentClick: true
        })
    });
//});
//$(function(){
    if ( $('.spoilers').length ){
	$('.spoilers').each(function(ed){
	    $(this).attr("id","t_tid"+ed).after('<div class="spoilerclick" id="tid'+ed+'"></div>').hide();
	    $("#tid"+ed).text($(this).attr("title")).live("click",function(){
		if ($(this).hasClass('show')){
		    $("#t_tid"+ed).slideUp(2000);
		    $(this).removeClass('show').text($("#t_tid"+ed).attr("title"));
		}else{
	    	    $("#t_tid"+ed).slideDown(2000);
	    	    $(this).addClass('show').text("скрыть");
		}
	    });
	})
    }
});
