showDetails = function(theID,themePath) {
	var theID = theID;
	
	$('detail-popup').setStyle({'top':(document.viewport.getScrollOffsets().top+20)+'px'});
	
	new Ajax.Updater('detail-popup-content',themePath+'/ajax.php', {
		method: 'get',
		parameters: {
			post_id: theID,
			action: 'details'
		},
		onComplete: function() {
			$('detail-popup').removeClassName('loading');
			new Effect.BlindDown('detail-image-wrap');
		}
	});
	
	new Effect.Appear('detail-popup-container',{
		duration:.5
	});
}

showAboutDetails = function(theID,themePath) {
	var theID = theID;
	
	$('detail-popup').setStyle({'top':(document.viewport.getScrollOffsets().top+20)+'px'});
	
	new Ajax.Updater('detail-popup-content',themePath+'/ajax.php', {
		method: 'get',
		parameters: {
			post_id: theID,
			action: 'aboutdetails'
		},
		onComplete: function() {
			$('detail-popup').removeClassName('loading');
			new Effect.BlindDown('detail-image-wrap');
		}
	});
	
	new Effect.Appear('detail-popup-container',{
		duration:.5
	});
}

showDetailImage = function() {
	new Effect.Appear('detail-image');
}

loadInlineArchives = function(year,month,themePath) {
	new Ajax.Updater('archive-scroller',themePath+'/ajax.php', {
		method: 'get',
		parameters: {
			year: year,
			monthnum: month,
			action: 'inlinearchives'
		},
		onComplete: initScrolling
	});
}


initScrolling = function() {
	var cur_pos = $('archives-slide').offsetLeft;
	var total_width = 0;
	$$('#archive-scroller li').each(function(elm) {
		total_width += $(elm).getWidth()+72;
	});

	//alert(cur_pos);

	if(cur_pos == 41 || cur_pos == 0) {
		$('scroll-left').setOpacity(.25);
		$('scroll-right').setOpacity(1);
		Event.observe('scroll-right','click',scrollRight);
		Event.stopObserving('scroll-left','click',scrollLeft);
	} else if((Math.abs(cur_pos) + 911) >= (total_width)) {
		$('scroll-right').setOpacity(.25);
		$('scroll-left').setOpacity(1);
		Event.observe('scroll-left','click',scrollLeft);
		Event.stopObserving('scroll-right','click',scrollRight);
	} else {
		$('scroll-left').setOpacity(1);
		$('scroll-right').setOpacity(1);
		Event.observe('scroll-left','click',scrollLeft);
		Event.observe('scroll-right','click',scrollRight);
	}
	
	
	
}
scrollLeft = function(e) {
	Event.stop(e);
	new Effect.MoveBy('archives-slide', 0, 870 , 
	    {
	        duration: 0.4,  
	        transition: Effect.Transitions.sinoidal,
			afterFinish: initScrolling
	    });
}
scrollRight = function(e) {
	Event.stop(e);
	new Effect.MoveBy('archives-slide', 0, -870 , 
	    {
	        duration: 0.4,  
	        transition: Effect.Transitions.sinoidal,
			afterFinish: initScrolling
	    });
}

document.observe('dom:loaded',function() {
	Event.observe('close-details','click',function(e) {
		Event.stop(e);
		$('detail-popup').addClassName('loading');
		new Effect.Fade('detail-popup-container',{
			duration:.25,
			afterFinish: function() {
				$('detail-popup-content').update('');
			}
		});
	});
});
