NahaaTable = newClass(Table,{
	constructor: function() {
	    this.constructor.prototype.constructor.call(this);
	}
});


NahaaTable.prototype.denyOperation = function() {
    $('#popupContainer').css('opacity',0.5);
    $('#popupContainer').css('display','block');
    $('#globalThrobber').css('display','block');
};

NahaaTable.prototype.allowOperation = function() {
    $('#globalThrobber').css('display','none');
    $('#popupContainer').css('display','none');
};

function sort_sign(val) {
    if(val == 'asc')
        return '<img src="/images/i/arrow_up.png" height="12" />';
    if(val == 'desc')
        return '<img src="/images/i/arrow_dn.png" height="12" />';
    return val;
}

NahaaTable.prototype.getNavigator = function() {
    tableObj = this;
    return feed.items.length ?
    tr({},td({'colspan':100,'align':'left','class':'navBlock'},
	     function() {
		 var code =
		 a({'id':tableObj.expandName('','navPrevDup'),'href':'#'},
		   img({'src':'/images/jquery.tablesorter.pager/prev.png','border': 0,'align':'absmiddle'})) + '&nbsp;' +
		     input({
			     'type': 'text',
			     'id': tableObj.expandName('','moveToPage'),
			     'value': tableObj.getCurrent(),
			     'size': 5,
			     'style': 'text-align: right; padding-right: 2px;'
			 }) + '&nbsp;' +
		     a({'id':tableObj.expandName('','navNextDup'),'href':'#'},
		       img({'src':'/images/jquery.tablesorter.pager/next.png','border': 0,'align':'absmiddle'})) +
		     '&nbsp;|&nbsp;';
		 
		 code += span({'class':'pageLink'},
			      a(tableObj.getCurrent() != tableObj.getFirstPage() ? {'href':'#','id':tableObj.expandName('','navFirst')}:{}, tableObj.getFirstPage())) + '&nbsp;';
		 
		 if(tableObj.getCurrent() - tableObj.getFirstPage() > 2) {
		     code += '...&nbsp;';
		 }
		 if(tableObj.getCurrent() - tableObj.getFirstPage() > 1) {
		     code += span({'class':'pageLink'},
				  a({'id':tableObj.expandName('','navPrev'),'href' : '#'},tableObj.getCurrent() - 1)) + '&nbsp;';
		 }
		 
		 if(tableObj.getCurrent() != tableObj.getFirstPage() && tableObj.getCurrent() != tableObj.getLastPage())
		     code += span({'id':tableObj.expandName('','curPage'), 'class':'pageLink currentPage'},tableObj.getCurrent()) + '&nbsp;';
		 
		 if(tableObj.getLastPage() - tableObj.getCurrent() > 1) {
		     code += span({'class':'pageLink'},
				  a({'id':tableObj.expandName('','navNext'),'href' : '#'},tableObj.getCurrent() + 1)) + '&nbsp;';
		 }
		 
		 if(tableObj.getLastPage() - tableObj.getCurrent() > 2) {
		     code += '...&nbsp;';
		 }
		 
		 if(tableObj.getLastPage() != tableObj.getFirstPage())
		     code += span({'class':'pageLink'},
				  a(tableObj.getCurrent() != tableObj.getLastPage() ? {'href':'#', 'id': tableObj.expandName('','navLast')} : {}, tableObj.getLastPage()));
		 
		 code += '|&nbsp;' + span({'class':'onPageSelector'},"Показывать по ",
					  select({'id':tableObj.expandName('','navOnPage')},
						 option(tableObj.getOnPage() == 10 ? {'selected': null,'value': 10} : {'value': 10}, 10),
						 option(tableObj.getOnPage() == 20 ? {'selected': null,'value': 20} : {'value': 20}, 20),
						 option(tableObj.getOnPage() == 50 ? {'selected': null,'value': 50} : {'value': 50}, 50),
						 option(tableObj.getOnPage() == 100 ? {'selected': null,'value': 100} : {'value': 100}, 100)));
		 return code;
	     }
	     )) : '';		 
};

NahaaTable.prototype.postBuildInit = function(sorts) {
    var tableObj = this;
    $(this.expandName('#','navPrev') + ',' + this.expandName('#','navPrevDup')).click(function() {
	    tableObj.setSourceOption_prevPage();
	    return false;
	});
    
    $(this.expandName('#','navNext') + ',' + this.expandName('#','navNextDup')).click(function() {
	    tableObj.setSourceOption_nextPage();
	    return false;
	});
    
    $(this.expandName('#','navFirst')).click(function() {
	    tableObj.setSourceOption_setPage(tableObj.getFirstPage());
	    return false;
	});
    
    $(this.expandName('#','navLast')).click(function() {
	    tableObj.setSourceOption_setPage(tableObj.getLastPage());
	    return false;
	});
    
    $(this.expandName('#','navOnPage')).change(function() {
	    tableObj.setSourceOption_onPage(parseInt(this.options[this.selectedIndex].value));
	    return false;
	});
    
    for(var i = 0; i < sorts.length ; i++) {
	$(this.expandName('#','sort__' + sorts[i])).click(function() {
		tableObj.setSourceOption_switchSort(this.id);
		return false;
	    });
    }
        
    $(this.expandName('#','moveToPage')).keypress(function(e) {
	    var ENTER_KEY = 13;
	    var code = "";
	    if (window.event) // IE
		code = e.keyCode;
	    else if (e.which) // Netscape/Firefox/Opera
		code = e.which;
	    
	    if (code == ENTER_KEY) {
		tableObj.setSourceOption_setPage(parseInt(this.value));
		return false;
	    }
	    
	    return true;
	});

}