
var sumCustomers = 0;
function changeActiveCustomer(id, rows, title, mode, cid) {
	for ( var i = 0; i <= sumCustomers; i++) {
		if (rows) {
			if (id == i) {
				theClass = 'customerRowSelected';
			} else {
				theClass = 'customerRow';
			}
			$('customer_' + i).className = theClass;
		}
	}
	ajaxUpdate(mode, (mode == 2 /*MODE_TAGS*/? title : cid));
	$('customer_details').style.display = 'block';
	$('customer_details_title').update(title);
	$('customer_details_title').className = 'title_white';
	x = sIFR.replace(transit, {
		selector : '#customer_details_title',
		wmode : 'transparent',
		tuneHeight : '-1',
		offsetTop : '2',
		opaque : 'true',
		css : [ '.sIFR-root { color:#ffffff;font-size:24px;top:5px}' ]
	});
	window.top.document.title = title +" - "+ pageTitle;
	if(screen.width>1024 && !screenDebug)
	  $("block").style.minWidth = 1145 + "px";
	else {
	  $("block").style.minWidth = 975 + "px"; 
	}
}

function ajaxUpdate(contentType, parameter) {
	var url = 'ajax.php';
	var params = 'type=' + contentType + '&par=' + parameter;
	var ajax = new Ajax.Updater( {
		success : 'customer_details_textbody'
	}, url, {
		method : 'get',
		encoding : 'ISO-8859-1',
		parameters : params,
		onFailure : reportError
	});
}

function reportError(request) {
	$('customer_details_textbody').update('Fehler bei Ajax Update!');
}

var scrollHistory = 0;
var customer_hidden_id = 0

window.onscroll = function() {
	var object = $("customer_details");
	if (first) {
		startPos = $("content").offsetTop;
		if (startPos == 0)
			startPos = 189;
		first = false;
	}

	var windowHeight = document.viewport.getHeight();
	var scrollPositionTop = (window.pageYOffset != null) ? window.pageYOffset
			: document.documentElement.scrollTop;
	var scrollPositionBottom = scrollPositionTop + windowHeight;
	var detailsHeight = object.offsetHeight;
	var detailsOffsetTop = object.offsetTop;
	var buffer = 30;
	var scrollTo = 0;

	if (activeId != $("customer_hidden_id")) {
		if (scrollHistory < scrollPositionTop) {
			scrollDown = true;
			scrollUp = false;
		} else if (scrollHistory > scrollPositionTop) {
			scrollDown = false;
			scrollUp = true;
		} else {
			scrollDown = false;
			scrollUp = false;
		}

		if (scrollDown) {
			if ((detailsHeight + buffer) > windowHeight) {
				if ((scrollPositionBottom + buffer) > (detailsHeight + detailsOffsetTop)) {
					scrollTo = (scrollPositionBottom - buffer - detailsHeight - startPos);
					if (scrollTo < 0) {
						scrollTo = 0;
					}
					new Effect.Move(object, {
						x : 0,
						y : scrollTo,
						mode : 'absolute'
					});
				}
			} else {
				if ((scrollPositionTop + buffer) > detailsOffsetTop) {
					scrollTo = (scrollPositionTop + buffer - startPos);
					if (scrollTo < 0) {
						scrollTo = 0;
					}
					new Effect.Move(object, {
						x : 0,
						y : scrollTo,
						mode : 'absolute'
					});
				}
			}
		} else if (scrollUp) {
			if ((scrollPositionTop + buffer) < detailsOffsetTop) {
				scrollTo = (scrollPositionTop + buffer - startPos);
				if (scrollTo < 0) {
					scrollTo = 0;
				}
				new Effect.Move(object, {
					x : 0,
					y : scrollTo,
					mode : 'absolute'
				});
			} else if (((scrollPositionTop + buffer) > detailsOffsetTop)
					&& (((detailsHeight + buffer) < windowHeight) || (scrollPositionTop+buffer<=startPos))) {
				scrollTo = (scrollPositionTop + buffer - startPos);
				if (scrollTo < 0) {
					scrollTo = 0;
				}
				new Effect.Move(object, {
					x : 0,
					y : scrollTo,
					mode : 'absolute'
				});
			}
		}
	}
	scrollHistory = scrollPositionTop;
}
