/* 
 *  Beyel Crane Slideshow
 *
 *  AB Roll
 *  ------- 
 * require: slidea slideb basea baseb texta textb
 * Z-index 10 11 20 21 30 31
 * DO:
 * * Copy B's to A's
 * * Reposition A
 * * Reposition B
 * * Reassign B
 * * Move B
 * * Done
 */

var xwd = 546;
var xhd = 257;

var CurrSlide = 1;
var NextSlide = 2;
var srcfrm = new Array();


srcfrm[1] = "/src/ssimg/slide01.jpg";
srcfrm[2] = "/src/ssimg/slide02.jpg";
srcfrm[3] = "/src/ssimg/slide03.jpg";
srcfrm[4] = "/src/ssimg/slide04.jpg";
srcfrm[5] = "/src/ssimg/slide05.jpg";
srcfrm[6] = "/src/ssimg/slide06.jpg";
srcfrm[7] = "/src/ssimg/slide07.jpg";

srcsub[1] = "Comprehensive fleet of equipment";
srcsub[2] = "Trustworthy";
srcsub[3] = "Rooted in the 1900's";
srcsub[4] = "Exceptional Service";
srcsub[5] = "Branches and sales offices throughout Florida";
srcsub[6] = "Beyel Brothers Inc";
srcsub[7] = "Beyel Brothers";

srctxt[1] = "Crane Rental, Marine Services, Heavy Haul, Special Project";
srctxt[2] = "We keep our promises";
srctxt[3] = "A century of quality service";
srctxt[4] = "24 hours a day 7 days a week 52 weeks a year";
srctxt[5] = "National Presence";
srctxt[6] = "We sell nothing but excellence.";
srctxt[7] = "Reaching new heights";

var yLoca = 0;
var xLoca = -550;

var xLocb = 0;
var yLocb = 0;

var xLocta = -570
var yLocta = 70

var xLoctb = 30
var yLoctb = 70

var xLocza = 1570
var yLocza = 140

var xLoczb = 130
var yLoczb = 140

// xStr r1, Copyright 2001-2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL

function xStr(s)
{
  for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])!='string') return false;}
  return true;
}

// xDef r1, Copyright 2001-2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL

function xDef()
{
  for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])=='undefined') return false;}
  return true;
}

// xOpacity r1, Copyright 2006-2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL

function xOpacity(e, o)
{
  var set = xDef(o);
  //  if (set && o == 1) o = .9999; // FF1.0.2 but not needed in 1.5
  if(!(e=xGetElementById(e))) return 2; // error
  if (xStr(e.style.opacity)) { // CSS3
    if (set) e.style.opacity = o + '';
    else o = parseFloat(e.style.opacity);
  }
  else if (xStr(e.style.filter)) { // IE5.5+
    if (set) e.style.filter = 'alpha(opacity=' + (100 * o) + ')';
    else if (e.filters && e.filters.alpha) { o = e.filters.alpha.opacity / 100; }
  }
  else if (xStr(e.style.MozOpacity)) { // Gecko before CSS3 support
    if (set) e.style.MozOpacity = o + '';
    else o = parseFloat(e.style.MozOpacity);
  }
  else if (xStr(e.style.KhtmlOpacity)) { // Konquerer and Safari
    if (set) e.style.KhtmlOpacity = o + '';
    else o = parseFloat(e.style.KhtmlOpacity);
  }
  return isNaN(o) ? 1 : o; // if NaN, should this return an error instead of 1?
}

// xGetElementById r2, Copyright 2001-2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL

function xGetElementById(e)
{
  if(typeof(e)=='string') {
    if(document.getElementById) e=document.getElementById(e);
    else if(document.all) e=document.all[e];
    else e=null;
  }
  return e;
}

// xAnimation r3, Copyright 2006-2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL

