// 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

var activeNav = null;
var bStatus = Array();
function checkOpen(id, end) {
	start = parseInt(document.getElementById(id).style.height.replace("px",""));
	if (start > end && !isOver(id)) {
		growY(id, start, end, 500);
	}
}
function changeStatus(id,newStatus) {
	bStatus[id] = newStatus;
}
function growOverY(id, start, end, 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; width:'+wd+'px;">'+content+'</div>';
	WriteByID('hTester',null,'');
	WriteByID('hTester',null,content);
	new_ht = parseInt(document.getElementById('hTester').offsetHeight);
	
	if (ht >= (0 + new_ht) || bStatus[id] == 'working') {
		//setTimeout("growOverY('"+id+"',"+start+","+end+","+millisec+")",20);
	} else {
				
		growY(id, start, (0 + new_ht), millisec);
		bStatus[id] = 'working';
		setTimeout("changeStatus('"+id+"','available');",(millisec+20));
		setTimeout("checkOpen('"+id+"','"+start+"');",3000);
	}
}
function growOutY(id, start, end, millisec) {
	ht = document.getElementById(id).style.height.replace("px","");
	if (isOver(id) || bStatus[id] == 'working') {
		setTimeout("growOutY('"+id+"',"+ht+","+end+","+millisec+")",20);
	} else if (ht > end) {
		bStatus[id] = 'working';
		setTimeout("changeStatus('"+id+"','available');",(millisec+20));
		growY(id, ht, end, millisec);
	}

}
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 slideXR(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("moveXR(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else {
		for (i = parseInt(start); i <= parseInt(end); i++) {
			setTimeout("moveXR(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}
function moveXR(val,id) {
	document.getElementById(id).style.right = val+"px";
}	

function slideXL(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("moveXL(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else {
		for (i = parseInt(start); i <= parseInt(end); i++) {
			setTimeout("moveXL(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}
function moveXL(val,id) {
	document.getElementById(id).style.left = val+"px";
}	


function growByID(h,id) {
	document.getElementById(id).style.height = h+"px";
}

function isOver(id) {
	var el;
	if (document.all) {
		el = document.all[id];
	} else if (document.getElementById) {
		el = document.getElementById(id);
	}
	
	elPos = getAbsolutePosition(el);
	
	if (xMousePos <= elPos.x || yMousePos <= parseInt(elPos.y - 5)) {
		//alert("test: "+xMousePos+" < "+elPos.x);
		return false;
	}
	//elW = el.style.width.replace("px","");
	elW = el.offsetWidth;
	elH = el.style.height.replace("px","");
	elWid = parseInt(elW);
	elHei = parseInt(elH);
	if (xMousePos >= parseInt(elWid + elPos.x + 5) || yMousePos >= parseInt(elHei + elPos.y + 20) || yMousePos <= parseInt(elPos.y - 10)) {
		return false;
	}
	return true;
}