
function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function change_main_image(thumb, new_image_src, original_width, original_height) {
	document.getElementById('main_image').src = '/images/loading.gif';
	imgs = getElementsByClass('image',document.getElementById('thumbnails'),'li');
	for(i in imgs)
		if(imgs[i].className.indexOf('selected') > -1)
			imgs[i].className = imgs[i].className.replace(/selected/g,'');

	if (thumb)
		thumb.className += ' selected';
	document.getElementById('main_image').src = new_image_src;

	if (original_width == null)
		width = 'auto';
	else if (original_width > 640)
		width = 640;
	else
		width = original_width;

	if (original_height == null)
		height = 'auto';
	else if (original_height > 480)
		if (original_width > 640)
			height = original_height*(640/original_width);
		else
			height = 480;
	else
		height = original_height;
	
	document.getElementById('main_image').width = width;
	document.getElementById('main_image').height = height;
}

function change_opacity(element, opac){
	return null;

	if ( opac == null ) {
		if (element.style.opacity > 0)
			opac = 0;
		else
			opac = 100;
	}

	element.style.opacity = opac;

}

function hover_border(thumb){
	imgs = getElementsByClass('thumb',document.getElementById('thumbnails'),'img');
	for(i in imgs)
		if(imgs[i].className.indexOf('over') > -1)
			imgs[i].className = imgs[i].className.replace(/over/g,'');

	if (thumb) // this way, I can call this with null and clear all borders without error
		thumb.className += ' over';
}

window.onload = function () {
	myimages = new Array();
	// preload = new Array(
	// ""
	// 	);
	// for (i = 0; i < preload.length; ++i) {
	// 	myimages[i]=new Image();
	// 	myimages[i].src=preload[i];
	// }
	// 
	// change_main_image(null,"");
}
