function init() {
	scrollToFirst();
	details();
	chart();
}

var detailsBoxes = new Array();
function details() {
	var details = document.getElementById('details');
	detailsDivs = details.getElementsByTagName('div');
	for (detailsDivCount = 0; detailsDivCount < detailsDivs.length; detailsDivCount++) {	
		if (detailsDivs[detailsDivCount].className.match(/box/)) {
			detailsBoxes.push(detailsDivs[detailsDivCount]);
		}
	}
	var detailsBoxesCount = detailsBoxes.length;
	if (detailsBoxesCount > 0) {
		details.style.width = detailsBoxesCount * 1000 + 'px';
		detailsBoxes[0].className += ' box_first';
		detailsBoxes[detailsBoxesCount - 1].className += ' box_last';
	}
}


var chartElements = new Array();
var chartElementsCount = 0;
var chartInterval = null;
var chartElementsMotion = 0;
var chartElementsMotionDelay = 0;
var chartAnimationStop = false;

function chart() {
	chartTimeoutDelay = 1000;
	chartElementsMotion = 2;
	chartElementsMotionDelay = 400;
	var chart = document.getElementById('chart');
	var chartDivs = chart.getElementsByTagName('div');
	for (chartDivCount = 0; chartDivCount < chartDivs.length; chartDivCount++) {
		if (chartDivs[chartDivCount].className.match(/element/)) {
			var chartElement = new Object();
			chartElement['element'] = chartDivs[chartDivCount];
			chartElement['element'].style.visibility = 'visible';
			chartElement['bar'] = chartDivs[chartDivCount].getElementsByTagName('div')[0];
			chartElement['height'] = chartElement['bar'].offsetHeight;
			chartElement['bar'].removeAttribute('style');
			chartElements.push(chartElement);
		}
	}
	setTimeout('chartAnimationDelay()', chartTimeoutDelay);
}

function chartAnimationDelay() {
	chartInterval = setInterval('chartAnimation()', 1);
}

function chartAnimation() {
	if (chartElementsCount < chartElements.length) {
		chartElement = chartElements[chartElementsCount];
		chartElementHeight = chartElement['bar'].offsetHeight;
		if (chartElementHeight + chartElementsMotion <= chartElement['height']) {
			chartElementHeight += chartElementsMotion;
			if (chartAnimationStop == true) {
				chartElementHeight = chartElement['height'];
				chartElementsMotionDelay = 50;
			}
			chartElement['bar'].style.height = chartElementHeight + 'px';
		} else {
			clearInterval(chartInterval);
			chartElement['bar'].style.height = chartElement['height'] + 'px';
			chartElement['element'].className += ' element_completed';
			chartElementsCount++;
			setTimeout('chartAnimationDelay()', chartElementsMotionDelay);
		}
	} else {
		clearInterval(chartInterval);
	}
}

var middle = null
var middleDivs = null;
var scrollBoxIds = null;
var scrollBoxIdCount = 0;
var scrollBoxActId = null;
var swf_cubes = null;
var cubesFlash = false;

function scrollToFirst() {
	$j('.content').scrollTo($j('.box:eq(0)'), 0);
}

function scrollToBox(id, flash) {
	if (middle == null) {
		getScrollBoxIds();
		chartAnimationStop = true;
	}
	
	if (flash) { 
		scrollBoxActId = id;
	}
		
	if (scrollBoxIds[id] != null) {
		$j('.content').trigger('goto', scrollBoxIds[id]);
	}
	
	if (swf_cubes == null) {
		swf_cubes = document.getElementById('swf_cubes');
		var cubesTagName = swf_cubes.tagName.toLowerCase();
		if (cubesTagName == 'object') {
			cubesFlash = true;
		}
	}
	if (cubesFlash) {
		setCubesActId(id);
	}
}

function scrollPos(scrollContent, scrollBox) {
	if (scrollBox.id == 'selection') {
		scrollBox.style.left = scrollContent.scrollLeft + 'px';
	} else {
		if (middle == null) {
		getScrollBoxIds();
		}
		document.getElementById('selection').style.left = scrollBox.offsetLeft + 'px';
		if (scrollContent.scrollTop == 0) {
			scrollToFirst();
		}
	}
}

