$(document).ready(function(){
    $('#pwd').bind('focus', function() {
	    this.style.color = '#000000';
	    if(this.value == 'Пароль') {
	        this.value = '';
	        changeInputType(this, 'password');
	    }
	}).bind('blur', function() {
        if(this.value == '') {
            this.style.color = '#CCCCCC';
            this.value = 'Пароль';
            changeInputType(this, 'text');
        }
	});
    $('#menu_text').css({
	   margin: '0',
       zIndex: '100'
	});
    if (!$.browser.msie) {
        var divTop = $('div[id^=menubox]:first').css('top');
        divTop = divTop.replace('px','');
        divTop = Number(divTop);
    }
    else
        var divTop = 175;
    window.divTop = divTop;
    $('#menu_text div[id^=_menu]').each(function() {
        $(this).css({display: 'block', float: 'left', height: '57px'});
        $('a[id^=link]', this).css({
            lineHeight: '57px',
            padding: '0 10px',
            color: '#b50000'
        });
    }); 
    $('#menu_text div div a').css({
        color: "#000000", 
        fontWeight: 'normal'
    }).hover(function() {
       $(this).css({background: "#F5F5DC", color: "#000000"});
    },
    function() {
       $(this).css({background: "#E9E9E9", color: "#000000"});
    });
    $('#menu_text div[id^=menubox]').css({
        visibility: "hidden", 
        display: 'none', 
        position: 'absolute',
        borderBottom: '1px #000000 solid',
        borderLeft: '1px #000000 solid',
        borderRight: '1px #000000 solid',
        zIndex: '100'
    });
    if ($.browser.msie && Number($.browser.version) == 6) {
        $('#menu_text div[id^=menubox]').each(function() {
            if ($(this).find('div').length > 1) {
                var w = 0;
                var divs = $(this).find('div');
                if (divs.length == 3)
                    w = 353;
                else
                    w = 531; 
                $(this).css({width: w + 'px'});
            }
        });
    }
    $("#menu_text div[id^=_menu]").hover(function(){
        $(this).css({backgroundColor: '#E9E9E9'});
        var id = $(this).find('a:first').attr('id');
        id = id.substr(5);
        var left = $(this).find('a:first').attr('offsetLeft');
        if ($.browser.msie && Number($.browser.version) < 8) {
            var parentLeft = $('.wrapper').attr('offsetLeft') + $('.bg_content').attr('offsetLeft') + $('#menu').attr('offsetLeft') + $('#menu_text').attr('offsetLeft');
            var pos = getElementPosition('_menu' + id);            
        	left = parentLeft + pos['left'];
        }
        id = 'menubox_' + id;
        if ($.browser.msie && Number($.browser.version) == 6) {
            $('#' + id).css({top: 57 + 'px'});
            left = 0;
        }
        $(this).find('a:first').css({background: "#E9E9E9"});
        $('#' + id).css({left: left + 'px', visibility: "visible", display: "block"}).show(400);
        if ($.browser.msie && Number($.browser.version) == 6) {
            var divHeight = 0;
            $('#' + id).find('div').each(function() {
                if ($(this).attr('clientHeight') > divHeight)
                    divHeight = $(this).attr('clientHeight'); 
            });
        }
	    else {
            var divHeight = 0;
            $('#' + id).find('div').each(function() {
                if ($(this).attr('offsetHeight') > divHeight)
                    divHeight = $(this).attr('offsetHeight'); 
            });
        }
        $('#' + id).css({height: divHeight + 'px'})
        $('#' + id + ' > div').each(function() {
            $(this).css({height: divHeight + 'px', display: 'block', float: 'left'});
        });
    },
    function(){
        $(this).css({backgroundColor: '#F5F5DC'});
        $(this).find('a:first').css({background: "#F5F5DC"});
        var id = $(this).find('a:first').attr('id');
        id = id.substr(5);
        id = 'menubox_' + id;
        $('#' + id).css({visibility: "hidden", display: 'none'});
    });
    $('.submenu_link').hover(function() {
    	var submenu_left = Number($(this).css('left').substr(0,$(this).css('left').indexOf('px'))) + Number($(this).css('width').substr(0,$(this).css('width').indexOf('px')));
    	submenu_left = submenu_left + 'px';
    	var submenu_id = $(this).attr('id');
    	var submenu_top = $(this).attr('offsetTop') + Number($(this).css('paddingTop').replace('px', '')) + Number($(this).css('marginTop').replace('px', ''));
        submenu_top = '19px';
        $(this).children('div:first').css({position: "absolute", display: "block", left: submenu_left, top: submenu_top});
    	$(this).children('div:first').css({visibility: "visible"});
    },
    function() {
    	$(this).children('div:first').css({visibility: "hidden"});
    });
});
function getElementComputedStyle(elem, prop) {
    if (typeof elem!="object")
        elem = document.getElementById(elem);
    // external stylesheet for Mozilla, Opera 7+ and Safari 1.3+
    if (document.defaultView && document.defaultView.getComputedStyle) {
        if (prop.match(/[A-Z]/))
            prop = prop.replace(/([A-Z])/g, "-$1").toLowerCase();
        return document.defaultView.getComputedStyle(elem, "").getPropertyValue(prop);
    }
    // external stylesheet for Explorer and Opera 9
    if (elem.currentStyle) {
        var i;
        while ((i=prop.indexOf("-"))!=-1)
            prop = prop.substr(0, i) + prop.substr(i+1,1).toUpperCase() + prop.substr(i+2);
        return elem.currentStyle[prop];
    }
    return "";
}
function getElementPosition(elemId) {
    var elem = document.getElementById(elemId);
    var w = elem.offsetWidth;
    var h = elem.offsetHeight;
    var l = 0;
    var t = 0;
    while (elem) {
        l += elem.offsetLeft;
        t += elem.offsetTop;
        elem = elem.parent;
    }
    return {"left":l, "top":t, "width": w, "height":h};
}		
		
function changeInputType(obj, _type) {
	var id = obj.id;
	var obj_style = $(obj).attr('style');
	var new_obj = '<input type="' + _type + '" ' + ((obj.id)?'id="' + obj.id + '" ':'') + ((obj.className)?'class="' + obj.className + '" ':'') +
		((obj.value)?'value="' + obj.value + '" ':'') + ((obj.name)?'name="' + obj.name + '" ':'') + ((obj.size)?'size="' + obj.size + '" ':'') + ((obj_style)?'style="' + obj_style + '" ':'') + '/>';
	$(obj).replaceWith(new_obj);
	if (_type == 'password')
		document.getElementById(id).focus();
	$('#' + id).bind('focus', function() {
	    this.style.color = '#000000';
	    if(this.value == 'Пароль') {
	        this.value = '';
	        changeInputType(this, 'password');
	    }
	}).
	bind('blur', function() {
		if(this.value == '') {
		    this.style.color = '#CCCCCC';
			this.value = 'Пароль';
		    changeInputType(this, 'text');
		}
	});
}

