	var piclib_fade_ready;
	piclib_fade_ready=true;

	function piclib_opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;
    piclib_fade_ready=false;
    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("piclib_changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("piclib_changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function piclib_changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    piclib_fade_ready=false;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
    if ((opacity==100) || (opacity==0)) piclib_fade_ready=true;
} 


	//Wait for all the images to finish loading, and wait for any 'fades' to complete	
	function wait_for_piclib_preload()
	{
		num_images = document.images.length;
		all_loaded=true;
		for (i=0;i<num_images;i++) 
			if (!document.images[i].complete) all_loaded=false;
		if (piclib_fade_ready==false) all_loaded=false;
			
		if (all_loaded==false)
			setTimeout("wait_for_piclib_preload()",200);
		else
			piclib_opacity('mod_piclib_holder',1,100,500);
	}

	//Ajax callback routine
	function mod_piclib_callback(data)
	{
		//Put the data in the hidden div, and wait for it to complete loading.
		document.getElementById('mod_piclib_holder').innerHTML = data;
		wait_for_piclib_preload();
	}

	function piclib_click_handler(album_id,page,photo_id)
	{
		piclib_changeOpac(0,'mod_piclib_holder');
		add_pool_request_fp('ajax_request_mod=mod_piclib_viewer&album_id='+album_id+'&page='+page+'&photo_id='+photo_id,mod_piclib_callback);
	}
	

	// Because the target div is loaded after this script, we need to poll until we know if it's there, if it's there we
	// call the click handler using default data so the main page is loaded on start.
	function piclib_init()
	{
		if (document.getElementById('mod_piclib_holder'))
			piclib_click_handler(0,0,0);
		else
			{
				setTimeout("piclib_init()",300);
			}
	}

	piclib_init();
