/**
* Moves an object over x/y axis or both
*
* @param String mObjectId ID of the object you want to move
* @param Decimal mFromX Position to fade from (value of 'left' in CSS)
* @param Decimal mFromY Position to fade from (value of 'top' in CSS)
* @param Decimal mToX Opacity to fade to
* @param Decimal mToY Opacity to fade to
* @param Int mTime Number of milliseconds the fade should last
*/
function moveObject(mObjectId, mFromX, mFromY, mToX, mToY, mTime){
	
	//fetch object, calculate opacity step
	mTime = mTime / 50;
	var xDif = mToX - mFromX;
	var yDif = mToY - mFromY;
	var xStep = xDif / mTime;
	var yStep = yDif / mTime;
	
	//set from x / y
	var mObject = document.getElementById(mObjectId);
	mObject.style['left'] = mFromX +'px';
	mObject.style['top'] = mFromY +'px';
	
	//start moving
	changePosition(mObjectId, mFromX, mFromY, xStep, yStep, 1, mTime);
}

/**
* Used by the above function to move the object
*
* @param String mObjectId ID of the moving object
* @param Decimal curPosX Current (unrounded) X position
* @param Decimal curPosY Current (unrounded) Y position
* @param Decimal xStep Amount by which to update x-position on each itteration
* @param Decimal yStep Amount by which to update y-position on each itteration
* @param Int curTime Amount of milliseconds that have passed since the loop started
* @param Int totTime Number of milliseconds the fade should last in total
*/
function changePosition(mObjectId, curPosX, curPosY, xStep, yStep, curTime, totTime){
	
	//fetch object, calc new opacity
	var mObject = document.getElementById(mObjectId);
	var newPosX = curPosX + xStep;
	var newPosY = curPosY + yStep;
	
	//set opacity using a convenient single standard that works in all browsers
	mObject.style['left'] = Math.round(newPosX) +'px';
	mObject.style['top'] = Math.round(newPosY) +'px';
	
	//call again
	if (curTime < totTime){
		//if (mObjectId == 'houses-overview-blocks') alert(xStep);
		curTime += 1;
		setTimeout('changePosition("'+ mObjectId +'", '+ newPosX +', '+ newPosY +', '+ xStep +', '+ yStep +', '+ curTime +', '+ totTime +')', 50);
	}
	
//	else if (mObjectId == 'houses-overview-blocks') alert(xStep);
}

/**
* Fades an object
*
* @param String fObjectId ID of the object you want to fade
* @param Decimal fFrom Opacity to fade from
* @param Decimal fTo Opacity to fade to
* @param Int fTime Number of milliseconds the fade should last
*/
function fadeObject(fObjectId, fFrom, fTo, fTime){
	
	//fetch object, calculate opacity step
	fTime = fTime / 50;
	var opacityDif = fTo - fFrom;
	var opacityStep = opacityDif / fTime;
	
	//set from opacity changing
	var fObject = document.getElementById(fObjectId);
	fObject.style['opacity'] = fFrom;
	fObject.style['-moz-opacity'] = fFrom;
	fObject.style['-khtml-opacity'] = fFrom;
	fObject.style['filter'] = 'alpha(opacity='+ (fFrom *100) +')';
	fObject.style['-ms-filter'] = 'alpha(opacity='+ (fFrom *100) +')';
	
	//make object visible
	fObject.style['visibility'] = 'visible';
	
	//start changing
	changeOpacity(fObjectId, fFrom, opacityStep, 1, fTime);
}

/**
* Used by the above function to fade an object in or out
*
* @param String fObjectId ID of the object you want to fade
* @param Decimal fCurOpacity Current (unrounded) opacity
* @param Decimal fOpacityStep Amount by which to update the opacity on each itteration
* @param Int fTime Amount of milliseconds that have passed since the loop started
* @param Int fTime Number of milliseconds the fade should last in total
*/
function changeOpacity(fObjectId, fCurOpacity, fOpacityStep, fCurTime, fTotTime){
	
	//fetch object, calc new opacity
	var fObject = document.getElementById(fObjectId);
	var newOpacity = fCurOpacity + fOpacityStep;
	
	//set opacity using a convenient single standard that works in all browsers
	fObject.style['opacity'] = Math.round(newOpacity*100)/100;
	fObject.style['-moz-opacity'] = Math.round(newOpacity*100)/100;
	fObject.style['-khtml-opacity'] = Math.round(newOpacity*100)/100;
	fObject.style['filter'] = 'alpha(opacity='+ (newOpacity *100) +')';
	fObject.style['-ms-filter'] = 'alpha(opacity='+ (newOpacity *100) +')';
	//or 5 single standards that work in one browser (I can dream, can't I?)
	
	//call again
	if (fCurTime < fTotTime){
		fCurTime += 1;
		setTimeout('changeOpacity("'+ fObjectId +'", '+ newOpacity +', '+ fOpacityStep +', '+ fCurTime +', '+ fTotTime +')', 50);
	}
}

/**
* Scales an object up or down
* 
* @param String objectId ID of the object you wish to scale
* @param Int newHeight Desired width
* @param Int newWidth Desired height
* @param Int sTime Number of milliseconds scaling should last in total
*/
function scaleObject(objectId, curHeight, curWidth, newHeight, newWidth, sTime){

	//fetch object, calculate opacity step
	sTime = sTime / 50;
	
	//fetch object height and width
	var sObject = document.getElementById(objectId);
	var hDif = newHeight - curHeight;
	var wDif = newWidth - curWidth;
	var hStep = hDif / sTime;
	var wStep = wDif / sTime;
	
	//start moving
	changeSize(objectId, curHeight, curWidth, hStep, wStep, 1, sTime);
}

/**
* Used by the above function to scale the object
*
* @param String mObjectId ID of the moving object
* @param Decimal curHeight Current (unrounded) height
* @param Decimal curWidth Current (unrounded) width
* @param Decimal hStep Amount by which to update x-position on each itteration
* @param Decimal wStep Amount by which to update y-position on each itteration
* @param Int curTime Amount of milliseconds that have passed since the loop started
* @param Int totTime Number of milliseconds the fade should last in total
*/
function changeSize(objectId, curHeight, curWidth, hStep, wStep, curTime, totTime){
	
	//fetch object, calc new opacity
	var sObject = document.getElementById(objectId);
	var newHeight = curHeight + hStep;
	var newWidth = curWidth + wStep;
	
	//set opacity using a convenient single standard that works in all browsers
	sObject.style['height'] = Math.round(newHeight) +'px';
	sObject.style['width'] = Math.round(newWidth) +'px';
	
	//call again
	if (curTime < totTime){
		curTime += 1;
		setTimeout('changeSize("'+ objectId +'", '+ newHeight +', '+ newWidth +', '+ hStep +', '+ wStep +', '+ curTime +', '+ totTime +')', 50);
	}
}
