
// This script should contain slidemenu.html, slidemenu.js and slidemenus.css before you've start modding it
// or adding it to you're website... the documentation has been written to: slidemenu.html
// Created by Henrik Kok Jørgensen / Inlead Media ApS (www.inleadmedia.com)


// We need some global vars - don't change any of theese, unless you've got the magic knowledge to do so :-)
var slideMenuInterval;
var currentSlide = 1;

function slideMenuShow(id)
{
	if (id == currentSlide) return;

	document.getElementById('slideMenuPic'+currentSlide+'').style.display = 'none';
	document.getElementById('slideMenuText'+currentSlide+'').className = 'slideMenuSecondary';	
	
	currentSlide = id;
	
	document.getElementById('slideMenuPic'+currentSlide+'').style.display = 'block';
	document.getElementById('slideMenuText'+currentSlide+'').className = 'slideMenuPrimary';
	
	opacity('slideMenuPic'+currentSlide+'', 20, 100, 10, 15);
//	opacity('slideMenuPic'+currentSlide+'', 0, 100, 1, 100);

//		opacity('slideMenuPic'+currentSlide+'', 100, 0, 500);
//		opacity('slideMenuPic'+id+'', 0, 100, 500);
}

function slideMenuStart()
{
	if (slideMenuInterval) return; 
	slideMenuInterval = setInterval("slideMenuSlide()", slideMenuBreak);
}

function slideMenuStop()
{
	clearInterval(slideMenuInterval);
	slideMenuInterval = null;
}

function slideMenuSlide()
{
	slideMenuShow((currentSlide == slideMenuCount ? 1 : parseInt(currentSlide) + 1)); 
}

var oldTimeoutId = null

function opacity(id, opacStart, opacEnd, intervalJump, millisec)
{
	if (0 == intervalJump) return;
	if (oldTimeoutId)
	{
		clearTimeout(oldTimeoutId);
		oldTimeoutId = null;
	}
	
	// Start by setting the opacity for the element
	changeOpac(opacStart, id);
	
	// Is that is, or do we have to fade some more?
	if (0 < intervalJump && opacStart >= opacEnd) return;
	if (0 > intervalJump && opacStart <= opacEnd) return;
	
	// Call my self again
	if (0 < intervalJump)
	{
		var nextOpac = Math.min((parseInt(opacStart) + parseInt(intervalJump)), parseInt(opacEnd))
	}
	else if (0 > intervalJump)
	{
		var nextOpac = Math.max((parseInt(opacStart) + parseInt(intervalJump)), parseInt(opacEnd))
	}
	if (!nextOpac)
	{
		alert('ERROR undefined nextOpac');
		return;
	}
	oldTimeoutId = setTimeout('opacity(\''+id+'\', '+nextOpac+', '+opacEnd+', '+intervalJump+', '+millisec+');', millisec);
}


//change the opacity for different browsers
function changeOpac(opacity, id) 
{
	//alert(document.getElementById(id).getElementsByTagName('img')[0].src);
	var object = document.getElementById(id).getElementsByTagName('img')[0].style;
//	var object2 = document.getElementById(id).firstChild;
	object.opacity = (opacity/100)-.001;
	object.MozOpacity = (opacity/100)-.001;
	object.KhtmlOpacity = (opacity/100);
	object.filter = "alpha(opacity=" + opacity + ")";
//	alert("Opacity: "+opacity+"\nid: "+id+"\nTagname: "+object2.tagName+"\nclassName: "+object2.className+"\nID: "+object2.id+"\nFilter: "+object.filter+"");
}


//this one is the magic trigger: starts the script
if (0 != slideMenuCount)
{
	setTimeout("slideMenuStart()", slideMenuDelayStart);
}
