//<!--

// NOTE: NEED TO LEVERAGE THE OTHER, BETTER SCRIPTS...this is very old...

// INTERACTIVE CODE FOR HOME PAGE

// Object utils
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++)
    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];}
}



// Adjust the backgorund of an object
function background_set (item, val)
{
    var el  = getStyleObj(item); 
    if (document.all) {el.backgroundColor = val;}
    else if (document.getElementById) {el.backgroundColor = val;}
    else {el.bgColor = val;}
}


// Get a reference to an object
function getObj(id) 
{
    //alert (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) 
{
   // alert (id);
    if (document.getElementById) {return getObj(id).style;} 
    else {return getObj(id);}
}

// Set visibility
function vis_set (item, val) 
{
    //alert ("setting visibility of " + item + " to " + val);
    var el  = getStyleObj(item); 
    el.visibility = val;
}

// Adjust the alpha of an object
function alpha_set (item, val)
{
    //alert ("setting alpha of " + item + " to " + val);
    var el  = getStyleObj(item);
    if (document.all) {el.filter = "alpha(opacity=" + val +");";}
    else if (document.getElementById) {el.opacity = parseFloat (val/100);}
}

function y_set(item, val)
{
    if (ie4)
    {
        //alert (item);
       // document.all.eval(item).style.top = val;
        document.getElementById(item).style.top = val + "px";  

    }
    else if (nn4)
    {
            
        document.eval(item).top = val;

    }
    else if (dom)
    {
        document.getElementById(item).style.top = val + "px";        
    }
}

function moveit()
{
    //alert ("moveit");
    y_set("thumbTop1", -25);
    //item="thumbTop1";
    //alert (document.all.eval(item).style.top);
}
// 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
*/

// Block Controls
var block_start = 0;
var block_end = 2;
var block_prefix = "tab";
var blocks_arr = new Array();

// Alpha controls
var alpha_min = 0;
var alpha_max = 100;
var alpha_curr = 0;
var alpha_header_curr = 0;

var object;
var start = 0;
var end = 100;
//var item_curr = 1;
//var item_temp = 1;
var item_curr = 0;
var item_temp = 0;

//var item_header_temp = 1;
//var item_header_curr = 1;
var item_header_temp = 0;
var item_header_curr = 0;

var item_header_max = 0;

// Animation controls
var alpha_val = Array (0, 100);
var alpha_dis = alpha_val[1] - alpha_val[0];

var thumb_pos = Array (0, -12); /*start, end*/
var thumb_dis = thumb_pos[0] - thumb_pos[1];
var prop = "x";
var thumb_start = thumb_pos[0];
var thumb_end = thumb_pos[1];
var new_pos = thumb_pos[0];
var thumb_pos_curr = thumb_pos[0];
var anim_ratio = thumb_dis/alpha_dis;





var easing = 0;                                     // controls the quadratic nature of the curve per the midpoint
var duration = 6;                                  // 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;


var slide_show_looper=0;
var slide_show_looper2=0;
var looper=0;
var delay=8000;


function thumb_control (menu, dir)
{
    this.quad_init ("circle4", document.getElementById("circle4").offsetLeft, this.circle_pos[dir], menu);
}


// This sets up a loop to change a property of an item
//quad_init (object, start_pos, end_pos, menu_next);
//this.quad_init ("homePromoLeftItem", this.item_header_curr, 0, 100, this.item_header_curr);
function quad_init (object_prefix, item, start, end, object_num)
{
    object = object_prefix + 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 + ", '" + object_prefix + "')", 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, object_prefix)
{
    //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);      
    
    //alert ("in quad set prop for " + object_num + " with alpha " + this.text_alpha_curr);
    this.alpha_set(object_prefix + object_num, this.text_alpha_curr);
 
    // Control the y-pos of the thumb
    this.thumb_pos_curr = Math.round(this.new_pos*this.anim_ratio) + this.thumb_pos[1];
    this.y_set("thumbTop"+ object_num, this.thumb_pos_curr);
    
    
    // Testing
    //document.getElementById("alphaCurr").innerHTML = this.text_alpha_curr;    
    
    // Increment t
    this.t++;
    
    this.looper = setTimeout ("this.quad_loop_check(" + object_num + ", '" + object_prefix + "')", 1);
}

function quad_loop_check(object_num, object_prefix)
{
    // 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(object_prefix + object_num, "hidden");
        }
    }
    else {this.quad_set_prop(object_num, object_prefix);}
}


// Control what is visible
function control(item)
{
    // Only show the text block that we want
    
    //if (item != 0)
    //{
    
        // Hide the old 
        //this.alpha_set (this.block_prefix + this.item_curr, 0);
        this.vis_set   (this.block_prefix  + this.item_curr, "hidden");
        this.vis_set   ("tabSet"  + this.item_curr, "hidden");
    
        // Control text to become in view       
        this.item_curr = item;
        this.vis_set   (this.block_prefix  + this.item_curr, "visible");
        //this.alpha_set (this.block_prefix + this.item_curr, 100);      
        this.vis_set   ("tabSet"  + this.item_curr, "visible");
        //this.quad_init (this.block_prefix  + this.item_curr, 0, 100, this.item_curr);     
        

        
        // Control the back button and the header       
        //this.vis_set ("cnBack", "visible");
        //this.vis_set ("cnHeader2", "visible");
    //}
//  else
    //{
        // Control back button
        //this.vis_set ("cnBack", "hidden");
        
        // Hide the current text block
        //this.quad_init (this.block_prefix + this.item_curr, 100, 0, this.item_curr);
    //}
}



