function MM_swapImgRestore() 
{
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("http://www.lincolnharbor.net#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


// Menu preloader
MM_preloadImages(
'/extension/frontline/design/frontline/images/global/search_over.gif',
'/extension/frontline/design/frontline/images/global/register_over.gif',
'/extension/frontline/design/frontline/images/global/go_over.gif',
'/extension/frontline/design/frontline/images/home/frontline_services_over.gif',
'/extension/frontline/design/frontline/images/home/get_to_know_over.gif',
'/extension/frontline/design/frontline/images/home/ask_ace_over.gif',
'/extension/frontline/design/frontline/images/col_right_promos/coupon_download_over.gif',
'/extension/frontline/design/frontline/images/col_right_promos/quarterly_contest_over.gif',
'/extension/frontline/design/frontline/images/col_right_promos/home_submit_your_story_header_over.gif',
'/extension/frontline/design/frontline/images/col_right_promos/home_find_hero_header_over.gif',
'/extension/frontline/design/frontline/images/col_right_promos/home_white_papers_header_over.gif',
'/extension/frontline/design/frontline/images/col_right_promos/home_who_is_xander_kane_header_over.gif',
'/extension/frontline/design/frontline/images/col_right_promos/submit_your_story_header_over.gif',
'/extension/frontline/design/frontline/images/col_right_promos/find_hero_header_over.gif',
'/extension/frontline/design/frontline/images/col_right_promos/white_papers_header_over.gif',
'/extension/frontline/design/frontline/images/col_right_promos/who_is_xander_kane_header_over.gif',
'/extension/frontline/design/frontline/images/characters/thumb_dr_ace_yield_over.gif',
'/extension/frontline/design/frontline/images/characters/thumb_pristine_over.gif',
'/extension/frontline/design/frontline/images/characters/thumb_torque_over.gif',
'/extension/frontline/design/frontline/images/characters/thumb_wizard_over.gif',
'/extension/frontline/design/frontline/images/characters/thumb_flex_over.gif',
'/extension/frontline/design/frontline/images/characters/thumb_flair_over.gif'
);


function erase_text(thisForm, thisItem, thisText)
{
	document.forms[thisForm][thisItem].value = document.forms[thisForm][thisItem].value.replace(thisText, "");
}





// Object utils

// Get a reference to an object
function getObj(id) 
{
    if (document.getElementById) {return document.getElementById(id);}
    else if (document.all)       {return document.all[id];}
    else         {return false;}
}


// Get a reference to the style definition of an object
function getStyleObj(id) 
{
    if (document.getElementById) {return getObj(id).style;} 
    else {return getObj(id);}
}

// Set visibility
function vis_set (item, val) 
{
    var el  = getStyleObj(item); 
    el.visibility = val;
}

// Adjust the alpha of an object
function alpha_set (item, val)
{
    var el  = getStyleObj(item);
    if (document.all) {el.filter = "alpha(opacity=" + val +");";}
    else if (document.getElementById) {el.opacity = parseFloat (val/100);}
}


// These are the functions to set up a quadratic curve to affect a property
/* These quadratic approach is adapted from Robert Penner.
   The code was slightly massaged and cherry-picked to fit into this javascript framework

    A BIG THANKS GOES OUT TO ROBERT PENNER!!!

    robertpenner.com
    news@robertpenner.com
    source@robertpenner.com
*/

// Specs

// Alpha controls
var alpha_min = 0;
var alpha_max = 100;
var alpha_curr = 0;

var object;
var start = 0;
var end = 100;
var item_curr = -99;

// Animation controls
var alpha_val = Array (0, 100);
var alpha_dis = alpha_val[1] - alpha_val[0];
var easing = 0;                                     // controls the quadratic nature of the curve per the midpoint
var duration = 20;                                  // total time of animation
var halftime = duration / 2;                        // the halfway point of the animation
var t = 1;                                          // time counter
var fake_t = 1;                                     // time counter after the halfway point
var direction = 1;                                  // 1 == right, 0 == left
var object = "";
var text_alpha_curr = 0;


// This sets up a loop to change a property of an item
//quad_init (object, start_pos, end_pos, menu_next);
function quad_init (object, start, end, object_num)
{
    //alert ("in quad init for " + object + ", " + object_num);
    
    // Clear all timers
    clearTimeout(this.looper);
    
    // Scope the object vars
    this.object = object;
    this.start = start;
    this.end = end;

    // Easing = 1 for start, and then easing = 2 after you get halfway
    this.easing = 1;
        
    // Save the midpoint of the total duration
    this.halftime = this.duration / 2;

    // Find the total distance to travel
    this.dist = this.end - this.start;

    // Find appropriate acceleration for easing
    this.acc = this.dist / Math.pow(this.halftime, 2);

    // Set time to one
    this.t = 1;
    
    // Start loop
    this.looper = setTimeout ("this.quad_set_prop(" + object_num + ")", 1);

}

function get_delta (time, accel) 
{
    if (this.easing == 1) {return accel * (time - 0.5)}
    else if (this.easing == 2) {return -accel * (time - 0.5 - this.halftime)}
}

function quad_set_prop(object_num)
{
    //alert ("in quad set prop for " + object_num);

    // Switch easing from IN to OUT when over halfway there
    if (this.t > this.halftime) {this.easing = 2; this.fake_t = this.t - this.halftime;} 
    else {this.easing = 1; this.fake_t = this.t;}

    // Add delta to the properties of the object
    // Control opacity of text block
    this.text_alpha_curr += this.get_delta(this.fake_t, this.acc);      
    this.alpha_set("story" + object_num, this.text_alpha_curr);
    
    // Testing
    //document.getElementById("alphaCurr").innerHTML = this.text_alpha_curr;    
    
    // Increment t
    this.t++;
    
    this.looper = setTimeout ("this.quad_loop_check(" + object_num + ")", 1);
}

function quad_loop_check(object_num)
{
    // Check if the trip is complete (t >= duration)
    if (this.t > this.duration) 
    {
        clearTimeout(this.looper);
        
        // Control visibility of the object
        if (this.text_alpha_curr < 1)
        {
            this.vis_set("story" + object_num, "hidden");
        }
    }
    else {this.quad_set_prop(object_num);}
}


// Control what is visible
function control(item)
{
    if (item != this.item_curr)
    {
        // Hide item_curr
        //this.vis_set ("story" + this.item_curr, "hidden");     
        if (this.item_curr != -99) 
        {
            this.alpha_set ("story" + this.item_curr, 0);
            this.alpha_set ("name" + this.item_curr, 0);
            this.alpha_set ("profile" + this.item_curr, 0);
        }
    
        // Control item come into view       
        this.text_alpha_curr = 0;
        this.quad_init ("story" + item, 0, 100, item);        

        this.vis_set ("story" + item, "visible");    
        this.alpha_set ("name" + item, 100);
        this.alpha_set ("profile" + item, 100);
        
        // Update the current item
        this.item_curr = item;
    } 
}



// This function initializes the blocks with a quick alpha transition while they are hidden
function set_blocks()
{
    // Loop through each block
    // Set it to invisible, set alpha to 100
    // Set alpha to 0
    // Set visibility to visible

    for (var i=0; i<2; i++) 
    {
        this.alpha_set ("story" + i, 100);
        this.alpha_set ("story" + i, 0);
        
        this.alpha_set ("name" + i, 100);
        this.alpha_set ("name" + i, 0);
    }   
    
    control(0);
}




function set_blocks_2()
{
    // Loop through each block
    // Set it to invisible, set alpha to 100
    // Set alpha to 0
    // Set visibility to visible

    this.alpha_set ("story0", 100);
    this.alpha_set ("story0", 0);
        
    this.alpha_set ("name0", 100);
    this.alpha_set ("name0", 0);
    
    
    control(0);
}
