
function Navigation() {

	var nav = new Object();
	
	nav.sHtml = '';
	nav.oParameters = new Object();
				
	nav.iJsFunction = 1; 		//liczba rekord?w na stronie
	nav.iPageCount = 0; 		//liczba rekord?w na stronie
	nav.iAllCount = 0; 	  		//liczba wszystkich rekord?w
	nav.iAllPages = 0;   	  	//liczba wszystkich stron
	nav.iNumPage = 0;       	//numer biez?cej strony
	nav.sParamPage = '';		// nazwa parametru strony
	nav.sLeft  = '<span class="left">&nbsp;</span>'; 	//strzalki w lewo
	nav.sRight = '<span class="right">&nbsp;</span>'; 	//strzalki w prawo
	nav.iLpp = 4;
	nav.sScriptName = 'getPage';  //nazwa skryptu do ktorego maja byc generowane linki
	nav.sExtraParam = ''; 					//dodatakowe parametry jakie maja byc obecne w linku
	nav.sNavType = 'static' //static or ajax

	
	nav.sBetween = '<span>...</span>';
	nav.sCssLeftRight = 'class="leftright"'; //dodawane jako styl do link?w lewej i prawej strza?ki
	nav.sCssSelected = 'class="selected"';
	

	/** Ustawia paramteray **/
	nav.handleArguments = function(args) {
		for (var i in args) {
			if (typeof(nav[i]) == "undefined") {
				nav.oParameters[i] = args[i];
			}
			else {
				nav[i] = args[i];
			}
		}
	};
	
	
	/** Ustawia link z paramterami i opcja wywolania funckji **/
	nav.setLink = function(iPage) {

		var sLink = '';

		if(iPage != '') {
			if(this.sParamPage != ''){
				sLink += this.sParamPage + '=' + iPage;
			}
			else{
				sLink += iPage;
			}
		}
		
		if(this.sExtraParam != ''){
			sLink += this.sNavType=='static' ? '&' + this.sExtraParam : ',' + this.sExtraParam;
		}
		
			
		if(this.iJsFunction == 1){
			sLink = 'javascript:' + this.sScriptName + '(' + sLink + ')';
		}
		else{
			sLink = this.sScriptName + sLink;
		}
			
		return sLink;
	}

	
   /*
    Wyswietlenie belki nawigacyjnej do stronicowania
   */
  	nav.makeHTML = function(){

		this.sHtml = '';
	
		if (!this.iPageCount) {
	  		this.iPageCount = 25;
  		}
		
		this.iAllPages = Math.floor(this.iAllCount/this.iPageCount);

		if (this.iAllCount % this.iPageCount) {
			this.iAllPages++;
 		}
			
		if (this.iAllPages > 1) {

			
			var tmp = 0;
	  
	    	if (this.iNumPage >= this.iAllPages - this.iLpp) {
        		max = this.iAllPages;
        		tmp = this.iLpp + 1 - (this.iAllPages - this.iNumPage);
		    }
			else {
				max = this.iNumPage + this.iLpp + 1;
		    }
	  
		  	if (this.iNumPage <= this.iLpp) {
      			min = 1;
		  		max += this.iLpp - this.iNumPage + 1;
				if (max > this.iAllPages) {
    	    		max = this.iAllPages;
    			}
			}
			else {
		    	//min = this.iNumPage - this.iLpp;
				min = this.iLpp;
		    }
		
			min -= tmp;

      		if (min < 1){
	  			min = 1;
			}
			
			// strzalka w lewo
		    if (this.iNumPage > 1){
    	  		this.sHtml += '<a href="'+this.setLink(this.iNumPage-1)+'" '+this.sCssLeftRight+'>'+this.sLeft+'</a>';
			}
			
			// linki do stron
			for (i=min;i<max;i++) {
				if (i == this.iNumPage) {
            		this.sHtml += '<span '+this.sCssSelected+'>'+i+'</span>';
				}
				else {
    	          this.sHtml += '<a href="'+this.setLink(i)+'">'+i+'</a>';
				}
	     	}

			if(this.iAllPages < 4){
				this.sBetween = '';
			}
			

			//ostatnia strona
			if (this.iNumPage == this.iAllPages) {
				this.sHtml += this.sBetween+'<span class="selected">'+this.iAllPages+'</span>';
			}
			else {
				this.sHtml += this.sBetween+'<a href="'+this.setLink(this.iAllPages)+'">'+this.iAllPages+'</a>';
			}

			//strzalka w prawo
			if (this.iNumPage < this.iAllPages) {
				this.sHtml += '<a href="'+this.setLink(this.iAllPages)+'" '+this.sCssLeftRight+'>'+this.sRight+'</a>';
			}

			this.sHtml += '&nbsp;';

		}
		else{
			this.sHtml = '';
		}
	}
	
	return nav;
}


Navigation.get = function(args) {
	var nav = Navigation.setParam(args);
	return nav;
};


Navigation.setParam = function(args) {
	if (typeof(args) != "undefined" && args != null) {
		var myNav = new Navigation();
		myNav.handleArguments(args);
		return myNav;
	}
};

