﻿// Accordion
////////////////////////

// functions to get scroller location
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}

function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}
///////////////////////////////////////

AccHeight=new Array();
AccHeight=[3420,1820,1755,2302,730];
var TimeToSlide = 800;
var openAccordion = 0; // no accordion opened
var screenHeight=500;

function runAccordion(index)
{ 
if (gallery[index-1]) {initGallery(index);}; // initialize only pages with gallery (index 4 is gallery [3] etx.)
ContentHeight = AccHeight[index-1];
//var nID = "Accordion" + index + "Content";
  var nID = index;
  if(openAccordion == nID) nID = 0;

  setTimeout("animate(" + new Date().getTime() + "," + TimeToSlide + ",'" + openAccordion + "','" + nID + "')", 33);
  
  openAccordion = nID;
}

function animate(lastTick, timeLeft, closingId, openingId)
{  
  var curTick = new Date().getTime();
  var elapsedTicks = curTick - lastTick;
  var opening = (openingId == 0) ? null : document.getElementById("Accordion" + openingId + "Content");
  var closing = (closingId == 0) ? null : document.getElementById("Accordion" + closingId + "Content");
 
  if(timeLeft <= elapsedTicks)
  {
    if(opening != null)
      opening.style.height = ContentHeight + 'px';
    
    if(closing != null)
    {
      closing.style.display = 'none';
      closing.style.height = '0px';
    }
  	document.flashfile1.GotoFrame(0);
  	document.flashfile3.GotoFrame(0);
  	document.flashfile4.GotoFrame(0);
	//callFlashPlayVideo(index); // for current accordion: replace with "Rewind" or "Stop" etc.
	//document.getElementById("Accordion"+(openingId-1)+"Title").scrollIntoView(true)
	//if (closingId)&&(closingId<openingId) {
		if (openingId==5){
			location.href=("#movie_2"); // about needs to scroll up so the photo will show completely
		} 
		if (closingId>0) {
			if (closingId<openingId) {location.href=("#movie_"+openingId);}
		}
	//	
	//};
    return;
  }
 
  timeLeft -= elapsedTicks;
  //var newClosedHeight = Math.round((timeLeft/TimeToSlide) * ContentHeight);
	newClosedHeight = (Math.round((timeLeft/TimeToSlide) * screenHeight));
	
  if(opening != null)
  {
    if(opening.style.display != 'block')
      opening.style.display = 'block';
      opening.style.height = (screenHeight - newClosedHeight) + 'px';
	  
	//document.getElementById("Accordion"+(openingId-1)+"Title").scrollIntoView(true)
}
  
  if(closing != null)
    closing.style.height = newClosedHeight + 'px';

  setTimeout("animate(" + curTick + "," + timeLeft +",'" + closingId + "','" + openingId + "')", 33);
}
