
var nWindowW = 0;
var nWindowH = 0;
var Resize_CallBack = "";
var sAutoRunScript = "";

var sCurr_FileName = "";
var nCurr_Index = "";
var nCurr_Width = "";
var nCurr_Height = "";

var nDebugLevel = 0; 
var nDebugLevel_FnTrace = 0; 

oImg_NoPhoto = new Image ()
oImg_NoPhoto.src = "images/nophoto.gif";
oImg_Loading = new Image ()
oImg_Loading.src = "images/loading.gif";

// ***
if ( navigator.platform.toLowerCase() == "iphone" )
{
	if ( !location.href.match("bMain=true") )
	{
		location.href = "iphone.php";
	}
}
// ***



function getObject( sName )
{
	return document.getElementById(sName);
}

function isObject( Obj, bReturnObj )
{
	switch ( typeof(Obj) )
	{
		case "string":
			Obj = getObject(Obj); break;
	}

	return (typeof(Obj) == "object")?(bReturnObj)?Obj:true:false;
}


function getWindowSize()
{
	 if( typeof( window.innerWidth ) == 'number' ) {
	 //Non-IE
		  nWindowW = window.innerWidth;
		  nWindowH = window.innerHeight;
	 } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	 //IE 6+ in 'standards compliant mode'
		  nWindowW = document.documentElement.clientWidth;
		  nWindowH = document.documentElement.clientHeight;
	 } else if( document.body && ( document.body.clientWidth || document.body.clientHeight) ) {
	 //IE 4 compatible
		  nWindowW  = document.body.clientWidth;
		  nWindowH = document.body.clientHeight;
	 }
}


function Resize()
{
	if ( nDebugLevel_FnTrace > 0  )  alert( "Resize" );

	getWindowSize();
	if ( nWindowW <= 600 )
	{
		document.getElementById('oInfoZone').style.display = "block";
		document.getElementById('oBody').style.display = "none";
	}else{

		nHeight = parseInt(document.getElementById('oFooter').offsetHeight);	
		
	//	alert(nWindowH+":"+nWindowH+":"+nHeight);
		
		if ( nWindowH-nHeight > 20 )
		{
			document.getElementById('oZone').style.height = (nWindowH-nHeight)+"px";
		}
		
		document.getElementById('oInfoZone').style.display = "none";
		document.getElementById('oBody').style.display = "block";
		setTimeout(sAutoRunScript, 600);
		
	}
}