// 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<this.blocks_arr.length; i++) 
    {
        this.alpha_set (this.block_prefix + this.blocks_arr[i], 100);
        //this.alpha_set (this.block_prefix + this.blocks_arr[i], 0);
        //alert ("block is " + this.block_prefix + this.blocks_arr[i]);      
    }   
}




// Control what is visible
//home_header_control(0,-1,1);
//home_header_control(1,-1,1)
function home_header_control(dir, skip_to, auto_play)
{
    // Capture temporary image in view before modifiying this.item_curr
    this.item_header_temp = this.item_header_curr;
    
    // Set the new this.item_header_curr per dir
    if (dir == 0)  {this.item_header_curr = 0;}
    if (dir == -1) 
    {
        if (this.item_header_curr > 0) 
        {
            this.item_header_curr--;
        }
        else 
        {
            this.item_header_curr = this.item_header_max;
        }
    }
    
    if (dir == 1 && skip_to == -1) 
    {
        if (this.item_header_curr < this.item_header_max) 
        {
            this.item_header_curr++;
        }
        else 
        {
            this.item_header_curr = 0;
        }
        
    }

    if (dir == 1 && skip_to != -1)
    {
        this.item_header_curr = skip_to; 
        auto_play = 0;
        
        // Move the thumbnail that's been rolled over
        
    }
    
       //alert ("dir, item_temp, item_curr, item_max :: " + dir + ", " + item_temp + ", " + item_curr + ", " + this.item_header_max);


    
    if (!(this.item_header_temp == this.item_header_curr && skip_to != -1) && dir != -99)
    {
 
    
        // Hide the current image
        this.vis_set ("homePromoLeftItem" + this.item_header_temp, "hidden");
        this.alpha_set ("homePromoLeftItem" + this.item_header_temp, 0);
        
        // Show the new image
        this.vis_set ("homePromoLeftItem" + this.item_header_curr, "visible");
        this.text_alpha_curr = 0;
        this.alpha_set ("homePromoLeftItem" + this.item_header_curr, 0);
        this.quad_init ("homePromoLeftItem", this.item_header_curr, 0, 100, this.item_header_curr);

        // Un-Highlight the button of the temp image that was in view
        //this.background_set ("button" + this.item_header_temp, this.btn_unhighlight);  
        //this.background_set ("button" + this.item_header_temp, "inherit");
        this.alpha_set ("thumbTop" + this.item_header_temp, 60);
        this.y_set("thumbTop"+ item_header_temp, thumb_pos[0]);

        // Highlight the button of the current image in view
        //this.background_set ("button" + this.item_header_curr, this.btn_highlight);
        this.alpha_set ("thumbTop" + this.item_header_curr, 100);
    }   

    // If auto_play is set to 1, set a timer to continue
    clearTimeout(this.slide_show_looper);
    if (auto_play == 1)
    {
        this.slide_show_looper = setTimeout ("this.home_header_control(1,-1,1)", this.delay);
    }
}


function view_as_slide_show(state)
{
    clearTimeout(this.slide_show_looper);
    clearTimeout(this.slide_show_looper2);
    
    if (state == 1)
    {
        this.slide_show_looper = setTimeout ("this.home_header_control(1)", 1);
        this.slide_show_looper2 = setTimeout ("this.view_as_slide_show(1)", 3200);
    }
    else if (state == 0)
    {
        // do nothing
    }   
}




// Browser detection
var agt       = navigator.userAgent.toLowerCase(); var is_major  = parseInt(navigator.appVersion); var is_minor  = parseFloat(navigator.appVersion); 
var is_nav    = ((agt.indexOf('mozilla') != -1) && (agt.indexOf('spoofer') == -1) &&
                 (agt.indexOf('compatible') == -1) && (agt.indexOf('opera') == -1) && 
                 (agt.indexOf('webtv') == -1));
var is_nav4up = (is_nav && (is_major >= 4)); var is_nav5up = (is_nav && (is_major >= 5)); var is_nav6up = (is_nav5up && (agt.indexOf('netscape/7.') != -1));
var is_nn4    = (is_nav4up && !is_nav5up && !is_nav6up); var is_nn6    = (is_nav4up &&  is_nav5up && !is_nav6up);
var is_ie     = (agt.indexOf("msie") != -1); var is_ie3 = (is_ie && (is_major < 4)); var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.")  == -1));
var is_ie4up  = (is_ie && (is_major == 4));  var is_ie5 = (is_ie && (is_major == 4) &&  (agt.indexOf("msie 5.0") != -1)); 
var is_ie5up  = (is_ie && (is_major == 4) && ((agt.indexOf("msie 5.1") != -1) || (agt.indexOf("msie 5.5") != -1))); 
var is_ie6    = (is_ie && (is_major == 4) &&  (agt.indexOf("msie 6.")  != -1));
var is_ie6up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5up && !is_ie6);
var is_opera  = (agt.indexOf('opera')  != -1); var is_safari = (agt.indexOf('safari') != -1);
var is_win    = ((agt.indexOf("win") != -1) || (agt.indexOf("16bit")!=-1)); var is_mac    = (agt.indexOf("mac")  != -1);
var is_mac10  = (agt.indexOf("mac os x") != -1)
var is_unix   = ((agt.indexOf("x11") != -1) && !is_win && !is_mac);
var nn4_bug   = false;


    // Browser detection for DOM behavior -- use a mix of feature sensing and browser version
    var browserVersion = parseInt(navigator.appVersion);
    ie4 = document.all ? true:false;
    dom = document.getElementById ? true:false;
    nn4 = false;
    if ((navigator.appName.indexOf('Netscape') != -1) && (browserVersion == 4)) {nn4 = true}


//-->
