// JavaScript Document
//global vars here
var current_date = "02-11-2007";//set by PHP
var global_traversal = 0;
var last_active = "";//we'll use this to removeClass on the active day
var last_article = 1;
var periodical;
var period = 10000;
var iteration = 0;
var last_iteration = 0;

function press(){
	return;
}

function fetch_event(date, traversal){
	//
	var orig_date = date;
	//alert("current date: " + current_date + " orig: " + orig_date);
	if(date.length>1){
	current_date = date;
	global_traversal = 0; //back to zero
	}else{
	global_traversal += traversal;
	date = current_date;
	}
	if(traversal==null){
	traversal = 0;	
	}
	
	var myJsDate = new Date();
	var myJsDateTomo = new Date();
	var splitDate = date.split('-');
	var year = splitDate[2];
	var month = splitDate[1] - 1;
	var day = splitDate[0];
	var testday = day/1 + global_traversal;
	//alert(testday);
	myJsDate.setFullYear(year, month, day);
	myJsDateTomo.setFullYear(year, month, testday);
	//myJsDateTomo.setDate(myJsDate.getDate() + global_traversal);//was traversal
	
	//alert(myJsDate + " - " + myTest);
	var d = myJsDateTomo.getDate();
	if(d<10){
		d = "0" + d;
	}
	
	var m = (myJsDateTomo.getMonth()+1);
	if(m<10){
		m = "0" + m;	
	}
	
	var hitDiv = d + "-" + m + "-" + myJsDateTomo.getFullYear();
	if($(orig_date)){
		
		hitDiv = orig_date;
	}
	//alert("hit: " + hitDiv);
	$$('.activate_me').removeClass('active_day');
	
	if($(hitDiv)){
	$(hitDiv).addClass('active_day');
	
	
	
	var url = "index.php?id=65&date=" + date + "&traversal=" + global_traversal;//hardcoded! - 65 = ajax event output
	var splitted = date.split(',');
	
	var date_obj = $(date);
	
	
	new Fx.Style('ajax_opacity', 'opacity', {duration: 500} ).start(0);
	
	(function(){
			  $('ajax_event').addClass('loader');
			  }).delay(400);
	(function(){
	new Ajax(url, {
		method: 'get',
		update: $('ajax_event'),
		onComplete: function(){
			$('ajax_event').removeClass('loader');
			new Fx.Style('ajax_opacity', 'opacity', {duration: 1000} ).start(0, 1);
		}
	}).request();
	}).delay(1000);//for debug only! remove this delay when live
	
	}else{
	//default message here	
		$('ajax_opacity').setHTML("<table height='300px' width='90%'><tr><td valign='middle' style='color: #333333; font-style: italic; padding: 0 0px 0 30px; text-align: right'>No events on this date. Please click on one of the dates above to see more events.</td></tr></table>");
		new Fx.Style('ajax_opacity', 'opacity', {duration: 1000} ).start(0, 1);
	}
	
	
	
}

var animate_loop = function (){
	
	
}



/*
//homepage JS									 
window.addEvent('load', function() {
	//periodical = animate_loop.periodical(8000);
        $('article_two').fireEvent('click');
	//causes the articles carousel to start, which will finish once user clicks an article
});

function click_one(this_iteration){
		//alert(this_iteration + ' vs(1) ' + last_iteration);
if(this_iteration > last_iteration + 1){
delay_time = 0;	
//alert('click 1');
}else{
delay_time = 8000;
}

	(function(){
			  last_iteration = iteration;
			  if(this_iteration == iteration){
			  
new Fx.Style(last_clicked, 'opacity', {duration: fade_speed, wait:true} ).start(0);
		(function(){
			last_clicked.setStyle('display', 'none');
			$('featured_article_1').setStyle('display', 'block');
			new Fx.Style('featured_article_1', 'opacity', {duration: fade_speed} ).start(1);
			last_clicked = $('featured_article_1');
last_article = 1;
		}).delay(fade_speed + 100);
		
		
		$('article_one').addClass('active_article');
		$('article_two').removeClass('active_article');
		$('article_three').removeClass('active_article');
		
		$('article_two').fireEvent('click');
			  }else{
				//alert('ignored 1');  
			  }
	
	}).delay(delay_time);

}

function click_two(this_iteration){
	//alert(this_iteration + ' vs(2) ' + last_iteration);
if(this_iteration > last_iteration + 1){
delay_time = 0;	
//alert('click two');
}else{
delay_time = 8000;
}

	(function(){
			  last_iteration = iteration;
			  if(this_iteration == iteration){
			  
new Fx.Style(last_clicked, 'opacity', {duration: fade_speed, wait:true} ).start(0);
		(function(){
			last_clicked.setStyle('display', 'none');
			$('featured_article_2').setStyle('display', 'block');
			new Fx.Style('featured_article_2', 'opacity', {duration: fade_speed} ).start(1);
			last_clicked = $('featured_article_2');
last_article = 1;
		}).delay(fade_speed + 100);
		
		
		$('article_two').addClass('active_article');
		$('article_one').removeClass('active_article');
		$('article_three').removeClass('active_article');
		
		$('article_three').fireEvent('click');
		
			  }else{
				//alert('ignored 2');  
			  }

	}).delay(delay_time);

}

function click_three(this_iteration){
//alert(this_iteration + ' vs(3) ' + last_iteration);
if(this_iteration > last_iteration + 1){
delay_time = 0;
//alert('click 3');
}else{
delay_time = 8000;
}

	(function(){
			  last_iteration = iteration;
			  if(this_iteration == iteration){
			  
new Fx.Style(last_clicked, 'opacity', {duration: fade_speed, wait:true} ).start(0);
		(function(){
			last_clicked.setStyle('display', 'none');
			$('featured_article_3').setStyle('display', 'block');
			new Fx.Style('featured_article_3', 'opacity', {duration: fade_speed} ).start(1);
			last_clicked = $('featured_article_3');
last_article = 1;
		}).delay(fade_speed + 100);
		
		
		$('article_three').addClass('active_article');
		$('article_two').removeClass('active_article');
		$('article_one').removeClass('active_article');
		
		$('article_one').fireEvent('click');
		
			  }else{
				//alert('ignored 3');  
			  }
		
	}).delay(delay_time);

}

window.addEvent('domready', function() {



last_clicked = $('featured_article_1');								 
	fade_speed = 1000;	
	if(window.ie7){
	fade_speed = 0;//ie7 antialiasing ruins the opacity effect	
	}
	$('featured_article_2').setStyle('opacity', '0');	
	$('featured_article_3').setStyle('opacity', '0');
					
					
	//carousel of featured articles here
	$('article_one').addEvent('click', function(e){
//$clear(periodical);
	iteration ++;
	//alert(iteration);
	click_one(iteration);
	});
	
		
	
	
	$('article_two').addEvent('click', function(e){
//$clear(periodical);				
		iteration ++;
		//alert(iteration);
		click_two(iteration);
		
		
	});
	
	$('article_three').addEvent('click', function(e){
//$clear(periodical);

		iteration ++;
		//alert(iteration);
		click_three(iteration);
	});


});

//end homepage JS
*/

//accordion for events calendar JS
window.addEvent('domready', function() {	
									 
if(window.webkit419){
	var disappear = $$('.date_page');
		
		for(var x=0; x<disappear.length; x++){
			var el = disappear[x];
			new Fx.Style(el, 'opacity', {duration: 100} ).start(1);
		}
}
									 
									 
var accordion = new Accordion('div.handle', 'div.element', {
	opacity: false,
	show: 0,
	//fixedHeight: 600,
	//transition: Fx.Transitions.linear,//change to whatever transition
	onActive: function(toggler, element){
		var dates = toggler.getElement('.dates');
		new Fx.Style(dates, 'background-color', {duration: 500} ).start('#9D9480');
		
		var disappear = toggler.getElements('.disappear');
		
		for(var x=0; x<disappear.length; x++){
			var el = disappear[x];
			if(!window.webkit419){
			new Fx.Style(el, 'opacity', {duration: 500} ).start(0);
			}else{
			var handle_more = toggler.getElement('.handle_link');	
			handle_more.setStyle('display', 'none');
			var event_title = toggler.getElement('.event_title');	
			event_title.setStyle('display', 'none');
			}
		}
		//toggler.setStyle('background-color', '#fff');
		//new Fx.Style(toggler, 'background-color', {duration: 300} ).start('#fff');'
		element.addClass('activeElement');
		var appear = element.getElement('.date_page');
		(function(){
		if(!window.webkit419){
		new Fx.Style(appear, 'opacity', {duration: 500} ).start(1);
		}
				
		}).delay(300);
	},
	onBackground: function(toggler, element){
		
		if(window.webkit419){
		(function(){
		var handle_more = toggler.getElement('.handle_link');	
		handle_more.setStyle('display', 'block');
		var event_title = toggler.getElement('.event_title');	
		event_title.setStyle('display', 'block');
		}).delay(500);
		}
		
		
		var dates = toggler.getElement('.dates');
		new Fx.Style(dates, 'background-color', {duration: 500} ).start('#C4BFB3');
		
		var disappear = toggler.getElements('.disappear');
		for(var x=0; x<disappear.length; x++){
			var el = disappear[x];
			if(!window.webkit419){
			new Fx.Style(el, 'opacity', {duration: 500} ).start(1);
			}
		}
		//new Fx.Style(toggler, 'background-color', {duration: 300} ).start('#E0E2D8');
		var appear = element.getElement('.date_page');
		element.removeClass('activeElement');
		(function(){
		if(!window.webkit419){
		new Fx.Style(appear, 'opacity', {duration: 500} ).start(0);
		}
		}).delay(0);
	}
}, $('calendar_accordion'));
});
//end accordion
