function thm_cosmo_girl_on_ready() {
	var thm_mp_poll_stars = $('#thm_girl_control_panel b');
	var thm_offset = thm_mp_poll_stars.offset();
	var thm_position = thm_mp_poll_stars.position();
	var thm_tt = $('#thm_cosmo_cosmogirl');
	var thm_ttt = thm_tt.offset();
	var t_win = $(window);
	var curx = 0;
	var thm_curr = 0;
	var choice = '0';
	$(window).resize(function() {
		thm_offset = thm_mp_poll_stars.offset();
		thm_position = thm_mp_poll_stars.position();
		thm_ttt = thm_tt.offset();
	}).scroll(function() {
		thm_offset = thm_mp_poll_stars.offset();
		thm_position = thm_mp_poll_stars.position();
		thm_ttt = thm_tt.offset();
	});
	$('#thm_cosmo_cosmogirl').append('<div id="thm_choice" style="display:none;"></div>');
	$('body').append('<div id="thm_poll_hint"></div>');
	$('#thm_poll_hint').css('display','none').css('opacity','0.8').css('filter','Alpha(Opacity=80)');
	
	$(thm_mp_poll_stars).mouseenter(function() {}).mouseover(function(e) {$('#thm_choice').attr('style','display:block;left:'+thm_position.left+'px;top:'+(thm_position.top+3)+'px;background-position: 0px '+choice+';');});
	$('#thm_choice').click(function(){
		/*
		сюда вставляем отправку оценки на сервер, а также проверку на то
		что с одного компа можно голосовать только один раз за одну девушку
		две нижние строчки, собственно показывают выбранную оценку звездочками
		и соответственно если пытаются проголосовать за одну девушку более
		одного раза то две нижние строчки не выполняем, тоесть оценка остается 
		прежней
		*/
		// 		alert(thm_curr+' '+topGirls[girlId]['photoid']);
		$.ajax(
		{
			url:'/content/competitions/cosmogirl/ajax-vote.php?PhotoId='+topGirls[girlId]['photoid']+'&sum='+thm_curr, 
			   success:function(data){
				   var result = eval(data);
				   alert(result['mes']);
			   }
		}
		);
		$(thm_mp_poll_stars).attr('class','thm_mp_' + thm_curr);
		$('#thm_choice').attr('style','display:none;');
	}).mousemove(function(e) {
		curx = e.pageX-thm_offset.left;
		if ((curx >= 0) && (curx <= 14)) {thm_curr = 1;choice = '0px';}
		if ((curx >= 15) && (curx <= 31)) {thm_curr = 2;choice = '-22px';}
		if ((curx >= 32) && (curx <= 47)) {thm_curr = 3;choice = '-44px';}
		if ((curx >= 48) && (curx <= 63)) {thm_curr = 4;choice = '-66px';}
		if ((curx >= 64) && (curx <= 78)) {thm_curr = 5;choice = '-88px';}
		$('#thm_choice').css('background-position','0px '+choice);
		var thm_hint_color = 'white';
		var thm_hint_text = 'балл';
		switch (thm_curr) {
			case 1 : thm_hint_color = '#fff200'; thm_hint_text = 'балл'; break;
			case 2 : thm_hint_color = '#d8f405'; thm_hint_text = 'балла'; break;
			case 3 : thm_hint_color = '#9ef70b'; thm_hint_text = 'балла'; break;
			case 4 : thm_hint_color = '#4afb15'; thm_hint_text = 'балла'; break;
			case 5 : thm_hint_color = '#02ff1e'; thm_hint_text = 'баллов'; break;
		}
		
		$('#thm_poll_hint').css('display','block').css('position','absolute').css('width','60px').css('padding','4px 4px 4px 10px').css('left',e.pageX+'px').css('top',(e.pageY+20)+'px').css('border','1px solid #520448').css('background','#8d3a82').css('font-family','Arial').css('font-size','10px').css('color',thm_hint_color).css('text-align','left').css('text-transform','uppercase').css('line-height','100%').css('margin','0 !important').css('opacity','0.8').css('filter','Alpha(Opacity=80)').html(thm_curr + ' ' + thm_hint_text);
	}).mouseout(function() {$('#thm_choice').attr('style','display:none;');$('#thm_poll_hint').fadeTo('slow', 0.0, function(){$('#thm_poll_hint').css('display','none');});});
	$('#thm_listgirl_left').click(function() {thm_list_girl('prev');});
	$('#thm_listgirl_right').click(function() {thm_list_girl('next');});
	thm_list_girl('');
};

$(document).ready(function(){
	try {
		thm_cosmo_girl_on_ready();
	} catch(e) {}

});

function thm_list_girl(thm_comand) {
	var thm_gname = thm_gcity = thm_gage = thm_grating = thm_gimage = '';
	var thm_gpos = $('#thm_cosmo_cosmogirl').position();
	var thm_image = new Image();
	thm_image.onload = function() {
		$('#thm_girl_control_panel .thm_mp_gname').html(thm_gname).show();
		$('#thm_girl_control_panel .thm_mp_meta').html(thm_gcity+', '+thm_gage).show();
		$('#thm_girl_control_panel b').attr('class', 'thm_mp_'+thm_grating).show();
		$('.thm_mp_gloading').hide();
		$('.thm_mp_pdiv').html(' / ').show();
		$('#thm_girl_photo img').attr('src',thm_gimage)
		$('#thm_girl_photo').fadeTo('fast', 1.0, function(){});
		$('#thm_girl_listing_ajax').remove();
	}
	$('#thm_cosmo_cosmogirl').append('<div id="thm_girl_listing_ajax" style="left:'+(thm_gpos.left+18)+'px;top:'+thm_gpos.top+'px;"><div>загрузка...</div></div>');
	$('#thm_girl_control_panel .thm_mp_gname').html('').hide();
	$('#thm_girl_control_panel .thm_mp_meta').html('').hide();
	$('.thm_mp_pdiv').html('').hide();
	$('.thm_mp_gloading').show();
	$('#thm_girl_control_panel b').attr('class', 'thm_mp_0').hide();
	$('#thm_girl_photo').fadeTo('fast', 0.2, function(){});
	switch (thm_comand) {
		case '' :
			girlId = 0;
			break;
		case 'prev' :
			if (girlId == 0) girlId = topGirls.length - 1; else girlId--;
			break;
		case 'next' :
			if (girlId == topGirls.length - 1) girlId = 0; else girlId++;
			break;
	}
	thm_gname = topGirls[girlId]['name'];
	thm_gcity = topGirls[girlId]['city'];
	thm_gage = topGirls[girlId]['age'];
	thm_grating = topGirls[girlId]['ratingClass'];
	thm_gimage = topGirls[girlId]['thumb'];
	thm_image.src = thm_gimage; 
}
