/* Sidebar Listing Widget */

var fd_list_type = 'ratings';
var fd_list_time = 'ever';
var fd_list_section = 0;
var fd_list_offset = 0;
var fd_list_count = 9;

function fd_hot_list(offset) {
	offset = typeof(offset) != 'undefined' ? offset : 0;
	fd_list_offset += offset;
	$('hot_ratings').className = ''; $('hot_hits').className = ''; $('hot_'+fd_list_type).className = 'active';
	$('hot_day').className = ''; $('hot_week').className = ''; $('hot_month').className = ''; $('hot_ever').className = '';
	$('hot_'+fd_list_time).className = 'active';
	new Ajax.Updater($('hot_list'),
	'http://www.innocentenglish.com/wp/wp-content/plugins/hot-pages/hot-pages-widget-ajax.php',
	 {method:'post', postBody: 'fd_list_type='+fd_list_type+'&fd_list_time='+fd_list_time+'&fd_list_section='+fd_list_section+'&fd_list_offset='+fd_list_offset+'&fd_list_count='+fd_list_count}
	);
}

Event.observe(window, 'load', function() {

	Event.observe($('hot_ratings'), 'click', function() { fd_list_offset = 0; fd_list_type = 'ratings'; fd_hot_list(); return false; });
	Event.observe($('hot_hits'), 'click', function() { fd_list_offset = 0;  fd_list_type = 'hits'; fd_hot_list(); return false; });
	
	Event.observe($('hot_day'), 'click', function() { fd_list_offset = 0;  fd_list_time = 'day'; fd_hot_list(); return false; });
	Event.observe($('hot_week'), 'click', function() { fd_list_offset = 0;  fd_list_time = 'week'; fd_hot_list(); return false; });
	Event.observe($('hot_month'), 'click', function() { fd_list_offset = 0;  fd_list_time = 'month'; fd_hot_list(); return false; });
	Event.observe($('hot_ever'), 'click', function() { fd_list_offset = 0;  fd_list_time = 'ever'; fd_hot_list(); return false; });
	
	Event.observe($('hot_list_cat'), 'change', function() { fd_list_offset = 0;  fd_list_section = $('hot_list_cat').value; fd_hot_list() });
	
	//Event.observe($('hot_next'), 'click', function() { fd_list_offset += 8; fd_hot_list(); return false; });
});

/* 
Rater Widget
*/
var hasClicked = false;
Event.observe(window, 'load', function() {
	
	$$('.fd_hot_rater').each( function(rater) {
		pid = rater.id.split('_'); pid = pid[1];
		Event.observe($('star_0'), 'mouseover', function() { fd_hot_mouseover(0); });
		Event.observe($('star_1'), 'mouseover', function() { fd_hot_mouseover(1); });
		Event.observe($('star_2'), 'mouseover', function() { fd_hot_mouseover(2); });
		Event.observe($('star_3'), 'mouseover', function() { fd_hot_mouseover(3); });
		
		for(i = 0; i < 4; i++) {
			Event.observe($('star_'+i), 'mouseout', function() { fd_hot_mouseout(); });
		}
		
		Event.observe($('star_0'), 'click', function() { fd_hot_click(0, pid); });
		Event.observe($('star_1'), 'click', function() { fd_hot_click(1, pid); });
		Event.observe($('star_2'), 'click', function() { fd_hot_click(2, pid); });
		Event.observe($('star_3'), 'click', function() { fd_hot_click(3, pid); });
	});
});

function fd_hot_mouseover(item_num) {
	if(hasClicked) return;
	for(i = 0; i <= item_num; i++) { $('star_'+i).setAttribute('src', 'http://www.innocentenglish.com/wp/wp-content/plugins/hot-pages/rating-over.gif'); }
}

function fd_hot_click(item_num, pid) {
	if(hasClicked) return; hasClicked = true;
	for(i = 0; i < 4; i++) { $('star_'+i).className = 'off'; }
	for(i = 0; i <= item_num; i++) { $('star_'+i).className = 'over'; }
	fd_hot_rate(pid, item_num + 1);
}

function fd_hot_rate(id, rating) {
	new Ajax.Updater('fd_rater_msg', 'http://www.innocentenglish.com/wp/wp-content/plugins/hot-pages/rating-ajax.php', {method:'post', postBody: 'id='+id+'&rating='+rating});
}

function fd_hot_mouseout() {
	for(k = 0; k < 4; k++) {
		$('star_'+k).setAttribute('src', 'http://www.innocentenglish.com/wp/wp-content/plugins/hot-pages/rating-'+$('star_'+k).className+'.gif');
	}
}