//кликаю по звездочке
function clk_on_star(itemId,starId,ftype)
{    new Request({method: 'get', url: '/vote.php?id='+itemId+'&ftype='+ftype+'&ball='+starId, onSuccess: function(text, xml) {$('rateDiv').empty().set('html', text);}}).send();
    return false;
}


//звездочки
function sel_stars(oimg,prefiks)
{
        //id звездочки на которую навели
        var sel_star_id=oimg.id;
        var zakrasit=1;

        //перебираем все звездочки
        for (i=0; i<5; i++)
        {

                        if (zakrasit==1)
                        {
                                //делаем звездочки полными
                                oimgoth=document.getElementById(prefiks+i);
                                oimgoth.className="starfull";
                        }
                        else
                        {
                                //делаем звездочик пустыми
                                oimgoth=document.getElementById(prefiks+i);
                                oimgoth.className="starnull";
                        }

                        //если попалась звездочка на которую навели, то остальные не закрашиваем
                        if (sel_star_id==prefiks+i) { zakrasit=0; }
        }
}

//делаем звездочки все пустыми
function sel_stars_null(prefiks)
{
        for (i=0; i<5; i++)
        {
                oimgoth=document.getElementById(prefiks+i);
                oimgoth.className="starnull";
        }
}

var Download = {

    start: function(){

        if(!$('tHead')) return false;
        Download.trs = $$('tr.cL');
		Download.chks = $$('tr.cL input');
        Download.bgColor = $('tHead').getStyle('background-color');

        Download.fx = [];
        Download.parse();

        if($('chkAll'))
            $('chkAll').addEvent('click', function(){                if(!$('chkAll').checked) Download.none();
                else Download.all();
        });

    },

    select: function(chk){
        chk.checked = 'checked';
        Download.fx[chk.index].start({
            'background-color': '#DEE0AB',
            'color': '#000'
        });
        chk.addClass('selected');
    },

    all: function(){
        Download.chks.each(function(chk){
			Download.select(chk);
		});
	},

	none: function(){
		Download.chks.each(function(chk){
			Download.deselect(chk);
		});
	},

	deselect: function(chk){
		chk.checked = false;
		Download.fx[chk.index].start({
			'background-color': '#FFFFFF'
//			'color': '#000000'
		});
		chk.removeClass('selected');
	},

	parse: function(){
		Download.trs.each(function(tr, n){
			Download.fx[n] = new Fx.Morph(tr, {wait: false, duration: 100});

			var chk = tr.getElement('input');

			chk.index = n;

			tr.addEvent('click', function(){
				if (!chk.hasClass('selected')) Download.select(chk);
				else Download.deselect(chk);
			});

			tr.addEvent('mouseenter', function(){				if (!chk.hasClass('selected')){					Download.fx[n].start({
						'background-color': '#efefef'
//						'color': '#FFFFFF'
					});
					tr.addClass('over');
				}
			});

			tr.addEvent('mouseleave', function(){				if (!chk.hasClass('selected')){
					Download.fx[n].start({
						'background-color': '#FFF'
//						'color': '#000000'
					});
					tr.removeClass('over');
				}
			});

		});
	}

};


addEvent('domready', function(){        if($('addFavLink') && $('addFav'))
            $('addFavLink').addEvent('click', function(e){
                new Event(e).stop();
                var log = $('log_res').empty().addClass('ajax-loading');
                var myHTMLRequest = new Request.HTML({
                	url: '/profile.php',
                	update: $('log_res'),
                    onComplete: function() {
                        log.removeClass('ajax-loading');
                        if(Download.chks) Download.chks.each(function(chk){
                            if(chk.checked){
                                chk.checked = false;
                                chk.destroy();
                            }
                        });
                    }
                }).post($('addFav'));
        });

        if($('pagination'))
            $('pagination').addEvent('change', function(e){                $('pagination').form.submit();            });

        Download.start();
});

