$(document).ready(
    function()
    {
        $('textarea').charCounter(250,{container:'#char_count'});
        $('.get_tablers').click(
            function()
            {
                //green the others first
                $('.get_tablers').each(
                    function()
                    {

                        if($(this).is('.selected'))
                        {

                            $(this).parent().removeClass('type_oren');
                            $(this).parent().addClass('type_green');
                            $(this).parent().removeClass('selected');
                            $(this).parents('.a_tab').find('img').each(
                                function()
                                {
                                    $(this).attr('src',$(this).attr('src').replace('oren','green'));
                                }
                            );

                        }


                    }
                );

                $(this).parent().removeClass('type_green');
                $(this).parent().addClass('type_oren');
                $(this).addClass('selected');
                $(this).parents('.a_tab').find('img').each(
                    function()
                    {
                        $(this).attr('src',$(this).attr('src').replace('green','oren'));
                    }
                );
            }
        );
        $('.pagination').click(
            function()
            {
                var type='';
                if ($(this).is('.bb'))
                {
                    type='bb';
                }
                else if ($(this).is('.cr'))
                {
                    type='cr';
                }
                var total=$('#total_'+type).val();
                //tries to get page
                var iframe=$('#iframe_'+type);
                var src=iframe.attr('src').split('/');

                page=(src[src.length-1]);

                //now we got page, type,total
                if ($(this).is('.left'))page--;
                else page++;
                $.log('total:'+total);
                $.log('page:'+page);
                if (page<0 || page>total)return false;
                var pagination=$('.pagination').filter('.'+type);
                if (page>=total)
                {
                    pagination.filter('.left').show();
                    pagination.filter('.right').hide();
                }
                else if (page==1)
                {

                    pagination.filter('.left').hide();
                    pagination.filter('.right').show();
                }
                else
                {
                    pagination.filter('.left').show();
                    pagination.filter('.right').show();
                }

                src[src.length-1]=page;
                iframe.attr('src',src.join('/'));
                return false;
            }
        );
    }

)