function initMenu() {
	menuItem = document.getElementsByTagName('div');
	for (i=0;i<menuItem.length;i++) {
		if (menuItem[i].className == 'menuItem') {
			menuItem[i].onmouseover=function() {
				this.childNodes[1].style.display = 'block';
			}
			menuItem[i].onmouseout=function() {
				this.childNodes[1].style.display = 'none';
			}
		}
	}
}

function initRollover() {
    var buttons = document.getElementsByTagName('div');
    for (var i=0;i<buttons.length;i++) {
        if (buttons[i].className == 'navMain') {
            buttons[i].onmouseover = function() {
                this.style.backgroundImage = "url('http://www.nulldata.net/development/digichart/images/nav_hover.gif')";
            }
            buttons[i].onmouseout = function() {
                this.style.backgroundImage = "url('http://www.nulldata.net/development/digichart/images/nav.gif')";
            }
        }
        if (buttons[i].className == 'navSub') {
            buttons[i].onmouseover = function() {
                this.style.backgroundImage = "url('http://www.nulldata.net/development/digichart/images/nav2_hover.gif')";
            }
            buttons[i].onmouseout = function() {
                this.style.backgroundImage = "url('http://www.nulldata.net/development/digichart/images/nav2.gif')";
            }
        }        
    }
}
function runAnimation() {
    cycle++;
    if (cycle == 1) { slideDown('showbg',417); }
    if (cycle == 2) { fadeIn('title'); }
    if (cycle == 3) { fadeIn('image'); }
    if (cycle == 4) { slideDown('desc',200); }
    else { return; }
}

function resetCurrent() {
    var current = document.getElementById('show');
    current = current.getAttribute('current');
    var title = document.getElementById('showTitle'+current);
    var image = document.getElementById('showImage'+current);
    var text = document.getElementById('showText'+current);
    
    title.style.display = 'none';
    image.style.display = 'none';
    text.style.display = 'none';
    title.style.opacity = 0;
    title.style.filter = 'alpha(opacity=0)';
    image.style.opacity = 0;   
    image.style.filter = 'alpha(opacity=0)';
    cycle = 0;
}

function slideIn(obj) {
    var x = 1;
    var element = document.getElementById(obj);
    element.style.width = 0 + 'px';
    element.style.display = 'block';
    element.style.opacity = 1;
    element.style.filter = 'alpha(opacity=100)';
    widthInt = window.setInterval(function(){x += 2},2);
    sizeInt = window.setInterval(function(){incSize(obj,x)},1);
}

function slideDown(obj,x) {
    var h = 1;
    var element = document.getElementById(obj);
    if (!element) { return; }
    element.style.height = 0 + 'px';
    element.style.display = 'block';
    heightInt = window.setInterval(function(){h += 15},2);
    sizeDownInt = window.setInterval(function(){incHeight(obj,h,x)},1);
}

function incSize(obj,x) {
    var element = document.getElementById(obj);
    if (x >= 420) {
        clearInterval(widthInt);
        clearInterval(sizeInt);
        runAnimation();
        return;
    }    
    element.style.width = x + 'px';
}

function incHeight(obj,h,x) {
    var element = document.getElementById(obj);
    if (h >= x) {
        element.style.height = h + 'px';
        clearInterval(heightInt);
        clearInterval(sizeDownInt);
        runAnimation();
        return;
    }    
    element.style.height = h + 'px';
}

function fadeOut(obj) {
    var opac = 1;
    opacOutInt = window.setInterval(function(){opac -= .03},55);
    fadeOutInt = window.setInterval(function(){decOpac(obj,opac)},50);
}

function fadeIn(obj) {
    var opac = 0;
    var element = document.getElementById(obj);
    element.style.display = 'block';
    opacInInt = window.setInterval(function(){opac += .03},55);
    fadeInInt = window.setInterval(function(){incOpac(obj,opac)},50);
}

function decOpac(obj,x) {
    if (x <= -1) {
        clearInterval(opacOutInt);
        clearInterval(fadeOutInt);
        runAnimation();
        return;
    }
    var element = document.getElementById(obj);
    element.style.opacity = x;
    element.style.filter = 'alpha(opacity='+ (x * 100) +')';
}

function incOpac(obj,x) {
    if (x >= 1) {
        clearInterval(opacInInt);
        clearInterval(fadeInInt);
        runAnimation();
        return;
    }
    var element = document.getElementById(obj);
    element.style.opacity = x;
    element.style.filter = 'alpha(opacity='+ (x * 100) +')';
}

function runInit() {
    cycle = 0;
    initRollover();
    initMenu();
    runAnimation();
}

function showPopup(obj) {
    var element = document.getElementById(obj);
    var dimmer = document.getElementById('dimmer');
    dimmer.style.display = 'block';
    element.style.display = 'block';
}

function hidePopup(obj) {
    var element = document.getElementById(obj);
    var dimmer = document.getElementById('dimmer');
    dimmer.style.display = 'none';
    element.style.display = 'none';
}

window.onload = runInit;