/* ------------------------------
   Varying Window Size ! 
------------------------------------------------------------ */

/* configuration */
var next_page = "mediawikiindex.php5";
var img_prefix = "images/page0-ffffff-";
var class_prefix = "a_page0_";
var img_max_ratio = 0.80;	// max 80% of the page height
var img_x_full = 504, 		// page0.jpg img full size 
    img_y_full = 800;	

/* store window width and height */
var wwidth = 0, 
    wheight = 0;
function check_window_sizes() 
{
    if (typeof(window.innerWidth) == 'number') {
	// Non-IE
	wwidth = window.innerWidth;
	wheight = window.innerHeight;
    } else if (document.documentElement 
	       && (document.documentElement.clientWidth 
		   || document.documentElement.clientHeight)) {
	// IE 6+ in 'standards compliant mode'
	wwidth = document.documentElement.clientWidth;
	wheight = document.documentElement.clientHeight;
    } else if (document.body 
	       && (document.body.clientWidth 
		   || document.body.clientHeight)) {
	// IE 4 compatible
	wwidth = document.body.clientWidth;
	wheight = document.body.clientHeight;
    }
}

/* store img filename and other infos*/
var img_src = "", 
    class_name = "";
function check_img_src()
{    
    var suffix = "";
    var max_img_h = wheight * img_max_ratio; // max img height wrt page height
    if (max_img_h > 800) {
	suffix = "800";
    } else if (max_img_h > 700) {
	suffix = "700";
    } else if (max_img_h > 600) {
	suffix = "600";
    } else if (max_img_h > 500) {
	suffix = "500";
    } else if (max_img_h > 400) {
	suffix = "400";
    } else if (max_img_h > 300) {
	suffix = "300";
    } else {
	suffix = "200";
    }
    img_src = img_prefix + suffix + ".jpg"; 
    class_name = class_prefix + suffix;       
}

function change_img()
{
    check_window_sizes(); 
    check_img_src();
    /* load the right img */
    document.getElementById("img_page0").src = img_src;
    /* and change the className accordingly */
    document.getElementById("a_page0").className = class_name;
}

function preload_next_page()
{
    var next = new Image();
    next.src = next_page;

    loadem(next); 
}

function load()
{
    change_img();
    // preload_next_page();
    if (window.addEventListener) {
	// Mozilla/W3C
	window.addEventListener('resize', change_img, false);
    } else if (window.attachEvent) {
	// IE : non W3C !
	window.attachEvent('onresize', change_img);
    }
}

