var resized_images_width = new Array();
var resized_images_height = new Array();
var MAX_POST_IMAGE_WIDTH = 500;

function fullscreen(){
	scrollbars = 0;
	var oSource = window.event.srcElement.src;
	width = resized_images_width[oSource];
	height = resized_images_height[oSource];

	url = window.event.srcElement.src;

	if(width > screen.availWidth){
		width = screen.availWidth;
		scrollbars = 1;
	}

	if(height > screen.availHeight){
		height = screen.availHeight;
		scrollbars = 1;
	}
	
	width = width + 25;
	height = height + 30;
	fullscr = window.open(url, "_blank","toolbar=no,location=no,menubar=no,fullscreen="+scrollbars+",channelmode="+scrollbars+",scrollbars="+scrollbars+",status=no,left=0,top=0,width="+width+",height="+height);
}

function resize(image){
	if(!image){
		var image = window.event.srcElement;
	}

	width = image.width;
	height = image.height;
	var url = image.src;

	if(width > MAX_POST_IMAGE_WIDTH){
		resized_images_width[url] = width;
		resized_images_height[url] = height;
		image.width = MAX_POST_IMAGE_WIDTH;
		image.alt = 'Click the image to see the original size. ('+width+'x'+height + ')';
		image.style.border = "dashed 1px #AAAAAA";
		image.style.cursor = "hand";
		image.onclick = fullscreen;
		image.height = Math.floor(height/(width/MAX_POST_IMAGE_WIDTH));
	}
}

function check_images(){
	count = document.images.length;
	i = 0;

	while(count>i){
		url = document.images[i].src;

		if(!url.match(/forums.ijji.com/) && !url.match(/images.ijjimax.com/) && !(document.images[i].width == 728 && document.images[i].height == 90)){
			if(document.images[i].complete){
				resize(document.images[i]);
			}else{
				document.images[i].onload = resize;
			}
		}

		i++;
	}
}
