// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults


// --------------  TOP5RECS UPDATING BY TIMER  ------------------------
//
var rec_update_timer_running = false;
var rec_update_timer_ID = null;
function rec_update_timer_start(period) {
	rec_update_timer_stop();
	rec_update_timer_ID = self.setTimeout("rec_update_timer_finish()", period); 
	rec_update_timer_running = true;
}
function rec_update_timer_stop() {
	if(rec_update_timer_running)  
	clearTimeout(rec_update_timer_ID);      
	rec_update_timer_ID = null; 
	rec_update_timer_running = false;
}
function rec_update_timer_finish() {
	rec_update_timer_stop();
	new Ajax.Request('/home/update_top5_recs', {  
		method: 'post' 
	});  
}

// --------------  CATEGORIES UPDATING BY TIMER  ------------------------
//
var categories_update_timer_running = false;
var categories_update_timer_ID = null;
var category_more = '';
var time_span = 'today';
var page = '0';
function categories_update_timer_start(period, category_more_param, page_param, time_span_param) {
	categories_update_timer_stop();
	time_span = time_span_param;
	category_more=category_more_param;
	page=page_param;
	categories_update_timer_ID = self.setTimeout("categories_update_timer_finish()", period); 
	categories_update_timer_running = true;
}
function categories_update_timer_stop() {
	if(categories_update_timer_running)  
	clearTimeout(categories_update_timer_ID);      
	categories_update_timer_ID = null; 
	categories_update_timer_running = false;
}
function categories_update_timer_finish() {
	categories_update_timer_stop();
	//location.reload(true);  // refresh the whole page
	var url = '/home/update_categories?category_more=' + category_more + '&time_span=' + time_span + '&page=' + page;	
	new Ajax.Request(url, {  
		method: 'post' 
	});  
}


// --------------  PROTOTIP TOOLTIPS  ------------------------
// 
// This function will add tooltips to all Lyteframe links. 
// The content of the tips are read from the html page, from a span with id of this kind: 'ttxxxx'
function create_tooltips() {
	$$('a[rel="lyteframe"]').each(function(element) {
		if (element.id != "") {
  			var a = 't' + element.id;
			if ($(a)) {
  	    		new Tip(element, $(a).innerHTML, { style: 'top5_wl'});
			}
		};
	});
}


// --------------  GENRERIC HELPERS  ------------------------
//
function javascript_hello(){
	alert("Hello from javascript");
}




