function $(elemId) { return document.getElementById(elemId) }
function dbg(mixed) { return; console.debug(mixed); alert(mixed) }
Math.round2=function(num, decimals) {
	var mul=Math.pow(10, decimals);
	return Math.round(num*mul)/mul;
}
var Effects={};
//comon things:
Effects.Common={};
Effects.Common.parseLength=function (lengthStr) {
	if(!lengthStr) lengthStr='0px';
	var lenVal=parseFloat(lengthStr);
	var usedUnit=lengthStr.substr? lengthStr.substr((lenVal+"").length) : '';
	
	var ToReturn=new Object();
	ToReturn.lenVal=lenVal;
	ToReturn.usedUnit=usedUnit;
	if(ToReturn.usedUnit.indexOf(' ')!=-1)
 		ToReturn.usedUnit= ToReturn.usedUnit.substr(0, ToReturn.usedUnit.indexOf(' '));
	return ToReturn;
}
Effects.Common.getAK=function() {
	return Math.random();
}
Effects.Cache=[];

/*
 *	
 */
Effects.SteppyChange={};
Effects.SteppyChange.PredefinedStepInfos={
	Default:{delay:50, step:5},
	Smooth:{step:15, delay:10},
	Fast:{step:31, delay:10},
	Opacity:{delay:203, step:0.01},
	OpacitySlow:{delay:323, step:0.02}
};
Effects.SteppyChange.change=function(elemId, to_change, new_len, currInfos, stepsInfo) {
	if (!stepsInfo) stepsInfo=Effects.SteppyChange.PredefinedStepInfos.Default;
	if (!currInfos) currInfos={len:'0px', opacity:1}
	
	var elem=$(elemId);
	if (!elem._effects)elem._effects={};
	if (!elem._effects.chInfos) elem._effects.chInfos=[];
	if (!elem._effects.chInfos['_']) {
		elem._effects.chInfos['_']={
			origOpacity:elem.style.opacity?elem.style.opacity:currInfos.opacity
		}
	}
	if (to_change!='opacity'){
		elem.style.opacity='1';
		if (elem._effects.chInfos['opacity']) elem._effects.chInfos['opacity'].oKey=null;
	}
	
	var xLenStr; eval('xLenStr=elem.style.'+to_change+'');
	if(xLenStr=='') xLenStr=currInfos.len;
	
	var xLenInfo=Effects.Common.parseLength(xLenStr);
	//var xLenInfo=Effects.Common.parseLength(elem.style.border)
	var newLenInfo=Effects.Common.parseLength(new_len);
	
	var step =(xLenInfo.lenVal>newLenInfo.lenVal) ? -stepsInfo.step : stepsInfo.step;
	var oKey=Effects.Common.getAK();
	elem._effects.chInfos[to_change]={
		delay:stepsInfo.delay,
		step:step,
		unit:xLenInfo.usedUnit,
		xLen:xLenInfo.lenVal,
		currLen:xLenInfo.lenVal,
		newLen:newLenInfo.lenVal,
		oKey:oKey,
		endEvHandlerInfo:currInfos.endEvHandlerInfo?currInfos.endEvHandlerInfo:false
	};
	
	
	Effects.SteppyChange._set(elemId, to_change, oKey);
	
	return elem._effects.chInfos[to_change];
}
Effects.SteppyChange._checkDone=function (currDiff, nextDiff) {
	return (currDiff>=0 && nextDiff<=0) || (nextDiff>=0 && currDiff<=0);
}
Effects.SteppyChange._reset=function(elemId) {
	var elem=$(elemId);/*
	Effects.SteppyChange.change(elemId, 'opacity', elem._effects.chInfos['_'].origOpacity,
			{opacity:elem._effects.chInfos['_'].origOpacity, len:elem.style.opacity},
			Effects.SteppyChange.PredefinedStepInfos.Opacity);*/
	setTimeout(function(){
		Effects.SteppyChange.change(elemId, 'opacity', elem._effects.chInfos['_'].origOpacity,
			{opacity:elem._effects.chInfos['_'].origOpacity, len:elem.style.opacity},
			Effects.SteppyChange.PredefinedStepInfos.Opacity);
	}, 1000);
	
}
Effects.percision=2;
Effects.SteppyChange._set=function(elemId, to_change, oKey) {
	var elem=$(elemId);
	var chInfos=elem._effects.chInfos[to_change];
	if (chInfos.oKey!=oKey){
		dbg('oKey Changed');
		return;
	}
	
	var nextLen=Math.round2(chInfos.currLen+chInfos.step, Effects.percision);
	//alert(chInfos);
	var toBeEvald='elem.style.'+to_change+'="'+nextLen+chInfos.unit+'"';
	//dbg(toBeEvald);
	eval(toBeEvald);
	if (Effects.SteppyChange._checkDone(chInfos.newLen-chInfos.currLen, chInfos.newLen-nextLen)) {
		if(chInfos.endEvHandlerInfo) {
			Thread.Start(function(){
				chInfos.endEvHandlerInfo.func(chInfos.endEvHandlerInfo.param);
			})
			
		} else {
			if (to_change!='opacity') Effects.SteppyChange._reset(elemId);
			return;
		}
	}
	chInfos.currLen=nextLen;
	setTimeout('Effects.SteppyChange._set("'+elemId+'", "'+to_change+'", "'+oKey+'")', chInfos.delay);
}

Thread={
	Start:function(func) {
		setTimeout(func, 0);
	}
}


/*
 *	Corners
 */
