/*----------------------------------------------------------------*/
/*	© 2009 Hal Lindsey Media Ministries
/*	JavaScript functions for The Hal Lindsey Report: archives
/*----------------------------------------------------------------*/

function preloadImages(){
	var imgNames = ['tab_active_1.gif', 'tab_hover_1.gif', 'tab_normal_1.gif', 'tab_active_2.gif', 'tab_hover_2.gif', 'tab_normal_2.gif'];
	var imgObjects = [];
	for(var i = 0; i < imgNames.length; i++){
		imgObjects[i] = new Image();
		imgObjects[i].src = '/images/' + imgNames[i];
	}
}

function switchView(view){
	$('#filters').attr('view',view);
	if($('#archives_'+view).css('display') == 'none'){
		// change 'tab' states
		$('#archives_tabs li a').attr('class','');
		$('#archives_tabs #tab_'+view+' a').attr('class','active');
		// show/hide filters
		if(view == 'news') $('#news_filters').show();
		else $('#news_filters').hide();
		// fade in/out content
		$('.archives_list').fadeOut('fast', function(){
			loadArchives();
		});
	}
}

function toggleCategory(ctg){
	var currentClass = $('#btn_'+ctg).attr('class') || "";
	if(currentClass == null || currentClass == ""){
		$('#btn_'+ctg).attr('class','off');
		$('#show_'+ctg).val(0);
	}else{
		$('#btn_'+ctg).attr('class','');	
		$('#show_'+ctg).val(1);
	}
}

function loadArchives(page){
	var view = $('#filters').attr('view');
	var month = $('#year').val() + "-" + $('#month').val();
	var categories = "";
	if($('#show_breaking-news').val() == 1) categories += "Breaking News";
	if($('#show_united-states').val() == 1) categories += (categories != "") ? ",United States" : "United States";
	if($('#show_international').val() == 1) categories += (categories != "") ? ",International" : "International";
	if($('#show_other-news').val() == 1) categories += (categories != "") ? ",Other News" : "Other News";
	if(page == null) page = 1;
	
	var target = "archives_" + view;
	$('#loader').fadeIn();
	$('#'+target).load("/includes/ajax/ajax_archives.php", {view:view, month:month, categories:categories, page:page}, function(){
		$('#loader').fadeOut();
		if($('#'+target).css('display') == 'none') $('#'+target).fadeIn();
	});
}

function viewPage(page){
	loadArchives(page);	
}