/*

 ***************************************************************************
 *                               mw3.js
 *                            -------------------
 *   begin                : Saturday, Jan 19, 2005
 *   copyright            : (c) 2005 by spooky2280 - Christian Fecteau
 *   email                : webmaster@christianfecteau.com
 *
 *   $Id: mw3.js, v 1.0.1 2005/02/22 spooky2280 $
 *
 *
 ***************************************************************************

 ***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 ***************************************************************************

   mw3 (Prevent Any Layout From Being Broken) 1.0.1
   A phpBB MOD originally created by Christian Fecteau.
   Credits must be given with my full name (Christian Fecteau)
   and a link to my portfolio: http://portfolio.christianfecteau.com/
   Removal or alteration of this notice is strongly prohibited.

*/

/*

   this is a severely neutered version of the above. less functionality,
   less super-cool javascriptness. but functional just the same.
   the warranty is most likely void now, but who doesn't void a warranty
   every once in a while by tinkering with something that should be left alone?

*/

/*
   getElementsByClassName function
   Written by Jonathan Snook, http://www.snook.ca/jonathan
   Add-ons by Robert Nyman, http://www.robertnyman.com
*/

function getElementsByClassName(oElm, strTagName, strClassName){
    var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i<arrElements.length; i++){
        oElement = arrElements[i];      
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }   
    }
    return (arrReturnElements)
}



/* get all the posts on the page */
function go()
{
	// lets make sure that there are posts in this page
	posts = getElementsByClassName(document, 'div', 'just_resize');
	if (posts && posts.length && (posts.length > 0)) {
		just_resize();
	}
}

/* function to resize images within posts */
function just_resize()
{
	if (!window.opera)
	{
		/* create a dummy object for the not yet existing popup */
		img_pop = new Object();
		img_pop.closed = true;
		// we need to close the popup onunload of the page for access permission (browser security)
		old_onunload = null;
		if (typeof window.onunload == "function") {
			old_onunload = window.onunload;
		}

		window.onunload = function() {
			if (old_onunload) {
				old_onunload();
				old_onunload = null;
			}
			if (!img_pop.closed) { img_pop.close(); }
		}
	}

	img_pop_options = 'top=0,left=0,width=' + String(window.screen.width-80) + ',height=' + String(window.screen.height-190) + ',scrollbars=1,resizable=1';

	loop_i:
	for (var i = 0; i < posts.length; i++)
	{
		imgs = posts[i].getElementsByTagName("IMG");
		
		loop_j:
		for (var j = 0; j < imgs.length; j++)
		{
			img = imgs[j];

			/* check if the image is larger than the max_image_width, then resize */
			if (	img.width && !isNaN(img.width) && max_image_width && !isNaN(max_image_width) && (img.width > max_image_width)	) {
				img.style.width = max_image_width + 'px';
				img.style.borderWidth = '2px;';
				img.style.borderStyle = 'solid';
				img.style.borderColor = '#FF0000';

				/* if we are in the Topic Review iframe, we dont make anything popable because of iframes security restrictions */
				if (window.topr) { continue loop_j; }

				/* make the popup onclick */
				if (!window.opera) {
					img.onclick = function() {
						if (!img_pop.closed) { img_pop.close(); }
						img_pop = window.open('about:blank','christianfecteaudotcom',img_pop_options);
						img_pop.resizeTo(window.screen.availWidth,window.screen.availHeight);
						img_pop.moveTo(0,0);
						img_pop.focus();
						img_pop.location.href = this.src;
					}
				}
				else {
					img.onclick = function() {
						img_pop = window.open(this.src,'christianfecteaudotcom',img_pop_options);
						img_pop.focus();
					}
				}
				document.all ? img.style.cursor = 'hand' : img.style.cursor = 'pointer';
				img.title = img.src;
			}
		}
	}
}

/* go! go! kill! */
if (	document.getElementsByTagName && (window.screen.width >= 800)	) {
	max_image_width = 600;
	old_onload = null;
	if (typeof window.onload == "function") { old_onload = window.onload; }
	window.onload = function() {
		if (old_onload) {
			old_onload();
			old_onload = null;
		}
		go();
	}
}
