function popup_image(image_url, title) {
	var winl = (screen.width - 800)/2;
	var wint = (screen.height - 600)/2;
	var settings ='top='+wint+',';
	settings +='left='+winl+',';
	settings +='width=200, ';
	settings +='height=300, ';
	settings +='scrollbars=no,';
	settings +='resizable=yes';

    title = title.replace(/\s/g, '%20');

	win=window.open('/image_popup.php?image_url='+image_url+'&title='+title, 'image',settings);

	if(parseInt(navigator.appVersion) >= 4) {
		win.window.focus();
	}
}

function popup_image_size(image_url, title, w, h) {
	var winl = (screen.width-w)/2;
	var wint = (screen.height-h)/2;
	var settings  ='height='+h+',';
	settings +='width='+w+',';
	settings +='top='+wint+',';
	settings +='left='+winl+',';
	settings +='scrollbars=no,';
	settings +='resizable=yes';

	title = title.replace(/\s/g, '%20');
	
	win=window.open('http://www.autobuy.co.nz/image_popup.php?image_url='+image_url+'&title='+title, 'image',settings);

	if(parseInt(navigator.appVersion) >= 4) {
		win.window.focus();
	}

}

function popup_image_size_smart(image, title, width, height) {
	// Check to make sure that neither the width nor the height happens to be too big for the current res
	if (width > screen.width || height > screen.height) {
		var ratio_x = screen.width / width;
		var ratio_y = screen.height / height;

		var ratio;
		if (ratio_x < ratio_y)
			ratio = ratio_x;
		else
			ratio = ratio_y;

		width = (width * ratio) * 0.95;
		height = (height * ratio) * 0.95;
	}

	popup_image_size(image, title, width, height);
}

