var current_step = 1;
var interval_amt = 7000;
var steps;
var tickit;
var popup_interval;
var popup_alpha;


function loaded_slideshow()
{
	step0pic = document.getElementById('steppic_0');
	bigplay = document.getElementById('bigPlay');
	bigplay.style.left = findPosX(step0pic) + (step0pic.width / 2) - 30 + 'px';
	bigplay.style.top = findPosY(step0pic) + (step0pic.height / 2) - 20 + 'px';
	show_elt('bigPlay');
}

function start_slideshow()
{

	//alert('start');
	

	stepdiv = document.getElementById('steps');
	steps = stepdiv.childNodes;
	no_steps = steps.length - 1;
	
	if (current_step >= no_steps)
	{
		current_step = 0;
	}
	else
	{
		current_step= 1;
	}

	hide_elt('bigPlay');
	hide_elt('fin');
	hide_elt('startBimble');
	hide_elt('resumeBimble');
	show_elt('pauseBimble');
	show_elt('step_0');

	hide_elt('step_' + no_steps);
	
	tickit = setInterval("step_tick()",interval_amt);
}

function pause_slideshow()
{
	clearInterval(tickit); 
	hide_elt('pauseBimble');
	hide_elt('startBimble');
	show_elt('resumeBimble');
}

function resume_slideshow()
{
	tickit = setInterval("step_tick()",interval_amt);
	hide_elt('startBimble');
	hide_elt('resumeBimble');
	show_elt('pauseBimble');
}

function step_tick()
{
	//window.status = 'step_' + current_step;
	
	hide_elt('bigPlay');
	hide_elt('step_' + (current_step - 1));
	show_elt('step_' + current_step);

	current_step = current_step + 1;

	if (current_step >= steps.length)
	{
		//clearInterval(tickit); 
		last_step = current_step - 1;
		current_step = 0;
		hide_elt('pauseBimble');
		hide_elt('resumeBimble');
		show_elt('startBimble');
		clearInterval(tickit); 
		tickit2 = setTimeout("fin(last_step)", interval_amt);
	}
	
}


function fin(last_tick)
{
	firstpic = document.getElementById('steppic_0');
	steppic = document.getElementById('steppic_'+(last_tick));
	fin = document.getElementById('fin');
	fin.style.left = findPosX(steppic) + (steppic.width / 2) - (144/2) + 'px';
	fin.style.top = findPosY(steppic) + (steppic.height / 2) - (99/2) + 'px';
	show_elt('fin');
	
	fade_elt('fin',200);
}

function fade_elt(popup_name, wait_ticks)
{
	popup = document.getElementById(popup_name);
	popup_interval = setInterval("fade_tick('"+popup_name+"')",30);
	popup_alpha = 100 + wait_ticks; 

}



function fade_tick(popup_name)
{
	popup = document.getElementById(popup_name);
	
	if (popup_alpha < 100)
	{
		popup.style.opacity = (popup_alpha / 100);
		popup.style.filter = "alpha(opacity=" + popup_alpha + ")";	
	}

	popup_alpha = popup_alpha - 2;

	if (popup_alpha == 0)
	{
		clearInterval(popup_interval);
		hide_elt(popup_name);
		popup.style.opacity = 1;	
		popup.style.filter = "alpha(opacity=100)";
	}
}


function show_elt(elt)
{
	the_elt = document.getElementById(elt);
	if (the_elt)
	{
		the_elt.className = the_elt.className.replace("hide", "show");
	}
}

function hide_elt(elt)
{
	the_elt = document.getElementById(elt);
	
	if (the_elt)
	{
		the_elt.className = the_elt.className.replace("show", "hide");
	}
}




function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }
