function showHide(){
	$('.read-more').bind('click', function(){		
		$(this).parent().hide();				
		$(this).parent().next().slideToggle('fast');		
		return false;
	});
	
	$('.less').bind('click', function(){
		$(this).parent().parent().slideToggle('fast');
		$(this).parent().parent().prev().children('.read-more').parent().show();
		return false;
	});
}

function pagination(){
	$('#pagination a:first').prepend('&laquo;');
	$('#pagination a:last').append('&raquo;');
	$('#news-content #pagination a').bind('click', paginate);
}

/*
function paginate(){
	// display loader
	$('#content').css({background:'#fff url(/images/loader2.gif) no-repeat 97% 20px', height:'500px'});
	
	// determine which content to filter by
	var div = $('.container:visible').attr('id');	
	switch(div){
		case 'news-content': var type = 'newscategory'; break;			
	}
	
	var page = $(this).attr('href')+'&type='+type;	
	$.get('/ajax/events.php'+page, function(o){
		$('#content').css({background:'#fff', height:'auto'});
		var resp = o.split('<!--split-->');
		$('#news-list').html(resp[0]);
		$('#news-banners').html(resp[1]);
		pagination();
	
	});	
	return false;
}
*/

$(document).ready(function(){
	showHide();
	//pagination();
	
	// change text color on focus 
	$('#search_term').focus(function(){
		$(this).addClass('focus');
	});
	
	$('.external').attr('target', '_blank');	
	
	$('#newsfilter').change(function(){
		if(this.selectedIndex != 0){
			$('#newsmonth').attr('selectedIndex', 0);
			$.get('/ajax/events.php', { category:$(this).val(), type:'newscategory'}, function(o){
				var resp = o.split('<!--split-->');
				$('#news-list').html(resp[0]);
				$('#news-banners').html(resp[1]);
				showHide();
			});
		}
	});
	
// ============================================ 
// = get all news articles for selected month = 
// ============================================ 
	$('#newsmonth').change(function(){
		if(this.selectedIndex != 0){
			$('#newsfilter').attr('selectedIndex', 0);
			$.get('/ajax/events.php', { type:'newsmonth', month:$(this).val()  }, function(o){
				var resp = o.split('<!--split-->');
				$('#news-list').html(resp[0]);
				$('#news-banners').html(resp[1]);
			});			
		}
	});
	
	$('#category').change(function(){
		// figure out which container is visible
		var div = $('.container:visible').attr('id');
		
		if(this.selectedIndex != 0){
			
			switch(div){
				case 'cal-content':
					$('#cal-content').html('').css({background:'url(/images/ajax-loader.gif) no-repeat center center', height:'300px'});
					$.get('/ajax/events.php', { category:$(this).val(), type:'calendar' }, function(o){
						$('#cal-content').html(o).css({background:'none', height:'auto'}).fadeIn('slow');
					})
				break;
				
				case 'list-content':
					$('#events').html('').css({background:'url(/images/ajax-loader.gif) no-repeat center cener', height:'300px'});
					$.get('/ajax/events.php', { category:$(this).val(), type:'list' }, function(o){
						var resp = o.split('<!--split-->');
						$('#events').html(resp[0]).css({background:'none', height:'auto'}).fadeIn('slow');
						$('#banners').html(resp[1]);
					});	
				break;
			}
		}
	});
	
	$('#month').change(function(){	
		var div = $('.container:visible').attr('id');
		switch(div){
			case 'cal-content':	
				toggle('month'+$(this).val()+'', 12, 'month', 'month', 'Y');
			break;
			
			case 'list-content':
				$.get('/ajax/events.php', { type:'list', month:this.options[this.selectedIndex].innerHTML }, function(o){
					var response = o.split('<!--split-->');
					$('#events').html(response[0]);
					$('#banners').html(response[1]);
				});
			break;
		}
	});
	
	// =========================================================================
	// = Determine if a tab has been marked in the location bar. Open that tab = 
	// ========================================================================= 
	var tab = window.location.hash;
	if(tab){
		if(tab == '#eventlist' || 'eventlist') {
			tab = '#list';
			$('#filters').show();
		}
		
		$('.container').hide();
		$(tab+'-content').show();		
		$('#caltabs .active').removeClass('active');
		$(tab).parent().addClass('active');
	}
	
	// tab switcher
	$('#caltabs a').click(function(){
		$('.active').removeClass('active');
		$(this).parent().addClass('active');
		var div = $(this).attr('id')+'-content';				
		
		// hide the container that is visible
		if($.browser.msie){
			$('.container:visible').hide();
			$('#'+div).show();
		} else {
			$('.container:visible').fadeOut('fast');			
			$('#content').css({background:'#fff url(/images/loader2.gif) no-repeat 97% 20px', height:'500px'});
			setTimeout(function(){
				$('#content').css({background:'#fff', height:'auto'});
				$('#'+div).fadeIn('slow');
			}, 1500);
			//$('#'+div).slideDown('slow');
		}
		
		// hide or show the filters
		if(div !== 'news-content'){
			$('#filters').show();
		} else {
			$('#filters').hide();
		}
		
		return false;
	});	

});