﻿//-------------------------------------------------------------------
// Image resize
//-------------------------------------------------------------------
// note to self:
// some browsers do not like function calls with parameters in setTimeout.
//  
var imgCollection       = new Array();
var imgCollectionStorage= new Array();

var ResizeFlag;
var ResizeWidth;
var ResizeHeight;

function RecallResize() // cause AOL sucks
{
	ResizeImage(ResizeFlag, ResizeWidth, ResizeHeight)
}
function ResizeImage(flag, w, h)
{
	var tmpWidth;
	var tmpHeight;
	var oImg = new Image();
	ResizeFlag		= flag;
	ResizeWidth		= w;
	ResizeHeight	= h

	for (var i in imgCollection) 
	{
		if ( ! imgCollection[i].complete )
		{
			setTimeout("RecallResize()", 500) 
		}
		else
		{		
			tmpWidth	= imgCollection[i].width
			tmpHeight	= imgCollection[i].height				
			if(flag == 0)
			{	
				if( tmpWidth > w) 
				{
					tmpHeight = Math.round(((w)/tmpWidth) * tmpHeight); 
					tmpWidth = w;									
				}
			}
			else
			{
				if( tmpHeight > h) 
				{
					tmpWidth = Math.round(((h)/tmpHeight) * tmpWidth); 
					tmpHeight = h; 
				}			
			}	
			document.getElementById(i).src			= imgCollection[i].src;
			document.getElementById(i).width		= tmpWidth;
			document.getElementById(i).height		= tmpHeight;			
			document.getElementById(i).style.width	= tmpWidth  + "px";
			document.getElementById(i).style.height	= tmpHeight + "px";
			document.getElementById(i).style.display= '';
		}
	}					
}

function RecallResizeOption1() // cause AOL sucks
{
	//alert('hi');
	ResizeImageOption1(ResizeFlag, ResizeWidth, ResizeHeight, imgCollectionStorage)
}
function ResizeImageOption1(flag, w, h, array)
{
	var tmpWidth;
	var tmpHeight;
	var oImg = new Image();
	
	ResizeFlag		        = flag;
	ResizeWidth		        = w;
	ResizeHeight	        = h
    imgCollectionStorage    = array
    
	for (var i in imgCollectionStorage) 
	{
		if ( ! imgCollectionCustom[i].complete )
		{		    
			setTimeout('RecallResizeOption1()', 500) 
		}
		else
		{		
			tmpWidth	= imgCollectionStorage[i].width
			tmpHeight	= imgCollectionStorage[i].height				
			if(flag == 0)
			{	
				if( tmpWidth != w) 
				{
					tmpHeight = Math.round(((w)/tmpWidth) * tmpHeight); 
					tmpWidth = w;									
				}
			}
			else
			{
				if( tmpHeight != h) 
				{
					tmpWidth = Math.round(((h)/tmpHeight) * tmpWidth); 
					tmpHeight = h; 
				}			
			}	
			document.getElementById(i).src			= imgCollectionStorage[i].src;
			document.getElementById(i).width		= tmpWidth;
			document.getElementById(i).height		= tmpHeight;			
			document.getElementById(i).style.width	= tmpWidth  + "px";
			document.getElementById(i).style.height	= tmpHeight + "px";
			document.getElementById(i).style.display= 'block';
		}
	}					
}

function SetImageSizeDefaultRecall() // cause AOL sucks
{
    SetImageSizeDefault(imageCollectionStorage)
}
function SetImageSizeDefault(array) {
    var currw;
    var currh;
    var src;
    var imgObject;
    var oImg = new Image();
    imageCollectionStorage = array

    for (var i in imageCollectionStorage) {
        if (imageCollectionStorage[i]) {
            imgObject = imageCollectionStorage[i];

            if (!imgObject.complete) {
                setTimeout('SetImageSizeDefaultRecall()', 500)
            }
            else {
                src = imgObject.src
                currw = imgObject.width
                currh = imgObject.height
                setImageProperties(i, currw, currh, src)
            }
        }
    }
}
function setImageProperties(i, w, h, src) {
    document.getElementById(i).src = src;
    //document.getElementById(i).width		= w;
    //document.getElementById(i).height		= h;			
    document.getElementById(i).style.width = w + "px";
    document.getElementById(i).style.height = h + "px";
    document.getElementById(i).style.display = '';

}

//-------------------------------------------------------------------
// Image resize
//-------------------------------------------------------------------