/* functions for the archive */

getMoreFromArchive = function(media, size, not)
{
	var lastHeight;
	divId = 'more_' + media;
	imageClass = '.px' + size;

  	if (navigator.appName == "Microsoft Internet Explorer") {
  		windowHeight = document.documentElement.clientHeight;
  	} else {
		windowHeight = document.viewport.getHeight();
  	}
	padding = 15;
	if ($$(imageClass).first().getStyle('margin-top') == null) {
		rowHeight = $$('.image').first().getHeight();
	} else {
		rowHeight = $$('.image').first().getHeight() + parseInt($$(imageClass).first().getStyle('margin-top'));
	}
	buttonHeight = $(divId).getHeight() + padding;
	numberPerRow = 1;
	if (size == "80x60") { numberPerRow = 4; }
	if (size == "160x120") { numberPerRow = 2; }
	if (size == "320x240") { numberPerRow = 1; rowHeight = 407; }
	quantity = (parseInt(((windowHeight-buttonHeight) / rowHeight))) * numberPerRow;
	offset = -windowHeight + buttonHeight + ((quantity/numberPerRow) * rowHeight);
	// cope with really small screens
	if (quantity < 2) { quantitiy = 2; }
	new Ajax.Request('/snippets/getMoreRandom.jsp', 
	{
		parameters: { media: media, size: size, not: not, quantity: quantity },
		method: 'get',
		evalScripts: true,
		onSuccess: function(response) {
			if (response.responseText != "")
			{
				$('footer').style.height = (2000/numberPerRow) + 'px';
				Effect.ScrollTo($(divId), { offset: offset, queue: 'end'});
				$(divId).replace(response.responseText);
				$('footer').style.height = '120px';
			}
		},
		onComplete: function(response) {
			_gaq.push(['_trackEvent','archiveMore', media, quantity]);
		}
	});

}
