var future = new Array();
var today = new Array();
var ongoing = new Array();
var past = new Array();
var maxFuture = 5;
var maxPast = 0;
var futureStart = 100000;
var futureEnd = 0;

var pointA;
var pointAp;
var pointD;
var pointDp;

var add = 5;

$(document).ready(function(){
	//alert('ww');
	countEvents();
	initialDisplay();
	//moreFuture(5);
});
	

function countEvents(){
	$(".events li").each(function(i){
		if ($(this).hasClass("future")){
			future.push(this.id);
			//alert(future.length);
		}
		if ($(this).hasClass("today")){
			today.push(this.id);
			//alert(today);
		}
		if ($(this).hasClass("ongoing")){
			ongoing.push(this.id);
			//alert(ongoing);
		}
		if ($(this).hasClass("past")){
			past.push(this.id);
			//alert(past);
		}
	});
	//alert('future.length '+future.length);
	//alert('today.length '+today.length);
	//alert('ongoing.length '+ongoing.length);
	//alert('past.length '+past.length);
}

function initialDisplay(){
	
	//knowledge
	var counter = 0;
	$("li.future").each(function(){
		//alert($(this).attr('id'));
		if($(this).attr('id')<futureStart){
			futureStart = $(this).attr('id');
		}
		if($(this).attr('id')<=future.length){
			counter = $(this).attr('id');
		}
	});
	//alert('futureStart: '+(futureStart-1));
	futureEnd = (futureStart-1+maxFuture);
	//alert('futureEnd: '+futureEnd);
	pointA = counter;

	//alert('maxFuture '+maxFuture);
	//alert('future.length '+future.length);
	pointAp = 3;
	
	var counter = 100000;
	$("li.past").each(function(){
		if($(this).attr('id') < counter){
			counter = $(this).attr('id');
		}
	});
	
	pointD = counter;
	//alert('pointD '+pointD);
	
	pointDp = parseFloat(counter)+parseFloat(maxPast);
	//alert('pointDp '+pointDp);	
	
	//action
	$("li.future").each(function(){
		if($(this).attr('id') > futureEnd){
			$(this).hide();
		}
	});
	
	$("li.past").each(function(){
		if($(this).attr('id') >= pointDp){
			$(this).hide();
		}
	});
}


function moreFuture(){

	//alert('more future was just clicked');
	futureEnd += add;
	//alert(futureEnd);
	$("li.future").each(function(){
		$(this).show();
		if($(this).attr('id') > futureEnd){
			$(this).hide();
		}
	});
}

function resetFuture(){
	//alert(futureEnd);
	futureEnd = (futureStart-1+maxFuture);
	
	$("li.future").each(function(){
		$(this).show();
		if($(this).attr('id') > futureEnd){
			$(this).hide();
		}
	});
}


function morePast(add){
	
	//alert('more past was just clicked');
	/*
	pointAp += add;
	$("li.future").each(function(){
		$(this).show();
		if($(this).attr('id') > pointAp){
			$(this).hide();
		}
	});
	*/
	//alert('this button will work soon.');
}

function overEvent(thisEvent){
	$("li").each(function(){
		if($(this).attr('id') == thisEvent){
			if($(this).find("div.event_description").is(':visible')){
				//alert('dd');
			}
			else{
				$(this).css({'background-color' : '#00AFDB	'});
			}
		}
	});
}

function outEvent(thisEvent){
	$("li").each(function(){
		if($(this).attr('id') == thisEvent){
			$(this).css({'background-color' : '#ccc'});
		}
	});
}

function toggleEvent(thisEvent){
	
	//alert(thisEvent);
	
	$("li").each(function(){
		if($(this).attr('id') == thisEvent){
			$(this).css({'background-color' : '#ccc'});
			$(this).find("div.event_description").toggle();
		}
		if($(this).attr('id') != thisEvent){
			$(this).css({'background-color' : '#ccc'});
			$(this).find("div.event_description").hide();
		}
	});
}




























/* ELEPHANT GRAVEYARD

$(".list_button").click(function(){
	alert('ha!');
	$(".events li").each(function(i){
		show();
	});
	manageEvents();
});


	from the top of moreFuture and morePast:
	//knowledge
	var counter = 0;
	$("li.future").each(function(){
		if($(this).attr('id')<=future.length){
			counter = $(this).attr('id');
		}
	});
	var pointA = counter;
	//alert('pointA '+pointA);
	var pointAp = parseFloat(counter)-parseFloat(maxFuture);
	//alert('pointAp '+pointAp);
	
	var counter = 100000;
	$("li.past").each(function(){
		if($(this).attr('id') < counter){
			counter = $(this).attr('id');
		}
	});
	
	var pointD = counter;
	//alert('pointD '+pointD);
	
	var pointDp = parseFloat(counter)+parseFloat(maxPast);
	//alert('pointDp '+pointDp);	
	
	//action
	$("li.future").each(function(){
		if($(this).attr('id') <= pointAp){
			$(this).hide();
		}
	});
	
	$("li.past").each(function(){
		if($(this).attr('id') > pointDp){
			$(this).hide();
		}
	});




function manageEvents(a,b){
	var i=1;

	for(i in future){
		s = parseInt(i)+parseInt(future[0]);
		cut = a-parseInt(future[0]);
		//alert(s);
		if (s <= cut){
			$(".events #"+s).hide();
		}
	}
	
	for(i in past){
		//alert(parseInt(past[0]));
		s = parseInt(i)+parseInt(past[0]);
		cut = b+parseInt(past[0]);
		//alert(s);
		if (s >= cut){
			$(".events #"+s).hide();
		}
	}
}

*/