Effects.Borders={};
Effects.Borders.setBorderRadius=function (elemID, corner, newVal, oKey) {
	var elem=document.getElementById(elemID);
	if (eval('elem.oKey_BorderRadius_'+corner) == oKey) {
		switch(corner.toUpperCase()) {
			case 'TR': case 'RT': elem.style.MozBorderRadiusTopright=newVal; 	break;
			case 'TL': case 'LT': elem.style.MozBorderRadiusTopleft=newVal;		break;
			case 'BL': case 'LB': elem.style.MozBorderRadiusBottomleft=newVal; 	break;
			case 'BR': case 'RB': elem.style.MozBorderRadiusBottomright=newVal;	break;
			default: alert('NOT_GOOD_VAL!! : |');
		}
		
	}
}

var CornerRadiusDefaultSteps=15;
var CornerRadiusDefaultStepDelay=40;

function SteppyCornerToVal(elemID, corner, newVal) {
	var currentValue;
	var elem=document.getElementById(elemID);
	with (elem.style) {
		switch(corner.toUpperCase()) {
			case 'TR': case 'RT': currentValue=parseInt(MozBorderRadiusTopright); 	break;
			case 'TL': case 'LT': currentValue=parseInt(MozBorderRadiusTopleft);	break;
			case 'BL': case 'LB': currentValue=parseInt(MozBorderRadiusBottomleft); break;
			case 'BR': case 'RB': currentValue=parseInt(MozBorderRadiusBottomright);break;
		}
	}
	if(isNaN(currentValue)) {
		currentValue=0;
	}
	
	var destValueInfo=parseLength(newVal);
	var distance=destValueInfo.lenVal-currentValue;
	
	//loop vars
	var steps=CornerRadiusDefaultSteps;
	var stepSize=distance/steps;
	var unitToUse=destValueInfo.usedUnit;
	var stepDelay=CornerRadiusDefaultStepDelay;
	var oKey=Math.random();
	eval('elem.oKey_BorderRadius_'+corner+'='+oKey);
	//and the loop itself
	
	for(var i=0; i<steps; i++) {
		var call_str="setBorderRadius('"+elemID+"','"+corner+"', '"+
			(currentValue+(stepSize*i))+unitToUse+"', "+oKey
			+")";
		
		setTimeout(call_str, stepDelay*i);
	}
	
	var call_str="setBorderRadius('"+elemID+"','"+corner+"', '"+
			newVal+"', "+oKey
			+")";
		
	setTimeout(call_str, stepDelay*i);
}

function borderRadiusChange(elemId, targetVal, targetedCorners) {
	try {
		with (document.getElementById(elemId).style) {
			if(!MozBorderRadiusTopleft && !MozBorderRadiusTopright &&
				 !MozBorderRadiusBottomleft && !MozBorderRadiusBottomright) {
				 return;
			}
		}
		
	} catch(e) {
		//okay=false;
		
		return;
	}
	
	for (var i=0; i<targetedCorners.length; i++) {
		SteppyCornerToVal(elemId, targetedCorners[i], targetVal);
	}
}

/*
 *		Resize
 */
/*
function resizeTo(elemId, targetHeight, targetWidth) {
	
	var elem=document.getElementById(elemId);
	var currentWidth =parseInt(elem.style.width);
	var currentHeight=parseInt(elem.style.height);
	
	//shared things
	var steps=CornerRadiusDefaultSteps;
	var Key=elem.Key=Math.random();
	var stepDelay=CornerRadiusDefaultStepDelay;
	//width vars
	var widthInfo=parseLength(targetWidth);
	var wanted_width=widthInfo.lenVal;
	var width_distance=wanted_width-currentWidth;
	var unitToUse_Width=widthInfo.usedUnit;
	var stepSize_Width=width_distance/steps;
	//height vars
	var heightInfo=parseLength(targetHeight);
	var wanted_height=heightInfo.lenVal;
	var height_distance=wanted_height-currentHeight;
	var unitToUse_Height=heightInfo.usedUnit;
	var stepSize_Height=height_distance/steps;
	
	for(var i=0; i<steps; i++) {
		var call_str="setSizeByKey('"+elemId+"','"+
			(currentHeight+(stepSize_Height*i))+unitToUse_Height+"', '"+
			(currentWidth+(stepSize_Width*i))+unitToUse_Width+"', "+Key
			+")";
		
		setTimeout(call_str, stepDelay*i);
	}
	var call_str="setSizeByKey('"+elemId+"','"+
			(targetHeight)+"', '"+
			(targetWidth)+"', "+Key
			+")";
	setTimeout(call_str, stepDelay*steps);
}

function setSize(elemId, height, width) {
	var elem=document.getElementById(elemId);
	elem.style.width=width;
	elem.style.height=height;
}

function setSizeByKey(elemId, height, width, Key) {
	var elem=document.getElementById(elemId);
	if (elem.Key==Key) {
		setSize(elemId, height, width);
	}
}
*/

/*
 *	SetOffset
 */

Effects.Offset={};
Effects.Offset.setOffset=function(elemId, top, left) {
	var elem =document.getElementById(elemId);
	elem.style.top=top;
	elem.style.left=left;
}
Effects.Offset.moveAsFormula=function(elemId, topFormula, leftFormula, extraInfo) {
	with (extraInfo) {
		for(var time=startWith; (startWith<endWith)? (time<endWith) : (time>endWith); time+=step) {
			var call_str='Effects.Offset.setOffset("'+elemId+'", "'+parseInt(eval(topFormula))+'px'+'", "'+parseInt(eval(leftFormula))+'px");';
			//alert(call_str); return;
			
			setTimeout(call_str, time*delay);
		}
	}
}


//TODO:Fix to sth more okay

NavigatorInfo={
	NVG_FFX:1,
	NVG_IE:9
};

NavigatorInfo.Type=NavigatorInfo.NVG_FFX;
NavigatorInfo.Version=0;