/**
 * fetchs the month and year from the form at the press archive page and creates unix timestamps
 * @author Stefan Sprenger <stefan.sprenger@dkd.de>
 * @since 2008-10-17
 */


// Auslesen der GET-Parameter

HTTP_GET_VARS=new Array();
strGET=document.location.search.substr(1,document.location.search.length);

if(strGET!='') {
		gArr=strGET.split('&');

		for(i=0;i<gArr.length;++i) {
		        v='';vArr=gArr[i].split('=');
		        if(vArr.length>1){v=vArr[1];}
		        HTTP_GET_VARS[unescape(vArr[0])]=unescape(v);
	        }
}

function GET(v)
{
		if(!HTTP_GET_VARS[v]){return 'undefined';}
		return HTTP_GET_VARS[v];
}

var newsArchive = {
	init: function(){
		if ( $('#news-timeselector').length ){
			this.autoSend();
			$("#news-timeselector > .timeselectors > .send").bind("click", function() {
			if($("#monthselector").val()=='0') {

				var url = location.pathname + '?tx_ttnews[year]=' + $("#yearselector").val() + '&archiveMode=year&no_cache=1';
				window.location.href = url;
				return false;
			}
			});
			$('#yearselector').next().hide();

			if(GET('archiveMode')=='year') {
				$("#monthselector > option:first").attr("selected","selected");
			}

//			$('.news-list-container').children().each(function(index, item) {
//				var date = $(item).children('.news-list-content').children('.right').children('.news-list-date').html();
//				if (date) {
//					var aktYear = $("#yearselector > option:selected").html();
//					var start = date.length-4;
//					var ende = start + 4;
//					jahr = date.substring(start, ende);
//					if (jahr != aktYear) {
//						$(item).detach();
//					}
//				}
//			});
		}
	},

	autoSend: function(){
		$('#monthselector, #yearselector').change(  function(){
			$("#news-timeselector > .timeselectors > .send").trigger('click');
		});
	}
}
