//<!--

// 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;}
}


function border_color_set (item, val)
{
    var el  = getStyleObj(item); 
    if (document.all) {el.borderColor = val;}
    else if (document.getElementById) {el.borderColor = val;}
    else {el.borderColor = val;}
}

function type_face (item, val)
{
    var el  = getStyleObj(item);
    if (document.all) {el.fontWeight = val;}
    else if (document.getElementById) {el.fontWeight = val;}
}


function type_color (item, val)
{
    var el  = getStyleObj(item);
    if (document.all) {el.color = val;}
    else if (document.getElementById) {el.color = 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);}
}


// 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 = 0;
var item_temp = 0;

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 easing = 0;										// controls the quadratic nature of the curve per the midpoint
var duration = 40;									// 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=7000;

// 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);
 

	
	// 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;}
    
       //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.border_color_set ("button" + this.item_header_temp, this.border_unhighlight); 

        // Highlight the button of the current image in view
        this.background_set ("button" + this.item_header_curr, this.btn_highlight);
        this.border_color_set ("button" + this.item_header_curr, this.border_highlight);
    }   

    // 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
    }   
}


function control_expo (expo)
{
    if (expo == 1)
    {
        this.vis_set ("expoSeason1", "visible");
        this.vis_set ("expoSeason2", "hidden");
               
        this.type_color ("expoLink1", "#ea303e"); 
        this.type_color ("expoLink2", "#0a94d6");         
        
    }
    else if (expo == 2)
    {
        this.vis_set ("expoSeason1", "hidden");
        this.vis_set ("expoSeason2", "visible");    
        
        this.type_color ("expoLink1", "#0a94d6"); 
        this.type_color ("expoLink2", "#ea303e");
    }
}






//-->
