$(document).ready(function(){
	privateChatOpened();
});
function addSmile(smile_code) {
	if ($('#private_chat_send input[type=text]').val()=='Введите сообщение...') {
		$('#private_chat_send input[type=text]').val('');
	}
	$('#private_chat_send input[type=text]').val($('#private_chat_send input[type=text]').val() + smile_code);
}
var clicked = false;
var draggable = false;
var private_chat_opened = false;
function privateChatOpened() {
	
	if (!$('#private_chat_close').length) return false;
	if (private_chat_opened) return false;
	private_chat_opened = true;
	
    $('#private_chat_close').live('mouseover mouseout', function(event) {
        if (event.type == 'mouseover') {
            $(this).css('background-image', 'url("http://www.starichki.ru/_server/im_new/private_chat/close_btn_hover.png")');
        } else {
            $(this).css('background-image', 'url("http://www.starichki.ru/_server/im_new/private_chat/close_btn.png")');
        }
    });

    $('#private_chat_send_button').live('mouseover mouseout', function(event) {
        if (event.type == 'mouseover') {
            $(this).css('background-image', 'url("http://www.starichki.ru/_server/im_new/private_chat/enter_btn_hover.png")');
        } else {
            $(this).css('background-image', 'url("http://www.starichki.ru/_server/im_new/private_chat/enter_btn_still.png")');
        }
    });
    $('#private_chat_smiles .smile1').live('click', function(){
        addSmile(' :) ');
    });
    $('#private_chat_smiles .smile2').live('click', function(){
        addSmile(' :O ');
    });
    $('#private_chat_smiles .smile3').live('click', function(){
        addSmile(' :D ');
    });
    $('#private_chat_smiles .smile4').live('click', function(){
        addSmile(' ;) ');
    });
    $('#private_chat_smiles .smile5').live('click', function(){
        addSmile(' :\'( ');
    });
    $('#private_chat_smiles .smile6').live('click', function(){
        addSmile(' :( ');
    });
    $('#private_chat_smiles .smile7').live('click', function(){
        addSmile(' :* ');
    });
    $('#private_chat_smiles .smile8').live('click', function(){
        addSmile(' 8-) ');
    });
    $('#private_chat_smiles .smile9').live('click', function(){
        addSmile(' :-/ ');
    });


    

}

    
$('#private_chat_send input').live('click', function(){
	if(!clicked) {
		clicked = true;
		$(this).val('');
	}
});
$('.private_chat').live('hover', function(){
	if(!draggable){
		$('.private_chat').draggable({
			cancel: '.cancel_draggable'
		});
	}
	privateChatOpened();
});
