preloadImg = function()
{
	for(var i = 0; i<arguments.length; i++)
	{
		$("<img>").attr("src", arguments[i]);
	}
}

function determineFullHeight() {
	$(".pdfview, .pdfview iframe, .seadragonimage, .remoteview").each(function(i,element) {
		var element = $(element);
		var viewareaheight = $(window).height() - parseInt(element.offset().top);
		document.cookie = 'viewareaheight='+viewareaheight+';path=/';
		if(element.height() != viewareaheight) {
			element.css('height',viewareaheight);
		}
	});
}

$(document).ready(function(){
	//search button hover
	$('.search_btn').hover(function(){$(this).addClass('search_hover');}, function() {$(this).removeClass('search_hover');});
	// clear input on focus
	$('.clearMeFocus').focus(function(){if($(this).val()==$(this).attr('title')){$(this).val('');}});
	
	$('#search_form').submit(function() {
		$(this).find(".clearMeFocus").each(function(i,e) {
			if($(e).val() == $(e).attr("title")) {
				$(e).val('');
			}
		});
	});
	
	$("select.result_sorting").change(function() {
		var location = window.location.search;
		var currentSort = location.match(/(^|\&)sort=[^\&]*(\&|$)/);
		if(currentSort) {
			window.location = window.location.search.replace(currentSort[0], "&sort="+ escape($(this).val()));
		} else {
			if(location == '') {
				location = '?';
			}
			window.location = location + "&sort="+ escape($(this).val());
		}
	});
	
	
	determineFullHeight();
	$(window).bind('resize', function () {
		$(window).clearQueue();
		$(window).delay(200);
		$(window).queue(determineFullHeight);
	});
});
