function openVerMenu(mid){
	if($("#vsubmenu_"+mid).css("display")=="none"){
		$("#vsubmenu_"+mid).show(200);
		saveOpenedMenu(mid,1);
	}else{
		$("#vsubmenu_"+mid).hide(200);
		saveOpenedMenu(mid,0);
	}
}
function saveOpenedMenu(mid,stat){
	 $.ajax({
	   type: "get",
	   url: saveMenuScript,
	   data: "mid="+mid+"&stat="+stat,
	   success: function(msg){
		 void(0);
	   }
	 });
}

window.onload = function () {
    // Set #body to size, (so it'd be dividable by 80) - 10. (for the sake of bk's good looking)
    var elem = $('#body');
    var h = elem.outerHeight();
    // The math magick.
    h += 70 - h % 80;
    // Substracting padding.
    h -= parseInt(elem.css('padding-top')) + parseInt(elem.css('padding-bottom'));
    elem.css('height', h);
}

$(document).ready(function() {
    /* blargh.. tables */
    $('.table-1 tr:not(:first) td:first-child').each(function(item, index) {
        if ($(this).html() != '&nbsp;') {
            /* console.log ($(this).parent()); */
            $(this).parent().children().css('border-top', '1px solid white');
            var titles = $(this).parent().find('td:not(:first)');
            if (titles.css('background-color') == 'rgb(241, 239, 230)') {
                titles.css('background', '#8a8779');
                titles.css('color', 'white');
                titles.css('font-weight', 'bold');
            }
        }
    });
    $('.table-1 tr td:not(:first-child):not(:nth-child(5))').each(function(item,index) {
        if ($(this).html().match(/^(&nbsp;|[\n\s])*\d+((&nbsp;|[\n\s])*\/(&nbsp;|<br \/>|[\n\s])*\d+)?\.?(&nbsp;|[\n\s])*$/) == null
            && $(this).html().match(/^_$/) == null) {
            if ($(this).html() != '&nbsp;')
                $(this).css('border-right', '15px solid #dcd9c9');
        }
        else {
            if ($(this).html().match(/^_$/)) $(this).html(' ');
                $(this).css('background', '#c5c2b7');
        }
    });

	$('input[type=text][title!=""]').each(function() {
	if ($.trim($(this).val()) == '') $(this).val($(this).attr('title'));
	if ($(this).val() == $(this).attr('title')) $(this).addClass('exampleText');
	}).focus(switchText).blur(switchText);
	$('[rel=fancybox]').fancybox({ 'zoomSpeedIn': 300, 'zoomSpeedOut': 300, 'overlayShow': true });
	leftMenu();
});
function switchText(){
	if ($(this).val() == $(this).attr('title'))
		$(this).val('').removeClass('exampleText');
	else if ($.trim($(this).val()) == '')
		$(this).addClass('exampleText').val($(this).attr('title'));
}
function __ (text, params) {
	text = text.toUpperCase();
	if (phrases[text])
		phrase = phrases[text];
	else
		phrase = '*' + text + '*';

	if (typeof(phrase) == "object" || typeof(phrase) == "array") {
		var param;
		for (key in params) {
			param = params[key];
			break;
		}

		phrase = phrase[plural(param)];
	}

	for (key in params)
		phrase = phrase.replace('%{' + key + '}', params[key]);

	return phrase;
}

function leftMenu(){
	var newClass = 'leftSubmenuBlock';
	$('.'+newClass).each(function(){
		var block = this;
		$(this).parent().bind("mouseenter",function(){
			$(this).addClass('selected');
			$(block).show();
		}).bind("mouseleave",function(){
			$(block).hide();
			$(this).removeClass('selected');
		});;
	});
}

