


function chooseMenuSelect() {
	$(".choose .menu li").click(
		function() { $(this).toggleClass("select");}
	);
}

function filterMore() {
	$(".filter .more").click(
		function() { $(".overlay").show(); $(".window").show();}
	);
}

function search() {

	
	$(".loading-window").click(
		function() {
			 $(".projects").fadeTo("fast", 0);
			 $(".pager").fadeTo("fast", 0);
			 $(".loading-window").hide();
			 $(".search-window").show();
		}
	);

}

function toogleBlock() {
	$(".block.hidden .title h3").click(
		function() { 
		    $(this).find("span").css({'border-bottom':'1px dotted', 'cursor':'pointer'}); 
		    $(this).parent().parent().toggleClass("hidden");
		    }
	);
}

function projectMenu() {
    $('a.delete_interier').live('click', function() {
        if ($("div.delete-hover").css('display') == 'none') {
            $("div.delete-hover").show();
        } else {
            $("div.delete-hover").hide();
        }    
        return false;
    });    

	$(".owner .projects li .object").hover(
		//function() { $(this).append('<div class="edit">Редактировать</div>');},
		//function() { $(this).find(".edit").remove();}
	);
	/*
	$(".owner .projects li.new .object").hover(
		function() { $(this).find(".edit").remove(); $(this).append('<div class="add">Новый проект</div>');},
		function() { $(this).find(".add").remove();}
	);
	*/
	
	//$(".owner .projects li.new .object").find(".butt-edit").remove();
	//$(".owner .projects li.new .object").append('<div class="button butt-add"><span>Новый проект</span></div>');
	
	
		$(".owner .projects li .delete").hover(
		function() { $(this).parent().append('<div class="button butt-delete-hover"><span>Удалить</span></div>');},
		function() { $(this).parent().find("div.butt-delete-hover").remove();}
	    );
	    
	  $(".owner .projects li .delete").click(
		function() { 
		
		    if ( $(this).hasClass("active") ) {		                    
                $(this).removeClass("active");
			    $(this).parent().append(".butt-edit");
			    $(this).parent().find(".delete-hover").hide(); 
		    } else {
                
                $(this).addClass("active");
			    $(this).parent().find(".butt-edit").remove();
			    $(this).parent().find(".delete-hover").show();
                		    
		    }
		

			return false;
		}
	);
	    
}


function messageHover() {
	$(".personal-mail li").hover(
		function() { $(this).addClass("hover");},
		function() { $(this).removeClass("hover");}
	);
}


var hover_timer = '';

function commentHover() {
	$(".comments .message").hover(
		function() { 
		    $(".comments .message").parent().removeClass("hover").find(".hover-img").hide();
		    $(".edit-menu").hide(); 
		    
		    
			$(this).parent().addClass("hover"); $(this).find(".hover-img").show();
			clearTimeout(hover_timer);
		},
		function() {
			clearTimeout(hover_timer)
			hover_timer = setTimeout('$(".comments .message").parent().removeClass("hover").find(".hover-img").hide();$(".edit-menu").hide();', 200);
			//console.log('comment hover')
		}
	);

	
}

function editMenuHover() {

}


function autoFill(id){
	
	var title = $(id).attr('title');
	
	if ($(id).val() == '') {
/*
	    var ititle = title; 
	    
	    $(id).addClass("readonly").attr({ value: ititle }).focus(function(){
		if($(id).val()==title){
			$(id).val("").removeClass("readonly");
		}
	    }).blur(function(){
		    if($(id).val()==""){
			    $(id).addClass("readonly").val(title);
		    }
	    });
*/	        
	    
	} else {
	    var ititle = $(id).val(); 
       
	    $(id).removeClass("readonly").focus(function(){
	    //console.log('val',$(id).val(), title, $(id).attr('title'));
		if($(id).val()==title){
			$(id).val("").removeClass("readonly");
		}
	    }).blur(function(){
		    if($(id).val()==""){
			    $(id).addClass("readonly").val(title);
		    }
	    });
	      	    
	    
	}
	
	

}

function showGallery() {
	$("#gallery-link").click(
		function() { $(".overlay").show(); $(".gallery-win").show();}
	);
}

function portrait() {
	var parent = $(".portrait .avatar").parent();
	$(".portrait li").hover(
		function() {
			$(this).addClass("hover");
			$(".portrait").find(".overlay").show();
			
		},
		function() { 
			$(this).removeClass("hover");
			$(".portrait").find(".overlay").hide();
		}
	);
}

$(
	function () {
		autoFill("#theme");
		search();
		chooseMenuSelect();
		toogleBlock();
		projectMenu();
		messageHover();
		commentHover();
		editMenuHover();
		portrait();
	}
)

