$.fn.extend({
	s_table_sort: function(){
	     var base = 0;
		 var headers = $(this).children().eq(0).children().eq(0).children();
		 var bodys = $(this).children().eq(1).children('tr');
         var thistable = $(this);
		 var len = bodys.size();
		 headers.each(function(i){
			$(this).click(function(){
			    headers.each(function(i_idx){
			        if (i_idx != i){
			             $(this).removeClass('headerSortUp');
			             $(this).removeClass('headerSortDown');
			        }
			    });
				var tmp_array = new Array();
				var ord = new Array();
				var isNumber = true;
				for (var idx = base; idx < len; idx++){
					tmp_array[idx] =  bodys.eq(idx).children().eq(i).text();
					if (isNaN(tmp_array[idx])){
					    isNumber = false;
					}
					ord[idx] = idx ;
				}			
                if ($(this).attr("class").indexOf('headerSortUp') != -1 ){
				        for (var max=len; max>0 ; max--){
							for (var j = base ; j<max - 1; j++ ){
							    var row_fr = bodys.eq(j);
								var row_af = bodys.eq(j+1);
								var column1 = tmp_array[j];
								var column2 = tmp_array[j+1];
								var check ;
								if (isNumber){
								    check = (column1 - column2) < 0? 1:-1;
								}else{
								    check = column2.localeCompare(column1);
								}
								if (check > 0){
									var tmp2 = tmp_array[j];
									tmp_array[j] = tmp_array[j+1];
									tmp_array[j+1] = tmp2;					
									var tmp3 = ord[j];
									ord[j] = ord[j+1];
									ord[j+1] = tmp3;
								}
							}
				        }
					$(this).removeClass("headerSortUp");
					$(this).addClass("headerSortDown");
                }else{
					 for (var max=len; max>0 ; max--){
						for (var j = base ; j<max - 1; j++ ){
							var row_fr = bodys.eq(j);
							var row_af = bodys.eq(j+1);
							var column1 = tmp_array[j];
							var column2 = tmp_array[j+1];
							var check;
							if (isNumber){
							    check = (column1 - column2) > 0? 1:-1;
							}else{
							    check = column1.localeCompare(column2);
							}
							if (check > 0){
								var tmp2 = tmp_array[j];
								tmp_array[j] = tmp_array[j+1];
								tmp_array[j+1] = tmp2;
								var tmp3 = ord[j];
								ord[j] = ord[j+1];
								ord[j+1] = tmp3;
							}
						}
					}
					$(this).removeClass("headerSortDown");
					$(this).addClass("headerSortUp");		
				}
				html = '';
				for (idx =base; idx < len; idx++){
					html += '<TR>' +  bodys.eq(ord[idx]).html() + '<TR/>';
				}
				thistable.children().eq(1).html(html);
			});
		 });
	}
})


var tID;
var tn;
var nStopTime=3000;
var nSpeed=50;
var isMove=true;
var nHeight=15;
var nS=0;
var nNewsCount=0;
function moveT(n)
{
	clearTimeout(tID);
	var noticev2= document.getElementById("noticev2");

	if(n){
		noticev2.style.lineHeight=nHeight+"px";
		var theText=noticev2.innerHTML.toLowerCase();
		nNewsCount=theText.split("<br>").length-1;
		noticev2.innerHTML+=""+noticev2.innerHTML;
		tn=nHeight;
	}

	nS=nSpeed;
	if(isMove){
		noticev2.style.marginTop=tn+"px";
		if((tn-2)%nHeight==0){
			nS=nSpeed+nStopTime;
		}
		tn--;
		if(Math.abs(tn)==(nNewsCount*nHeight*2-nHeight))
			tn=(nNewsCount-1)*nHeight*-1;
	}
	tID=setTimeout("moveT()",nS);
}
