var hotnewsID = 0;
var hotnewsCurrentID = 0;
var hotnewsTimeOutID;
var maxheight = 0;

function getHotNews(){
	
	$('HOTNEWS').innerHTML = '<center><img src="images/loading.gif" /></center>';
	sendRequest('hotnews.php', delegate_hotnews)
}

function delegate_hotnews(originalRequest){
	
	var html = originalRequest.responseText;
	$('HOTNEWS').innerHTML = html;
	
	setTimeout("hotnews_maxheight()", 500);
	
	var obj = $('hotnews_0');
	
	if(obj != null){
		
		obj.style.display = "";
	}
	
	hotnewsCurrentID = 0;
	hotnewsID = 1;
	hotnews_start();
}

function hotnews_maxheight(){
	
	for(var i=0; ;i++){
		
		var obj = $('hotnews_'+i);
		
		if(obj == null) break;
		
		if(obj.offsetHeight > maxheight){
			
			maxheight = obj.offsetHeight;
		}
		
		obj.style.display = 'none';
	}
	
	$('HOTNEWS').height = maxheight + 10;
}

function hotnews_start(){
	
	hotnewsTimeOutID = setTimeout("hotnews_navi(true)", 2000);
}

function hotnews_stop(){
	
	clearTimeout(hotnewsTimeOutID);
}

function hotnews_next(){
	
	hotnews_navi(false);
}

function hotnews_back(){
	
	hotnewsID = Math.max(0, hotnewsID-2);
	
	if(hotnewsID != hotnewsCurrentID){
		
		hotnews_navi(false);
	}else{
		
		hotnewsID = 1;
	}
}

function hotnews_navi(loop){
	
	var obj = $('hotnews_'+hotnewsID);
	
	if(obj != null){
		
		obj.style.display = "";
				
		obj = $('hotnews_'+hotnewsCurrentID);
		if(obj != null) obj.style.display = "none";
		
		hotnewsCurrentID = hotnewsID;
		
		hotnewsID += 1;
	}else{
		
		obj = $('hotnews_0');
		if(obj != null){
			
			obj.style.display = "";
		}

		if(hotnewsCurrentID != 0){
			
			obj = $('hotnews_'+hotnewsCurrentID);
			if(obj != null) obj.style.display = "none";
		}
		
		hotnewsCurrentID = 0;
		hotnewsID = 1;
	}
	
	if(loop)
	hotnews_start();
}