function opacity(id, opacStart, opacEnd, millisec, delay) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;
	
	if (delay == undefined) {
		delay = 0;
	}
	
	// MSIE support
	var browser = window.navigator.userAgent;
	if (browser.indexOf("MSIE") != -1) {
		var object = document.getElementById(id);
		object.style.width = object.offsetWidth + 'px';
		object.style.height = object.offsetHeight + 'px';	
	}

	//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 + delay);
			timer ++;
		}
	} else if (opacStart < opacEnd) {
		for (i = opacStart; i <= opacEnd; i++) {
			setTimeout("changeOpac(" + i + ",'" + id + "')", timer * speed + delay);
			timer ++;
		}
	}
}

function changeOpac(opacity, id) {
	var obj = document.getElementById(id).style;
	changeOpacObj(opacity, obj);
}

function changeOpacObj(opacity, object) {
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function currentOpac(id, opacEnd, millisec, delay) {
	if (delay == undefined) {
		delay = 0;
	}
	
	//if the element has an opacity set, get it
	var currentOpac = 100;
	if (document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}
	
	opacity(id, currentOpac, opacEnd, millisec, delay);
}

var scrollWidth = new Array();

function scrollToWidth (parent, id, position, millisec, delay) {
	var pObj = document.getElementById(parent);
	var iObj = document.getElementById(id);

	var maxscroll = iObj.offsetWidth - pObj.offsetWidth;
	var curpos = Math.abs(parseFloat(iObj.style.left));
	
	if (maxscroll <= 0)
		return;	
	
	if (scrollWidth[id] == undefined) {
		scrollWidth[id] = new Array();
	} else {
		for (i = 0; i < scrollWidth[id].length; i ++) {
			clearTimeout(scrollWidth[id][i]);
		}
		scrollWidth[id] = new Array();
	}

	position = position > maxscroll ? maxscroll : (position < 0 ? 0 : position);
	
	if (delay == undefined) {
		delay = 0;
	}
	
	var timer = 0;
	for (i = curpos; curpos > position ? i > position : i < position; curpos > position ? i -= 3 : i += 3) {
		scrollWidth[id][timer] = setTimeout("document.getElementById(\"" + id + "\").style.left=\"" + (0 - i) + "px\"", timer * millisec + delay);
		timer ++;
	}
	setTimeout("document.getElementById(\"" + id + "\").style.left=\"" + (0 - position) + "px\"", timer * millisec + delay);
}

function scrollWidthRelative (parent, id, alter) {
	var pObj = document.getElementById(parent);
	var iObj = document.getElementById(id);
	
	scrollToWidth(parent, id, Math.abs(parseInt(iObj.style.left)) + alter, 12, 0);
}

var scrollHeight = new Array();

function scrollToHeight (parent, id, position, millisec, delay) {
	var pObj = document.getElementById(parent);
	var iObj = document.getElementById(id);

	var maxscroll = iObj.offsetHeight - pObj.offsetHeight;
	var curpos = Math.abs(parseFloat(iObj.style.top));
	
	if (maxscroll <= 0)
		return;
	
	if (scrollHeight[id] == undefined) {
		scrollHeight[id] = new Array();
	} else {
		for (i = 0; i < scrollHeight[id].length; i ++) {
			clearTimeout(scrollHeight[id][i]);
		}
		scrollHeight[id] = new Array();
	}

	position = position > maxscroll ? maxscroll : (position < 0 ? 0 : position);
	
	if (delay == undefined) {
		delay = 0;
	}
	
	var timer = 0;
	for (i = curpos; curpos > position ? i > position : i < position; curpos > position ? i -= 3 : i += 3) {
		scrollHeight[id][timer] = setTimeout("document.getElementById(\"" + id + "\").style.top=\"" + (0 - i) + "px\"", timer * millisec + delay);
		timer ++;
	}
	setTimeout("document.getElementById(\"" + id + "\").style.top=\"" + (0 - position) + "px\"", timer * millisec + delay);
}

function scrollHeightRelative (parent, id, alter) {
	var pObj = document.getElementById(parent);
	var iObj = document.getElementById(id);
	
	scrollToHeight(parent, id, Math.abs(parseInt(iObj.style.top)) + alter, 12, 0);
}

if (!document.all) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = getMPos;

var mx = 0;
var my = 0;
function getMPos (e) {
	if (document.all) { 
		mx = event.clientX + document.body.scrollLeft
		my = event.clientY + document.body.scrollTop
	} else {
		mx = e.pageX
		my = e.pageY
	}  
	return true;
}

var tooltip_timer;
function tooltip (text) {
	obj = document.getElementById('tooltip');
	obj.style.left = (mx + 12) + 'px';
	obj.style.top = (my + 12) + 'px';
	
	while (obj.firstChild) { obj.removeChild(obj.firstChild); }
	obj.appendChild(document.createTextNode(text));
	
	if(typeof tooltip_timer == "number")
		clearTimeout(tooltip_timer);
	
	obj.style.visibility = 'visible';
	tooltip_timer = setTimeout('hide_tooltip()', 8000);
}

function hide_tooltip () {
	document.getElementById('tooltip').style.visibility = 'hidden';
}
	
function slideShowAdd (id, image_url, width, height) {
	var obj = document.getElementById(id);
	
	var slide = document.createElement("div");
	var image = document.createElement("img");

	image.setAttribute('src', image_url);
	if (width != undefined) {
		image.setAttribute('width', width);
	}
	if (height != undefined) {
		image.setAttribute('height', height);
	}

	slide.appendChild(image);
	
	slide.style.position = 'absolute';
	slide.style.left = '0px';
	slide.style.top = '0px';
	
	slide.id = id + '_slide_' + obj.childNodes.length;
	obj.appendChild(slide);
	
	changeOpac(0, slide.id);
}

function slideShow (id, interval, next, condition) {
	var obj = document.getElementById(id);
	if (interval == undefined) {
		interval = 6 * 1000;
	}
	
	if (!obj.childNodes.length)
		return;
						
	if ((condition == -1 || condition == undefined) || condition == rightSectionView || next == undefined)  {
		if (next == undefined) {
			next = 0;
		} else {
			var prev = next - 1;
			if (prev < 0) {
				prev = obj.childNodes.length - 1;
			}
			opacity(obj.childNodes[prev].id, 100, 0, interval / 5);	
		}	
		opacity(obj.childNodes[next].id, 0, 100, interval / 5);

		if (condition == -1 || condition == undefined || condition == rightSectionView) {
			next ++;
			if (next >= obj.childNodes.length) {
				next = 0;
			}
		}
	} else if (next == undefined) {
		next = 0;
	}
		
	if (condition == undefined)
		condition == -1;
		
	setTimeout('slideShow("' + id + '", ' + interval + ', ' + next + ',' + condition + ')', interval);
}

rightSectionAutoScroll = true;
rightSectionView = 0;

function showNextRightSection (count) {
	if (!rightSectionAutoScroll)
		return;
		
	rightSectionView ++;
	if (rightSectionView >= count)
		rightSectionView = 0;
		
	scrollToWidth('rightsection_container', 'rightsection_in', rightSectionView * 194, 8, 0);
	setTimeout('showNextRightSection('+count+')', 6000);
}

function addPropositions(innerHTML, attributes) {
	var div = document.createElement('div');
	div.innerHTML = innerHTML;
	
	if (attributes != undefined) {
		for (attribute in attributes)
			div.setAttribute(attribute, attributes[attribute]);
	}
	
	var parent = 'propositions_in';
	document.getElementById(parent).appendChild(div);
	document.getElementById(parent).style.width = (parseInt(document.getElementById(parent).style.width) + div.offsetWidth) + 'px';
}