function xAnimation(r)
{
  this.res = r||10;
}
xAnimation.prototype.init = function(e,t,or,ot,oe,a,b)
{
  var i = this;
  i.e = xGetElementById(e);
  i.t = t;
  i.or=or; i.ot=ot; i.oe=oe;
  i.a = a||0;
  i.v = xAnimation.vf[i.a];
  i.qc = 1 + (b||0);
  i.fq = 1/i.t;
  if (i.a) {
    i.fq *= i.qc * Math.PI;
    if (i.a == 1 || i.a == 2) { i.fq /= 2; }
  }
  else { i.qc = 1; }
  i.xd=i.x2-i.x1; i.yd=i.y2-i.y1; i.zd=i.z2-i.z1;
};
xAnimation.prototype.run = function(r)
{
  var i = this;
  if (!r) i.t1 = new Date().getTime();
  if (!i.tmr) i.tmr = setInterval(
    function() {
      i.et = new Date().getTime() - i.t1;
      if (i.et < i.t) {
        i.f = i.v(i.et*i.fq);
        i.x=i.xd*i.f+i.x1; i.y=i.yd*i.f+i.y1; i.z=i.zd*i.f+i.z1;
        i.or(i);
      }
      else {
        clearInterval(i.tmr); i.tmr = null;
        if (i.qc%2) {i.x=i.x2; i.y=i.y2; i.z=i.z2;}
        else {i.x=i.x1; i.y=i.y1; i.z=i.z1;}
        i.ot(i);
        var rep = false;
        if (typeof i.oe == 'function') rep = i.oe(i);
        else if (typeof i.oe == 'string') rep = eval(i.oe);
        if (rep) i.resume(1);
      }
    }, i.res
  );
};
xAnimation.vf = [
  function(r){return r;},
  function(r){return Math.abs(Math.sin(r));},
  function(r){return 1-Math.abs(Math.cos(r));},
  function(r){return (1-Math.cos(r))/2;}
];
xAnimation.prototype.pause = function()
{
  clearInterval(this.tmr);
  this.tmr = null;
};
xAnimation.prototype.resume = function(fs)
{
  if (typeof this.tmr != 'undefined' && !this.tmr) {
    this.t1 = new Date().getTime();
    if (!fs) {this.t1 -= this.et;}
    this.run(!fs);
  }
};

// xAniOpacity r1, Copyright 2006-2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL

function xAniOpacity(e, o, t, a, oe)
{
  if (!(e=xGetElementById(e))) return;
  var o0 = xOpacity(e); // start value
  var dx = o - o0; // displacement
  var fq = 1 / t; // frequency
  if (a) fq *= (Math.PI / 2);
  var t0 = new Date().getTime(); // start time
  var tmr = setInterval(
    function() {
      var et = new Date().getTime() - t0; // elapsed time
      if (et < t) {
        var f = et * fq; // constant velocity
        if (a == 1) f = Math.sin(f); // sine acceleration
        else if (a == 2) f = 1 - Math.cos(f); // cosine acceleration
        f = Math.abs(f);
        xOpacity(e, f * dx + o0); // instantaneous value
      }
      else {
        clearInterval(tmr);
        xOpacity(e, o); // target value
        if (typeof oe == 'function') oe(); // 'onEnd' handler
        else if (typeof oe == 'string') eval(oe);
      }
    }, 10 // timer resolution
  );
}

function ABRoll ()
{
    var frma = document.getElementById("slidea");
    var frmb = document.getElementById("slideb");
    var basa = document.getElementById("basea");
    var suba = document.getElementById("subta");
    var txta = document.getElementById("texta");

// Given A is now B is next
// Fade in B
    setTimeout ("xAniOpacity('slideb', 1, 1000)", 1000);

// Assign A = B
    setTimeout("aisb()",2000);
//    alert (CurrSlide);

// Slide text out
    setTimeout ("xSlideTo('texta',"+xLocza+", "+yLocza+", 1000)", 600);  

// Slide Subhead out
    setTimeout ("xSlideTo('subta',"+xLocta+", "+yLocta+", 1000)", 500);  

// slide Base out
    setTimeout ("xSlideTo('basea',"+xLoca+", "+yLoca+", 1000)", 800);  

// fade background

// Assign new value to text
    setTimeout ("NewValues()",1400);

// slide base in
    setTimeout ("xSlideTo('basea',"+xLocb+", "+yLocb+", 1000)", 2000);  

// slide Subhead in
    setTimeout ("xSlideTo('subta',"+xLoctb+", "+yLoctb+", 1000)", 2500);  

// slide text in
    setTimeout ("xSlideTo('texta',"+xLoczb+", "+yLoczb+", 1000)", 3000);  
// Fade out B
    setTimeout("xAniOpacity('slideb', 0, 1000);",7000);

// Assign B = next
    frmb.src = srcfrm[NextSlide];

    // Increment the Current Slide
    CurrSlide++;
    if (CurrSlide >= srcfrm.length) {
	CurrSlide = 1;
    }
    NextSlide = CurrSlide + 1;
    if (NextSlide >= srcfrm.length) {
	NextSlide = 1;
    }
    setTimeout("ABRoll()", 8000);
}

function aisb () {
    var frma = document.getElementById("slidea");
    var frmb = document.getElementById("slideb");
    frma.src = frmb.src;
}

function NewValues () {
    var suba = document.getElementById("subta");
    var txta = document.getElementById("texta");
    suba.innerHTML = srcsub[CurrSlide];
    txta.innerHTML = srctxt[CurrSlide];
}
