// Design Brooklyn (www.designbrooklyn.com) 
// Appearance Functions


// OPACITY

function opacity(id, opacStart, opacEnd, millisec, linkTo) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;
	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			if (i == opacEnd && linkTo) {
				setTimeout("redirect('" + linkTo + "')",(timer * speed));
			}
			timer++;
		}
		
		
	} else if(opacStart < opacEnd) {
		for (i = opacStart; i <= opacEnd; i++) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style;
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

// position

function getAbsolutePosition(element) {
  var r = { x: element.offsetLeft, y: element.offsetTop };
  if (element.offsetParent) {
    var tmp = getAbsolutePosition(element.offsetParent);
    r.x += tmp.x;
    r.y += tmp.y;
  }
  return r;
};




// sliding / expanding

function growNavY(id, task, millisec) {
	
	ht = document.getElementById(id).style.height.replace("px","");
	wd = document.getElementById(id).style.width.replace("px","");
	content = document.getElementById(id).innerHTML;
	content = '<div style="position:relative; max-width:'+wd+'px; width:'+wd+'px;">'+content+'</div>';
	WriteByID('hTester',null,'');
	WriteByID('hTester',null,content);
	new_ht = parseInt(document.getElementById('hTester').offsetHeight);
	
	//speed for each frame	
	var timer = 0;	
	if (task == "shrink") {
		start = new_ht;
		end = 0;
		speed = Math.round(millisec / Math.abs(parseInt(end) - parseInt(start)) * 100)/100;
		for (i = parseInt(start); i >= parseInt(end); i--) {
			setTimeout("growByID(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else {
		start = 0;
		end = new_ht;
		speed = Math.round(millisec / Math.abs(parseInt(end) - parseInt(start)) * 100)/100;
		for (i = parseInt(start); i <= parseInt(end); i++) {
			setTimeout("growByID(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

function growY(id, start, end, millisec) {

	//speed for each frame
	var speed = Math.round(millisec / Math.abs(parseInt(end) - parseInt(start)) * 100)/100;
	var timer = 0;	
	if (start > end) {
		for (i = parseInt(start); i >= parseInt(end); i--) {
			setTimeout("growByID(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else {
		for (i = parseInt(start); i <= parseInt(end); i++) {
			setTimeout("growByID(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}


function growByID(h,id) {
	document.getElementById(id).style.height = h+"px";
}