function Resize_PhotoZone()
{
	if (  nDebugLevel_FnTrace > 0 )  alert( "Resize_PhotoZone" );
	
	if ( nWindowW > 600 )
	{
		nHeight =  document.getElementById('oID_Projects').offsetHeight;
		nWidth =  document.getElementById('oID_Projects').offsetWidth;
		
		if (  nDebugLevel > 0 )  
			alert(nWindowH+":"+nWindowW+":"+nHeight+":"+nWidth);
		
		if ( nHeight-30 > 30 )
			document.getElementById('oPhotoZone').style.height = (nHeight-30)+"px";
	
		nPhotoThumTop = document.getElementById('oFn_PhotoThumb').offsetTop;
		
		if ( nHeight-46-nPhotoThumTop > 30 )
			document.getElementById('oFn_PhotoThumb').style.height = (nHeight-46-nPhotoThumTop)+"px";
	}
}


	function oScaleSize( W1, H1, W2, H2 )
	{
		if ( nDebugLevel_FnTrace > 0 )  alert( "oScaleSize" );
	
		this.R1 = W1/H1;
		this.R2 = W2/H2;

		this.I1 = (this.R1 > 1)?"W":"H";
		this.I2 = (this.R2 > 1)?"W":"H";
		
		
		W3=parseInt(H1*R2);
		H3=parseInt(W1/R2);
		
		sTempResult=0;
		if ( W3 <= W1 )
		{
			sTempResult += 1;
			this.width = parseInt( W3 );
			this.height = parseInt( H1 );
		}
		if ( H3 <= H1 )
		{
			sTempResult += 2;
			this.width = parseInt( W1 );
			this.height = parseInt( H3 );
		}

//		var oDebug = getObject("oDebug");		
//		if ( oDebug )
		if ( 0 )
		{
			oDebug.innerHTML = " Zone "+W1+"px "+H1+"px --- Img "+W2+"px "+H2+"px ";
			oDebug.innerHTML += "<BR> R2: "+R2;
			oDebug.innerHTML += "<BR> R2: "+R2;
			oDebug.innerHTML += "<BR>"+ sTempResult;
			
			oDebug.innerHTML += "<BR> W3: "+W3+":"+H1+"::"+W3/H1;
			oDebug.innerHTML += "<BR> H3: "+W1+":"+H3+"::"+W1/H3;
		}
		return this;
	}


	function chgPhoto( nIndex, nWidth, nHeight )
	{
		if ( nDebugLevel_FnTrace > 0 )  alert( "chgPhoto" );

		sFilePath = nIndex+".jpg";
//alert(sFilePath+":"+nIndex );
		if ( sFilePath == "" || nIndex == "" ) return;
		nCurr_Index = nIndex;
		nCurr_Width = nWidth;
		nCurr_Height = nHeight;
		
		oItem = document.getElementById("_Item"+nIndex);
//		nWidth = oItem.style.ImgW;
//		nHeight = oItem.style.ImgH;

		oTemp_Phone = document.getElementById("oPhoto");
		oTemp_PhotoZone = document.getElementById("oPhotoZone");
//		oTemp_Phone.src = "images/_blank2.gif";

		oTemp_Phone.src = "images/_blank2.gif";
		
		
		if (  nWidth > nHeight ){
			nTempWidth = parseInt(oTemp_PhotoZone.offsetWidth);
			if (nTempWidth>1000)
				sPath = "xlarge/";
			else if (nTempWidth>500)
				sPath = "large/";
			else
				sPath = "small/";
		}else{
			nTempHeight = parseInt(oTemp_PhotoZone.offsetHeight);
			if (nTempHeight>1000)
				sPath = "xlarge/";
			else if (nTempHeight>500)
				sPath = "large/";
			else
				sPath = "small/";
		}

//		alert( nWidth+":"+nHeight);
		oTemp = oScaleSize( oTemp_PhotoZone.offsetWidth, oTemp_PhotoZone.offsetHeight, nWidth, nHeight );
		oTemp_Phone.style.width = oTemp.width+"px";
		oTemp_Phone.style.height = oTemp.height+"px";		

		oTemp_Phone.src = sFd_Photo+sPath+sFilePath;
		
	}
	
	

	function chgPhoto_Furniture( nIndex, nWidth, nHeight )
	{
		if ( nDebugLevel_FnTrace > 0 )  alert( "chgPhoto" );

		sFilePath = nIndex+".jpg";
//alert(sFilePath+":"+nIndex );
		if ( sFilePath == "" || nIndex == "" ) return;
		nCurr_Index = nIndex;
		nCurr_Width = nWidth;
		nCurr_Height = nHeight;
		
		oItem = document.getElementById("_Item"+nIndex);
//		nWidth = oItem.style.ImgW;
//		nHeight = oItem.style.ImgH;

		oTemp_Phone = document.getElementById("oPhoto");
		oTemp_PhotoZone = document.getElementById("oPhotoZone");
		oTemp_ItemNum = document.getElementById("oItemNum");
//		oTemp_Phone.src = "images/_blank2.gif";

		oTemp_Phone.src = "images/_blank2.gif";
		
		
		if (  nWidth > nHeight ){
			nTempWidth = parseInt(oTemp_PhotoZone.offsetWidth);
			if (nTempWidth>1000)
				sPath = "xlarge/";
			else if (nTempWidth>500)
				sPath = "large/";
			else
				sPath = "small/";
		}else{
			nTempHeight = parseInt(oTemp_PhotoZone.offsetHeight);
			if (nTempHeight>1000)
				sPath = "xlarge/";
			else if (nTempHeight>500)
				sPath = "large/";
			else
				sPath = "small/";
		}

//		alert( nWidth+":"+nHeight);
		oTemp = oScaleSize( oTemp_PhotoZone.offsetWidth, oTemp_PhotoZone.offsetHeight, nWidth, nHeight );
		
//		alert( oTemp.width+":"+oTemp.height );
		oTemp_Phone.style.width = oTemp.width+"px";
		oTemp_Phone.style.height = oTemp.height+"px";		

		oTemp_Phone.src = sFd_Photo+sPath+sFilePath;
		oTemp_ItemNum.innerHTML = nIndex;

	}
	

	function loadThumbIcon( sObjName )
	{
		if ( nDebugLevel_FnTrace > 0 )  alert( "loadThumbIcon" );
		var oThumb = getObject(sObjName);
		oThumb.src = sFd_Photo_Thumb+ sObjName.replace("_Thumb", "")+".jpg";
	}
	
	function loadThumbIcon_IDlist( sObjName )
	{
		if ( nDebugLevel_FnTrace > 0 )  alert( "loadThumbIcon_idlist" );
		var oThumb = getObject(sObjName);
		oThumb.src = "interiordesign/"+sObjName.replace("_Thumb", "")+"/thumb.jpg";
	}
	
	function loadThumbIcon_FElist( sObjName, nProjectID )
	{
		if ( nDebugLevel_FnTrace > 0 )  alert( "loadThumbIcon_FElist" );
		var oThumb = getObject(sObjName);
		oThumb.src = "furniture/"+sObjName.replace("_Thumb", "")+"/thumb.jpg";
	}

	
window.onresize = Resize;
window.onload = Resize;