function scrollArrows(scrollBox) {
	if (middle == null) {
		getScrollBoxIds();
	}
	middle.className = '';
	if (scrollBox.id != 'selection') {
		middle.className = 'scroll';
		if (!scrollBox.className.match(/box_first/)) {
			middle.className += ' scroll_prev';
		}
		if (!scrollBox.className.match(/box_last/)) {
			middle.className += ' scroll_next';
		}
		setCubesActId(scrollBox.id);
	}
}

function setCubesActId(id) {
	if (scrollBoxActId != id && id != 'selection') {				
		if (swf_cubes && cubesFlash) {
			swf_cubes.SetVariable('setCubeActId', id);
			scrollBoxActId = id;
		}
	}
}

function getScrollBoxIds() {
	middle = document.getElementById('middle');
	middleDivs = middle.getElementsByTagName('div');
	scrollBoxIds = new Object();
	for (middleDivCount = 0; middleDivCount < middleDivs.length; middleDivCount++) {	
		if (middleDivs[middleDivCount].className.match(/box/)) {
			var scrollBoxId = middleDivs[middleDivCount].id;
			scrollBoxIds[scrollBoxId] = scrollBoxIdCount;
			scrollBoxIdCount++;
		}
	}
}


var slideshowCount = 0;
var slideshowLimit = 1;
var intSlideshow = null;

function slideshow(id, fade) {
	var $old = $j('#' + id + ' img.first');
	var $new = $old.next().length ? $old.next() : $j('#' + id + ' img:first');
	$old.addClass('middle');
	$old.removeClass('first');
	$new.css({opacity: 0.0});
	$new.addClass('first');
	$new.animate({opacity: 1.0}, fade, function() {
		$old.removeClass('middle');
	});
	
	if (slideshowLimit > 0) {
		if (slideshowCount <= slideshowLimit) {
			clearInterval(intSlideshow);
		}
		slideshowCount++;
	}
}

function slideshowInterval(id, fade, pause, limit) {
	document.getElementById(id).className += ' visible';
	
	slideshowLimit = 0;
	if (limit > 0) {
		slideshowLimit = limit;
	}
	intSlideshow = setInterval('slideshow("' + id + '", ' + fade + ')', pause);
}


var page = null;
var pageDivs = new Array();
var noticeDivs = new Array();
var noticeInterval = null;
var noticeDivCount = 0;
var noticeIntervalDelay = 0;

function notices(condition) {
	if (!page) {
		page = document.getElementById('page');
		pageDivs = page.getElementsByTagName('div');
		for (pageDivCount = 0; pageDivCount < pageDivs.length; pageDivCount++) {
			if (pageDivs[pageDivCount].className.match(/notice /)) {
				noticeDivs.push(pageDivs[pageDivCount]);
			}
		}
	}
	clearInterval(noticeInterval);
	noticeIntervalDelay = 500;
	if (condition == 'on') {
		page.className = 'notices';
	} else {
		noticeIntervalDelay = noticeIntervalDelay / 2;
		page.className = '';
	}
	if (noticeDivs.length > 0) {
		noticeInterval = setInterval('noticeAnimation("' + condition + '")', noticeIntervalDelay / 4);
		clearInterval(noticeInterval);
		noticeInterval = setInterval('noticeAnimation("' + condition + '")', noticeIntervalDelay);
	}
}

function noticeAnimation(condition) {
	if (condition == 'on') {
		noticeDivs[noticeDivCount].style.display = 'block';
		noticeDivCount++;
		if (noticeDivCount >= noticeDivs.length) {
			noticeDivCount--;
			clearInterval(noticeInterval);
		}
	} else {
		noticeDivs[noticeDivCount].style.display = 'none';
		noticeDivCount--;
		if (noticeDivCount < 0) {
			noticeDivCount++;
			clearInterval(noticeInterval);
		}
	}
}
