var CRate = {
    init: function()
    {
        $('.rates .rbox').each( function()
        {
            var pPlus = $(this).find('div.rateup');
            var pMinus = $(this).find('div.ratedown');

            if(pPlus)
            {
                pPlus.click(function() {
                    //alert($(this).attr('rel'));
                    if($(this).attr('rel') != '')
                    {
                        if($(this).attr('rel') == 'no')
                        {
                            CFacebook.login(true);
                        }
                        else
                        {
                            $.ajax({
                                cache: false,
                                url:$(this).attr('rel'),
                                success: function(data)
                                {
                                    if(data != '')
                                    {
                                        // alert(data);
                                    }
                                }
                            });

                            var nPlus = $(this).parent().find('.rvalue').html();
                            nPlus = parseInt(nPlus);
                            nPlus++;
                            $(this).parent().find('.rvalue').html(nPlus);
                            $(this).attr('rel','');
                            $(this).unbind('mouseover mouseout mousedown mouseup');
                            $(this).css('background-position','0px -100px');

                            var pCurrentDown = $(this).parent().parent().find('.rbox .ratedown');
                            pCurrentDown.unbind('mouseover mouseout mousedown mouseup');
                            pCurrentDown.attr('rel','');
                            pCurrentDown.css('background-position','0px 0px');
                        }
                    }
                });
                
                if(pPlus.attr('rel') != '')
                {
                    pPlus.mouseover(function(){$(this).css('background-position','0px -150px');}); 
                    pPlus.mouseout(function(){$(this).css('background-position','0px -125px');});
                    pPlus.mousedown(function(){$(this).css('background-position','0px -175px');});
                    pPlus.mouseup(function(){$(this).css('background-position','0px -125px');});
                }
            }

            if(pMinus)
            {
                pMinus.click(function() {
                    //alert($(this).attr('rel'));
                    if($(this).attr('rel') != '')
                    {
                        if($(this).attr('rel') == 'no')
                        {
                            CFacebook.login(true);
                        }
                        else
                        {
                            $.ajax({
                                cache: false,
                                url:$(this).attr('rel'),
                                success: function(data)
                                {
                                    if(data != '')
                                    {
                                        // alert(data);
                                    }
                                }
                            });

                            var nMinus = $(this).parent().find('.rvalue').html();
                            nMinus = parseInt(nMinus);
                            nMinus++;
                            $(this).parent().find('.rvalue').html(nMinus);
                            $(this).attr('rel','');
                            $(this).unbind('mouseover mouseout mousedown mouseup');
                            $(this).css('background-position','0px 0px');

                            var pCurrentUp = $(this).parent().parent().find('.rbox div.rateup');
                            pCurrentUp.unbind('mouseover mouseout mousedown mouseup');
                            pCurrentUp.attr('rel','');
                            pCurrentUp.css('background-position','0px -100px');
                        }
                    }
                });

                if(pMinus.attr('rel') != '')
                {
                    pMinus.mouseover(function(){$(this).css('background-position','0px -50px');}); 
                    pMinus.mouseout(function(){$(this).css('background-position','0px -25px');});
                    pMinus.mousedown(function(){$(this).css('background-position','0px -75px');});
                    pMinus.mouseup(function(){$(this).css('background-position','0px -25px');});
                }
            }
        });
    }
};
