/*
*
* functionailty for paginating ajax results
*
* @author  Kai Price <pricek@soe.sega.co.uk>
* @date    31 July 2008
*
*/

//globals that will be used through out this function
var params, fn;

/**
* displays the pagination arrows depeding on whether there are results to move to
*
* @param    int         starting point of the resultset that has been returned
* @param    int         maximum number of results that are to be returned
* @param    int         total numebr of results that are to be returned
* @param    string[]    all of the params that will need to be passed into the function call
* @param    string      name of the function that is being called
*
**/
function paginate(start, limit, count, params_ar, functionname){
    fn     = functionname;
    params = '(';
    start  = parseInt(start);
    limit  = parseInt(limit);
    count  = parseInt(count);

    if((start-limit)>=0){//if there are screenshots further down the order
        document.getElementById("pag_previous").style.display = 'block';

        //loop through the params_ar and put the values into a string
        for (var i in params_ar){
            switch(i){
                case 'start':
                    params += "'" + (start-limit) + "',";
                    //start it a special case because we want to change the start
                    //value
                break;
                default:
                    params += "'" + params_ar[i] + "',";
                break;
            }
        }
        params = params.substr(0,params.length-1) + ');';
        document.getElementById("pag_prev_click").onclick = Function(fn + params);//set the onclick
    }else{//this button should not be seen
        document.getElementById("pag_previous").style.display = 'none';
    }

    params ='(';
    if((start+limit)<count){//if there are images left to move onto
        document.getElementById("pag_next").style.display = 'block';
        //document.getElementById("pag_next_click").onclick = Function(fn + "()");

        //loop through the params_ar and put the values into a string
        for (var i in params_ar){
            switch(i){
                case 'start':
                    params += "'" + (start+limit) + "',";
                    //start it a special case because we want to change the start
                    //value
                break;
                default:
                    params += "'" + params_ar[i] + "',";
                break;
            }
        }
        params = params.substr(0,params.length-1) + ');';
        //alert(params.substr(0,params.length-1) + ');');
        document.getElementById("pag_next_click").onclick = Function(fn + params);//set the onclick
    }else{//this button should not be seen
        document.getElementById("pag_next").style.display = 'none';
    }
}
