var rambles_sort;
var next_page;
function GetTopRambles(id, pag){
	//use: most recent: onclick="javascript: GetTopRambles(1);"
	//use: 24 hrs: onclick="javascript: GetTopRambles(2);"
	//use: 7 days: onclick="javascript: GetTopRambles(3);"
	//use: 30 days: onclick="javascript: GetTopRambles(4);"
	//use: 365 days: onclick="javascript: GetTopRambles(5);"
	
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
	  alert ("Please install the newest version for your browser!");
	  return;
	} 
	
	if(id==null){
		return;
	}
	
	if(id < 1 || id > 5)
		return;
	
	if(pag == null)
		pag = 1;
		
	next_page = pag+1;	
	
	rambles_sort = id;
			
	var url="index.php?get_rambles=" + id + "&pag=" + pag;
	
	url=url+"&sid="+Math.random();
	
	document.getElementById("container").innerHTML = '<div style="padding-top: 150px"><img src="_layouts/images/load2.gif" border="0" /></div>';
	
	title = new Array();
	title[0] = '';
	title[1] = 'Most Recent';
	title[2] = '24 hrs';
	title[3] = '7 days';
	title[4] = '30 days';
	title[5] = '365 days';
	
	//highlight selected
	elem = eval("document.getElementById('div_0" + id + "')");
	elem.innerHTML = title[id];
	elem.setAttribute("class", "recent_0"+ id + "_selected");
	elem.setAttribute("className", "recent_0" + id + "_selected");
		
	title = new Array();
	title[0] = '';
	title[1] = '<a href="javascript: void(0);" onclick="GetTopRambles(1);" class="link_recent">Most Recent</a>';
	title[2] = '<a href="javascript: void(0);" onclick="GetTopRambles(2);" class="link_recent">24 hrs</a>';
	title[3] = '<a href="javascript: void(0);" onclick="GetTopRambles(3);" class="link_recent">7 days</a>';
	title[4] = '<a href="javascript: void(0);" onclick="GetTopRambles(4);" class="link_recent">30 days</a>';
	title[5] = '<a href="javascript: void(0);" onclick="GetTopRambles(5);" class="link_recent">365 days</a>';
	
	for(i = 1; i < 6; i++){
		if(i != id){
			//put links on menu items that are not selected
			elem = eval("document.getElementById('div_0" + i + "')");
			elem.innerHTML = title[i];
			//put class wothout background for non selected items
			elem.setAttribute("class", "recent_0" + i);
			elem.setAttribute("className", "recent_0" + i);
		}
	}
		
	xmlHttp.onreadystatechange=putTopRambles;
	
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
} 

function putTopRambles(){
	if (xmlHttp.readyState==4){
		response=xmlHttp.responseText;	
		
		sort = '';
		if(rambles_sort == 2)
			sort = '24hrs';
		else if(rambles_sort == 3)
			sort = '7days';
		else if(rambles_sort == 4)
			sort = '30days';
		else if(rambles_sort == 5)
			sort = '365days';			
		
		
		update = response.split("|||");
		
		//rss_button = '<div style="float: left; clear: both; padding-top: 10px"><a href="_layouts/rss/top_all.xml"><img src="_layouts/images/rss.gif" border="0" style="vertical-align: bottom" /></a></div>';
		
		view_all_button = '<div style="float: right"><a href="all/' + sort + '"><img src="_layouts/images/but_view_all.gif" onmouseover="this.src=\'_layouts/images/but_view_all_over.gif\'" onmouseout="this.src=\'_layouts/images/but_view_all.gif\'" border="0" /></a></div>';
		
		if(next_page == 2)
			prev_page = '';
		else{
			prev_page = next_page - 2;
			if(prev_page < 1)
				prev_page = '';
			else
				prev_page = '<a href="javascript: void(0);" onclick="javascript: GetTopRambles(' + rambles_sort + ',' + prev_page + ');"><img src="' + LAYOUTS + 'images/arrow_page_up.gif" border="0" align="bottom" /></a>';	
		}	
				
		if(update[1] == 1)
			next_page_button = '<div class="top_rambles_pagination"><a href="javascript: void(0);" onclick="javascript: GetTopRambles(' + rambles_sort + ',' + next_page + ');"><img src="' + LAYOUTS + 'images/arrow_page.gif" border="0" align="bottom" /></a> ' + prev_page + '</div>';
		else
			next_page_button = '<div class="top_rambles_pagination">' + prev_page + '</div>';
			
		document.getElementById("container").innerHTML = update[0] + next_page_button + view_all_button;
				
		$('.washlink').click(modal_div); 
		
		//tag rants as favorite
		$('.tag_favorite').click(addFavorite); 
		
	}
}

