var iMaxWidth = 250;
var iMaxHeight = 55;
var iHeight;
var iWidth;
var oScaleImg;
var iTry;
var oScaleTimer;

//#####################
function ShowLogo( sSrc ){
	oScaleImg = new Image();
	oScaleImg.src = sSrc;
	iTry = 0;
	
	Wait();
}


//#####################
function WriteLogo(){
	var oImgLogo = GetObj( 'IMG_logo', self );

	Scale( oScaleImg.width, oScaleImg.height, oScaleImg.src, oImgLogo );
}


//#####################
function Wait(){

	if(!oScaleImg.complete && iTry<20){	
		iTry ++;
		oScaleTimer = window.setTimeout('Wait()', 1000);
	}
	else{
		WriteLogo();
		window.clearTimeout( oScaleTimer );
	}
}

//#####################
function CheckWidth(iW){
	return (iW <= iMaxWidth); }

//#####################
function CheckHeight(iH){
	return (iH <= iMaxHeight); }

//#####################
function Scale(iW, iH, sSrc, oImgLogo){
	iWidth = iW;
	iHeight = iH;

	if( !CheckWidth(iW) ){
		ScaleWidth(iW, iH);
		if( !CheckHeight(iHeight) ){			
			ScaleHeight(iW, iH);
		}
	}
	else if(!CheckHeight(iH) ){
		ScaleHeight(iW, iH);
		if(!CheckWidth(iWidth)) ScaleWidth(iW, iH);
	}
	
	with(oImgLogo){
		width = iWidth;
		height = iHeight;
		src = sSrc;
	}

}

//#####################
function ScaleHeight(iW, iH){
	var iScale = iMaxHeight / iH;
	iHeight = iMaxHeight;
	iWidth = iW * iScale;
}

//#####################
function ScaleWidth(iW, iH){
	var iScale = iMaxWidth / iW;
	iWidth = iMaxWidth;
	iHeight = iH * iScale;
}

