var my_fades= new Array();
	my_fades["motion_button_HOME"]= 1;
	my_fades["motion_button_ABOUT_US"]= 1;
	my_fades["motion_button_SERVICES"]= 1;
	my_fades["motion_button_CAREERS"]= 1;
	my_fades["motion_button_NEWS"]= 1;
	my_fades["motion_button_CONTACT_US"]= 1;

var body_fade = 1;

var my_motto= new Array();
	my_motto[0]= "WE MAKE IT RIGHT";
	my_motto[1]= "RIGHT ON TIME DESIGN AT THE RIGHT PLACE";
	my_motto[2]= "INNOVATIVE";
	my_motto[3]= "UNIQUE";
	my_motto[4]= "CUTTING-EDGE TECHNOLOGY";
	my_motto[5]= "STATE-OF-THE-ART";
	
function on_mouse_over_button(id){
	if(my_fades[id] == 1) {	
		fadeOut(id);
	}
}

function caption_change(){
	
	//if(document.getElementById('home_image') == undefined) {	
	//}else {
		//fadeOutCAP('home_caption');	
		//fadeOutCAP('home_caption2');
	//	fadeOutCAP('home_image');
	//}	
}

var old_id_for_button_chosen = 1;
function on_click_button(id){		
		var title;
		if(old_id_for_button_chosen != 1) {
			document.getElementById(old_id_for_button_chosen).className = "motion_button";
		}
		document.getElementById(id).className = "motion_button_chosen";		
		old_id_for_button_chosen = id;
		title = id.substring(14, id.length);
		document.title = "ASIC Depot - " + title.replace("_", " ");
		init();
}

/* set the opacity of the element (between 0.0 and 1.0) */
function setOpacity(level, id) {
  var element = document.getElementById(id);
  element.style.opacity = level;
  element.style.MozOpacity = level;
  element.style.KhtmlOpacity = level;
  element.style.filter = "alpha(opacity=" + (level * 100) + ");";
  my_fades[id] = level;
  if(level >= 0.9999) {
	my_fades[id] = 1;
	body_fade = 0;
  }

}

function fadeIn(id){
/*	var duration = 1000;  /* 1000 millisecond fade = 1 sec */
	var duration = 100;  /* 1000 millisecond fade = 1 sec */
	var steps = 30;       /* number of opacity intervals   */
	var delay = 1000;     /* 5 sec delay before fading out */
  for (i = 0; i <= 1; i += (1 / steps)) {
    setTimeout("setOpacity(" + i + ",  '" + id + "')", i * duration);
  }
 // setTimeout("fadeOut('" + id+ "')", delay);
}

function fadeOut(id) {
/*	var duration = 1000;  /* 1000 millisecond fade = 1 sec */
	var duration = 100;  /* 1000 millisecond fade = 1 sec */
	var steps = 20;       /* number of opacity intervals   */
	var delay = 2000;     /* 5 sec delay before fading out */
  for (i = 0; i <= 1; i += (1 / steps)) {
    setTimeout("setOpacity(" + (1 - i) + ",  '" + id + "')", i * duration);
  }
  setTimeout("fadeIn('" + id+ "')", duration);
}

function setOpacityCAP(level, id) {
  var element = document.getElementById(id);
  element.style.opacity = level;
  element.style.MozOpacity = level;
  element.style.KhtmlOpacity = level;
  element.style.filter = "alpha(opacity=" + (level * 100) + ");";
  my_fades[id] = level;
  if(level <= 0.1) {
	document.getElementById('home_image').innerHTML = '<img src="images/home'+ rand(3) + '.jpg" />';
	document.getElementById('home_caption').innerHTML = my_motto[rand(6)-1];
	document.getElementById('home_caption2').innerHTML = my_motto[rand(6)-1];
  }

}

function rand ( n )
{
  return ( Math.floor ( Math.random ( ) * n + 1 ) );
}

function fadeOutCAP(id) {
	var duration = 1000;  /* 1000 millisecond fade = 1 sec */
	var steps = 20;       /* number of opacity intervals   */
	var delay = 2000;     /* 5 sec delay before fading out */
  for (i = 0; i <= 1; i += (1 / steps)) {
    setTimeout("setOpacityCAP(" + (1 - i) + ",  '" + id + "')", i * duration);
  }
  setTimeout("fadeIn('" + id+ "')", duration);
}

function loadXMLDoc(url)
{
	document.getElementById('body_td_div').innerHTML= '<div align="center"><img src="images/loading42.gif"/></div>';
	
	if(body_fade == 0) {	
		//fadeOut('body_td_div');
	}
	if (window.XMLHttpRequest)
	  {// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
		xmlhttp.open("GET",url,false);
		xmlhttp.send(null);
	  }
	else
	  {// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		xmlhttp.open("GET",url,false);
		xmlhttp.send();
	  }
	document.getElementById('body_td_div').innerHTML=xmlhttp.responseText;	
}



function init(){
	var stretchers = document.getElementsByClassName('box');
	var toggles = document.getElementsByClassName('tab');
	var myAccordion = new fx.Accordion(
		toggles, stretchers, {opacity: false, height: true, duration: 600}
	);
	//hash functions
	var found = false;
	toggles.each(function(h3, i){
		var div = Element.find(h3, 'nextSibling');
			if (window.location.href.indexOf(h3.title) > 0) {
				myAccordion.showThisHideOpen(div);
				found = true;
			}
		});
		if (!found) myAccordion.showThisHideOpen(stretchers[0]);
}



var ContentHeight = 200;
var TimeToSlide = 250.0;

var openAccordion = '';

function runAccordion(index)
{
  var nID = "Accordion" + index + "Content";
  if(openAccordion == nID)
    nID = '';
    
  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 == '') ? null : document.getElementById(openingId);
  var closing = (closingId == '') ? null : document.getElementById(closingId);
 
  if(timeLeft <= elapsedTicks)
  {
    if(opening != null)
      opening.style.height = ContentHeight + 'px';
    
    if(closing != null)
    {
      closing.style.display = 'none';
      closing.style.height = '0px';
    }
    return;
  }
 
  timeLeft -= elapsedTicks;
  var newClosedHeight = Math.round((timeLeft/TimeToSlide) * ContentHeight);

  if(opening != null)
  {
    if(opening.style.display != 'block')
      opening.style.display = 'block';
    opening.style.height = (ContentHeight - newClosedHeight) + 'px';
  }
  
  if(closing != null)
    closing.style.height = newClosedHeight + 'px';

  setTimeout("animate(" + curTick + "," + timeLeft + ",'" 
      + closingId + "','" + openingId + "')", 33);
}


