 var objList = new Array();

     function init_gal(objname, opt, bindto, dopt, objds)

    {

        objList[objname] = new Array();
        
        if (objds) {
                objList[objname]['dataS'] = objds;
        }else{
                objList[objname]['dataS'] = new DataSetHolder(dopt);
        }
        objList[objname]['dataS'].addListener("onDataError", catchErr);



	objList[objname]['theGrid'] = new GridWindow(objname,'theGrid',opt);

	objList[objname]['theGrid'].onDataChange = 

	  function(objEvt) {

		switch(objEvt.dEvType)

		{

			case "update":



				var hasElems = this.dataSource._dset.detect(

					function( item, index ) {

						return item;

					}

				);



				alert( "---" + hasElems );

				

				if ( !hasElems && this.opt.emptyMessage ) {

					$( objname ).innerHTML = this.opt.emptyMessage;

				}

			

				if(objEvt.from >= this._firstRecord && objEvt.from < (this._firstRecord+_totCells))

				{

					var dset = this.dataSource.getItemAt(objEvt.from);

					var rIndex = objEvt.from-this._firstRecord;

					this.options.renderingFunction(dset, this._cells[rIndex], objEvt.from);

				}

				break;

			default:

				

				if (this.dataSource.getLength() < this._totCells ) {

					$("p_previous_" + objname).style.display = 'none';

					$("p_next_" + objname).style.display = 'none';

				}



				this.draw();



				var hasElems = this.dataSource._dset.detect(

					function( item, index ) {

						return item;

					}

				);



				if ( !hasElems && opt.emptyMessage ) {

					$( objname ).innerHTML = opt.emptyMessage;

				}

				break;

		}

	  };

	objList[objname]['theGrid'].create();

	objList[objname]['theGrid'].bindDataSource(objList[objname]['dataS']);

        objList[objname]['offset'] = 0;

        objList[objname]['theGrid'].setOffset(0, true);



	//      theGrid.draw();
        if (!objds){
        objList[objname]['dataS'].bindTo(

            bindto.url , 

            bindto.parameters || "",

            bindto.method 

        );
        }else{
        objList[objname]['theGrid'].draw();
        }

    }

    

    function next_item(objname)

    {

    	objList[objname]['offset'] += objList[objname]['theGrid']._totCells;

        objList[objname]['offset'] = objList[objname]['theGrid'].setOffset(objList[objname]['offset'], true);

	//alert(objList[objname]['offset'])

        objList[objname]['theGrid'].draw();

	$('p_previous_'+objname).style.display='inline';

	if ( objList[objname]['offset'] + objList[objname]['theGrid']._totCells 

	     >= objList[objname]['dataS'].getLength() ) {

		     

		$('p_next_'+objname).style.display='none';

	}

	

	//if ( (objList[objname]['dataS'].getLength() - objList[objname]['offset']) 

	//     - objList[objname]['theGrid']._totCells == 0 ){	     

	//	$('p_next_'+objname).style.display='none';

	//}

    }



    function prev_item(objname)

    {

    	objList[objname]['offset'] -= objList[objname]['theGrid']._totCells;

        objList[objname]['offset'] = objList[objname]['theGrid'].setOffset(objList[objname]['offset'], false);

        objList[objname]['theGrid'].draw();

	

	if (objList[objname]['offset'] == 0){

	$('p_previous_'+objname).style.display='none';

	}

	// alert("totale: "+objList[objname]['dataS'].getLength()+"offset: "+objList[objname]['offset']+" "+objList[objname]['theGrid']._totCells)

	if ( (objList[objname]['offset'] + objList[objname]['theGrid']._totCells ) 

		<= objList[objname]['dataS'].getLength() ){

			

			$('p_next_'+objname).style.display='inline';

	}

    }

