function t_event( emotion, name, text_formal, text_unformal ){
	
	if( emotion == 'NORMA' ){ this.bird_id = 1; }
	if( emotion == 'RADOST' ){ this.bird_id = 2; }
	if( emotion == 'UDIVLENIE' ){ this.bird_id = 3; }
	this.name = name;

	this.text = new Array();
	this.text[1] = text_formal;
	this.text[2] = text_unformal;

}

function t_bird( x, y ){


	this.x = x;
	this.y = y;
	
	this.msg_width = 300;
	this.msg_bottom = 130;
	this.msg_padding = 10;
	
	this.lang = 1;
	
	this.faces = new Array();
	this.faces[0] = new Image(); this.faces[0].src = '/img/bird/normal.png';
	this.faces[1] = new Image(); this.faces[1].src = '/img/bird/normal.png';
	this.faces[2] = new Image(); this.faces[2].src = '/img/bird/pleasure.png';
	this.faces[3] = new Image(); this.faces[3].src = '/img/bird/surprise.png';

	this.events = new Array();
	
	// Методы
	this.show = t_bird_show;
	this.event = t_bird_event;
	this.reset = t_bird_reset;
	// Смена морды
	this.changeFace = t_bird_changeFace;
	// Смена языка общения
	this.showLang = t_bird_showLang;
	this.hideLang = t_bird_hideLang;
	this.setLang = t_bird_setLang;

	/////////////////

	if( document.cookie.indexOf('birdLanguage=2') != -1 ){
		this.lang = 2;
	} else {
		this.lang = 1;
		// Не найден
		//if( document.cookie.indexOf('birdLanguage=1') == -1 ){ this.showLang(); }
	}


	
}

function t_bird_show(){
	
	document.write( '\
		<div id="div_bird" style="position:fixed; bottom:'+this.y+'px; right:'+this.x+'px;" >\
			<div id="msg_bird" style="position:absolute; left:-'+this.msg_width+'px; bottom:'+this.msg_bottom+'px; border:solid #FF5F45 1px; background:#FFEAE7; width:'+( this.msg_width-2*this.msg_padding )+'px; _width:'+( this.msg_width )+'px; padding:'+this.msg_padding+'px; display:none;"></div>\
			<div id="lang_bird" onmouseover="bird.showLang();" onmouseout="bird.hideLang();" style="position:absolute; left:-220px; bottom:10px; border:solid #999999 1px; background:white; width:220px; _width:220px; padding:5px; display:none;">\
			Язык помощника:<br>\
			<label for="bird_lang_1" onclick="bird.setLang(1);"><input type="Radio" id="bird_lang_1" name="bird_lang" '+( this.lang == 1 ? 'checked' : '' )+'>Формальный</label>\
			<label for="bird_lang_2" onclick="bird.setLang(2);"><input type="Radio" id="bird_lang_2" name="bird_lang"'+( this.lang == 2 ? 'checked' : '' )+'>Неформальный</label>\
			</div>\
			<img id="img_bird" onmouseover="bird.showLang();" onmouseout="bird.hideLang();" src="'+this.faces[0].src+'">\
		</div>\
		' );

}

function t_bird_changeFace( num ){
	document.all['img_bird'].src = this.faces[num].src;
}

function t_bird_event( num ){
	document.all['img_bird'].src = this.faces[ this.events[num].bird_id ].src;
	document.all['msg_bird'].innerHTML = '<h3>'+this.events[num].name+'</h3><p>'+this.events[num].text[ this.lang ]+'</p>';
	document.all['msg_bird'].style.display = 'block';
	
}

function t_bird_reset( num ){
	document.all['img_bird'].src = this.faces[0].src;
	document.all['msg_bird'].innerHTML = '';
	document.all['msg_bird'].style.display = 'none';
}

function t_bird_showLang(){
	document.all['lang_bird'].style.display = 'block';
}
function t_bird_hideLang(){
	document.all['lang_bird'].style.display = 'none';
}

function t_bird_setLang(num){
	this.lang = num;
	dt= new Date();
	dt.setTime( dt.getTime() + ( 365*24*3600*1000 ) );
	document.cookie = 'birdLanguage='+this.lang+'; expires='+dt.toGMTString();
}


