$(document).ready(function(){
   /* $('.left_side .menu li div a:not(.selected)').hover(
        function(){
    		$(this).addClass('hover');
    	},
  		function(){
    		$(this).removeClass('hover');
    	}
    );
    $('.main .menu .items li.top').each(function(){
    	var shadow	= $(this).find('a').html();
    	$(this).prepend('<span class="shadow">' + shadow + '</span>');
    });
    $('.main .menu .items li.top:not(.selected)').hover(
        function(){
    		$(this).addClass('hover');
    	},
  		function(){
    		$(this).removeClass('hover');
    	}
    ); */
    $('input.onfocus').focus(function(){
		var value	= $(this).attr('title');
		if($(this).attr('value') == value)
	    	$(this).attr('value', '');
	});

	$('input.onfocus').blur(function(){
		var value	= $(this).attr('title');
		if($(this).attr('value') == '')
	    	$(this).attr('value', value);
	});

   	$('form.required_form .required').each(function(){
   		var value	= $(this).attr('value');
   		if (value == ''){
   			var value	= $(this).attr('title');
   			$(this).attr('value', value).addClass('required_text');
   		}
   		letsCheck();
   	});

   	$('form.required_form .required').focus(function(){
   		var title	= $(this).attr('title');
   		if($(this).attr('value') == title)
   		$(this).attr('value', '').removeClass('required_text');

   		var button			= $(this).parents('form.required_form').find('input.button');
		var required_check	= $(this).parents('form.required_form').find('.required_text').size();

   		$(this).keyup(function(){
			var required_value	= $(this).attr('value');
			if(required_check == 0 & ($(required_value).size() != 1)) {
				$(button).attr('disabled', '');
			} else {
				$(button).attr('disabled', 'disabled');
			}
   		});
   	});

   	$('form.required_form .required').blur(function(){
   		var title	= $(this).attr('title');
   		if($(this).attr('value') == '')
			$(this).addClass('required_text').attr('value', title);
		letsCheck();
   	});

   	function letsCheck(){
    	$('form.required_form').each(function(){
    		var required_check	= $(this).find('.required_text').size();
    		var button			= $(this).find('input.button');
    		if(required_check == 0) {
				$(button).attr('disabled', '');
			} else {
				$(button).attr('disabled', 'disabled');
			}
    	});
	}

	$('#big_map_link').click(function(){
   		$('#big_map').toggle();
   	});
	
	// справочник
	$('.directory-list .item h3 span').click(function(){
		$(this).parent().siblings('.text').toggle();
	});

});

function change_image() {

	var random = Math.floor(Math.random() * (4 - 0 + 1)) + 0;
	var current = $('#head .photo div[class^=img]:eq(' + random + ')');
	var num = $(current).attr('class').match(/img_(\d+)/)[1];

	$(current).stop().fadeOut(1000, function(){
		$.get('/im/photo/rnd.php', {num: num}, function(data){
			$(current).find('img').attr('src', data).load(function(){
				$(current).fadeIn(1000);
			});
		});		
	});

}

$(window).ready(function(){
	setInterval('change_image()', 5000);
});
