function $_(n) {
	if(!n) return false;
	if(!document.getElementById(n)) return false;
	return document.getElementById(n)
}

function bubbling_no(e) {
	e = bubbling_ie(e); /* for ie */
	if (!e.cancelBubble) e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();
	return false;
}
function bubbling_ie(e) {
	if (!e) var e = window.event;
	return e;
}

function bounds(obj) {
	var left = obj.offsetLeft;
	var top = obj.offsetTop;
	for (var parent = obj.offsetParent; parent; parent = parent.offsetParent) {
		left += parent.offsetLeft;
		top += parent.offsetTop;
	}
	return {left: left, top: top, width: obj.offsetWidth, height: obj.offsetHeight};
}

var prethis, preel, preeff;

function toggle_hide(_this, el, eff) {
	switch (eff) {
		case "fade":
			$("#"+el).fadeOut("fast");
			break; 

		case "none":
			$("#"+el).css({ display:"none"});
			break; 

		default:
			$("#"+el).slideUp("fast");
	}
	
	$(_this).removeClass("active");
}

function toggle(e, _this, el, eff) {
	if (prethis && $_(preel) && prethis != _this) toggle_hide(prethis, preel, preeff);
	prethis = _this;
	preel = el;
	preeff = eff;
	bubbling_no(e);
	if ($_(el)) {
		if (_this.className.indexOf("active") == -1) {
			$(_this).addClass("active");
			
			switch (eff) {
				case "fade":
					$("#"+el).fadeIn("fast");
					break;    

				default:
					$("#"+el).slideDown("fast");
			}
			
			$("#"+el).click(function(e) {
				bubbling_no(e);
			});

		} else {
			toggle_hide(_this, el, eff);
		}
		
		$(document).click(function() {
			toggle_hide(_this, el, eff);
		});
	}
}

function toggle_only(_this, el, eff) {
	if ($_(el)) {
		if (_this.className.indexOf("active") == -1) {
			$(_this).addClass("active");
			
			switch (eff) {
				case "fade":
					$("#"+el).fadeIn("fast");
					break;
				
				case "block":
					$("#"+el).css({ display:"block"});
					break;

				default:
					$("#"+el).slideDown("fast");
			}
		} else {
			toggle_hide(_this, el, eff);
		}
	}
}

function zoom(el) {
	try {
		if ($_(el)) {
			$("#"+el).fadeIn("fast");
			$("#spacer").css({ display:"block" });
			
			if (!$_("hideselect")) $("body").append("<iframe id='hideselect'></iframe>");
			$("#hideselect").css({ display:"block" });
			
			overlay_size(el);
			
			$(window).resize(function() {
				overlay_size(el);
			});
			
			$("#spacer").click(function() {
				$("#hideselect").css({ display:"none" });
				$("#spacer").css({ display:"none" });
				$("#"+el).fadeOut("fast");
			});
		}
	} catch(e) {
		//alert( e );
	}
}

function overlay_size(el) {
	if (window.innerHeight && window.scrollMaxY) h = window.innerHeight + window.scrollMaxY;
	else if (document.body.scrollHeight > document.body.offsetHeight) h = document.body.scrollHeight;
	else h = document.body.offsetHeight;
	
	$("#spacer").css("height",h +"px");
	$("#hideselect").css("height",h +"px");
}


