var isScrolling = false;
var scrollSpeed = 5;

function $elem$(id) {
	return document.getElementById(id);
}

function checkScroll() {
	with ($elem$('page_content')) {
		if (scrollHeight > clientHeight) {
			style.width = '430px';
			style.right = '28px';
			$elem$('scroll_buttons').style.visibility = 'visible';
		}
	}
}

function startScrolling() {
	isScrolling = true;
	
	if ($('#arrival_date')) $('#arrival_date').datepicker('hide');
	if ($('#departure_date')) $('#departure_date').datepicker('hide');
}

function stopScrolling() {
	isScrolling = false;
	scrollSpeed = 5;
}

function scrollUp() {
	with ($elem$('page_content')) {
		if (scrollTop > 0 && isScrolling) {
			scrollTop -= scrollSpeed;
			setTimeout('scrollUp()', 50);
		}
		else return;
	}
}

function scrollDown() {
	with ($elem$('page_content')) {
		if (scrollTop < scrollHeight - clientHeight && isScrolling) {
			scrollTop += scrollSpeed;
			setTimeout('scrollDown()', 50)
		}
		else return;
	}
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			if (obj.id == 'page_content') break;
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function showConversions(anchor, EUR, USD, GBP) {
	anchor = findPos(anchor);
	$elem$('preturi').innerHTML = '<table style="width: 150px" class="tarife" cellspacing="0" cellpadding="5" border="1"><tr><td>EUR</td><td>' + EUR + '</td></tr><tr><td>USD</td><td>' + USD + '</td></tr><tr><td>GBP</td><td>' + GBP + '</td></tr></table>';
	with ($elem$('preturi').style) {
		top = left = right = bottom = '';
		display = 'block';
		right = (500 - anchor[0]) + 'px';
		if (anchor[1] + $elem$('preturi').clientHeight > $elem$('page_content').clientHeight)
			bottom = (($elem$('page_content').clientHeight - anchor[1] - 17) + 'px');
		else
			top = anchor[1] + 'px';
	}
}

function hideConversions() {
	$elem$('preturi').style.display = 'none';
}

