
window.onload = function (e) {
	// set a timezone cookie so the server can localise
	var now = new Date();
	var expires = "; expires=" + String(new Date(now.getFullYear(),
		now.getMonth() + 1, now.getDate()));
	document.cookie = "timezone=" + (-now.getTimezoneOffset() * 60) + expires + "; path=/";
}

function showMore (moreSpan, moreId) {
	moreSpan.style.display = 'none';
	document.getElementById(moreId).style.display = '';
}


function focusSearchField (field) {
	if (!field) { return; }
	if (field.value == field.getAttribute('default')) {
		field.value = '';
	}
	field.style.color = '';
}

function blurSearchField (field) {
	if (!field) { return; }
	if (field.value == '' || field.value == field.getAttribute('default')) {
		field.style.color = '#bbb';
		field.value = field.getAttribute('default');
	} else {
		field.style.color = '';
	}
}

function loadSearchField (field) {
	blurSearchField(field);
}

function image_loaded (img) {
	if ('naturalHeight' in img) {
		scale_image(img, img.naturalWidth, img.naturalHeight);
	} else {
		var img_clone = new Image();
		img_clone.onload = function () {
			scale_image(img, img_clone.width, img_clone.height);
		}
		img_clone.src = img.src;
	}
}

/** Scale the image to the correct proportions */
function scale_image (img, width, height) {
	var thumbHeight = img.height, thumbWidth = img.width; // thumbnail dimensions
	var scaledHeight = height, scaledWidth = width; // scaled dimensions
	if (scaledHeight > thumbHeight) { // if its too tall squish it
		img.height = scaledHeight = thumbHeight;
		img.width = scaledWidth = (width / height) * thumbHeight;
	}
	if (scaledWidth > thumbWidth) { // if its too wide squish it
		img.width = scaledWidth = thumbWidth;
		img.height = scaledHeight = (height / width) * thumbWidth;
	}
	
	img.style.borderStyle = 'solid';
	img.style.borderTopWidth = Math.floor((thumbHeight - scaledHeight) / 2) + 'px';
	img.style.borderBottomWidth = Math.ceil((thumbHeight - scaledHeight) / 2) + 'px';
	img.style.borderLeftWidth = Math.floor((thumbWidth - scaledWidth) / 2) + 'px';
	img.style.borderRightWidth = Math.ceil((thumbWidth - scaledWidth) / 2) + 'px';
}

function fixPng (img) {
    if (arguments.length == 0) { img = this; }

    if (navigator.platform == "Win32"
        && navigator.appName == "Microsoft Internet Explorer"
        && typeof img.style.filter == 'string'
        && img.src.match(/\.png$/i) != null)
    {
        var src = img.src;
        if (img.width) { img.style.width = img.width + "px"; }
        if (img.height) { img.style.height = img.height + "px"; }
        img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='scale')"
        img.onload = function () {
            img.className = img.className.replace(/\bfixPng\b/g, '');
        }
        img.src = src.substring(0, src.lastIndexOf('/')) + '/blank.gif';
    } else {
        img.className = img.className.replace(/\bfixPng\b/g, '');
    }
}

if (navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer") {
    document.write('<style type="text/css"> .fixPng { visibility: hidden; } </style>');
}

