﻿<!--
/**
 * pageEvents.js
 *
 * Author: Thomas Nicolosi 
 * Contact: thomas@redbuscorp.com
 * Company: Red Bus Corp.
 *
 * Revision: 1.0.0
 * Date: 2009-12-08
 */
function setGridImages(){
    /**
     * This function allows for the use of a single image with squared off corners to used for each grid cell.
     * The images are coded into the href attribute of the img tag. This script moves the image to the background of the
     * containing anchor tag and substitutes a transparent png with rounded corners over the top.
     * The hover state substitutes a transparent png with a highlighted and rounded border.
     * jQuery plug-in jquery.ifixpng.js must be used to allow the png transparency in IE6.
     */
    var theImageSource = $("ul.grid-primary li a img").map(function(){
        //first gather the img elements into an array.
                                                    var each = $(this);
                                                    return each;
                                                    });
    var i = 0;
    var len = theImageSource.length;
    var imageString = "";
    var anchorImage = "";
    var alertString = "";
    for(i = 0; i < len; i++){
        anchorImage = theImageSource[i].parent("a"); //reference the img containing a tag
        imageString = "url(" + theImageSource[i].attr("src") + ")"; //grab the src attribute of the img tag
        anchorImage.css("backgroundImage",imageString); //make the background of the a tag the src of the img
        theImageSource[i].attr("src","images/css/grid-overlay.png").ifixpng();//replace the src of the img tag with the transparent png images/grid-overlay.png
        }
    //set hover behavior
    $("ul.grid-primary li a").hover(function(){
        //this is the hover state
        var theLink = $(this);
        theLink.children("img").attr("src","images/css/grid-overlay-hover.png").ifixpng();//images/grid-overlay-hover.png
        },function(){
        //this is the "off" state
        var theLink = $(this);
        theLink.children("img").attr("src","images/css/grid-overlay.png").ifixpng();//images/grid-overlay.png
        });
    }
function adjustTabText(){
    /**
     * This function adjusts padding for tab text that takes up 2 lines.
     * A <br /> tag is used to force the second line.
     * Anchor text is contained within a span tag.
     */
    var theTabs = $("ul.tabbed-nav li a span").map(function(index){
        //first gather each span tag into an array.
                                                                var eachTab = $(this);
                                                                return eachTab;
                                                                });
    var i = 0;
    var len = theTabs.length;
    var theSpanHtml = "";
    var theStrings = "";
    var theMatch = new RegExp('<br','gi');
    var iSMatch = false;
    for(i = 0; i < len; i++) {
        theSpanHtml = theTabs[i].html();
        iSMatch = theSpanHtml.match(theMatch);
        if(iSMatch){
         theTabs[i].addClass("tab-title-2-line");//if the html within the span contains <br add the class for 2-line
        } else {
            theTabs[i].addClass("tab-title-1-line")}
    };
}
function tabbedContent(){
/**
 * Controls tabbed content areas.
 */
    //$("#tabs").addClass("hidden");
    $("#tabs ul").removeClass("hidden"); //List containing tab titles is hidden if no javascript.
    $("#tabs div.tab-content-container").hide();
    $("#tabs div.first-tab-content").show(); //Show the first tab when page is first loaded.
    $("#tab-1").removeClass("inactive");//$("a#tab-1").removeClass("inactive");
    $("#tab-1").addClass("active");//$("a#tab-1").addClass("active");
    $("#tabs h2").hide();
    //setTimeout(function(){$("#tabs").removeClass("hidden");},1000);
    $("ul.tabbed-nav li a").click(function(){
            var theID = $(this).attr("id");//changed case to lower
            var showPara = "div" + "." + theID;
            $("ul.tabbed-nav li a").removeClass("active");
            $("ul.tabbed-nav li a").addClass("inactive");
            $(this).removeClass("inactive");
            $(this).addClass("active");
            //Cufon.replace('ul.tabbed-nav li a',{hover: 'true',fontFamily: 'HelveticaNeue'}); //Font replacement after class switched.
            $("div.tabs div.tab-content-container").hide();
            $(showPara).show();
            $(this).blur();
            return false;
        });
}
function topnavfirst() {
/**
 * Controls hover state of the first item in the top nav list.
 */
$("li.topnav-first a").hover(
    function(){
        $("div.topnav-inner").removeClass("topnav-inner-hover-off").addClass("topnav-inner-hover");
    },
    function(){
        $("div.topnav-inner").removeClass("topnav-inner-hover").addClass("topnav-inner-hover-off");
    });
}
function closeNotActive() {
    /* Function to close nav lists that are not active. */
    var navList = $("div.wrapper-left-nav ul.left-nav-top li.topLevel").map(function(index){
                                                                                    var nav = $(this);
                                                                                    return nav;
                                                                                    });
    var i = 0;
    var len = navList.length;
    var isActive = false;
    for(i = 0; i < len; i++)
        {
            isActive = navList[i].hasClass("activeList");
            if(!isActive) {
                if(navList[i].hasClass("expanded"))
                    {
                        navList[i].children("ul").hide();
                        navList[i].removeClass("expanded").addClass("closed");
                    }
                }
        }
    return true;
    }
function expandLeftNav() {
    /**
     * After loading the page hide the nested lists and add the class "closed" to the top level
     * to change the bullet.
     */
    $("div.wrapper-left-nav ul li:not(.currentPage) ul").hide();
    $("div.wrapper-left-nav ul.left-nav-top li:not(.currentPage).topLevel").addClass("closed");
    /**
     * Add function to the click event of the anchors in the left nav.
     * Note - make this generic for multiple levels.
    $("div.wrapper-left-nav ul.left-nav-top li.topLevel a").click(function(){
        var clickedListElement = $(this).parent(); //List element that contains anchor that was clicked.
        //var clickedClass = clickedListElement.attr("class");
        if(clickedListElement.hasClass("closed")){
                clickedListElement.addClass("activeList");
                closeNotActive();
                clickedListElement.removeClass("activeList");
                clickedListElement.removeClass("closed").addClass("expanded");
                clickedListElement.children("ul").focus().fadeIn(700).end();
            } else {
                    if(clickedListElement.hasClass("expanded")){
                        clickedListElement.children("ul").focus().fadeOut("slow").end();
                        clickedListElement.removeClass("expanded").addClass("closed").end();
                        };
            };
        return false;
        });
     */
    }
function yearsList(){
/**
 * Redirects to press release page based on dropdown list selection.
 */
 $("select.yearSelect").change(function(){
    var selectValue = $(this).attr("value");
    if (selectValue != 0)
    {
        window.location = selectValue;
        }
    });
}
function replaceCustomFonts(){
/**
 * Font replacement with Cufon.
 * Add line for each new selector that needs replacement.
 */
        Cufon.replace('div.content-main-inner-left h1',{fontFamily: 'HelveticaNeue'});
        Cufon.replace('div.topnav ul li a',{hover: 'true',fontFamily: 'HelveticaNeue'});
        Cufon.replace('ul.tabbed-nav li a',{hover: 'true',fontFamily: 'HelveticaNeue'});
        Cufon.replace('.page-level2 div.tab-list-wrapper ul li a',{hover: 'true',fontFamily: 'HelveticaNeue'});
        //Cufon.replace('.page-primary div.tab-content-right ul li',{hover: 'true',fontFamily: 'HelveticaNeue'});
        //Cufon.replace('.page-primary div.tab-content-right ul li a:not(.plain-link)',{hover: 'true',fontFamily: 'HelveticaNeue'});
        //Cufon.replace('.block-info ul li',{hover: 'true',fontFamily: 'HelveticaNeue'});
        //Cufon.replace('div.wrapper-search-button button',{hover: 'true',fontFamily: 'HelveticaNeue'});
        Cufon.replace('.page-level2 .content-main-inner-right h1',{hover: 'true',fontFamily: 'HelveticaNeue'});
        Cufon.replace('.page-level2 .content-main-inner-right h2',{hover: 'true',fontFamily: 'HelveticaNeue'});
        Cufon.replace('.wrapper-left-nav ul.left-nav-top li a',{hover: 'true',fontFamily: 'HelveticaNeue'});
        //Cufon.replace('ul li#nav-main-section a',{hover: 'true',fontFamily: 'HelveticaNeue'});
        Cufon.replace('a.button-contact span',{hover: 'true',fontFamily: 'HelveticaNeue'});
        Cufon.replace('div.section-block-inner-wrapper h2',{hover: 'true',fontFamily: 'HelveticaNeue'});
        Cufon.replace('div.section-block-right a:not(.item-details,.plain-link)',{hover: 'true',fontFamily: 'HelveticaNeue'});    
    }
var brochuresLink = function(){
    if ( typeof triggerVar !== 'undefined' ){
        if( triggerVar.value === "brochures" ){
            $("table td a").click(function(event){
                    event.preventDefault();
                    var theLink = $(this).attr("href");
                    window.open(
                                theLink,
                                "brochureForm",
                                "width=740, height=1080, resizable=yes, scrollbars=yes");
                });
        }
    }
}
$(document).ready(function(){
 //expandLeftNav();
 tabbedContent();
 topnavfirst();
 //replaceCustomFonts();
 adjustTabText();
 setGridImages();
 yearsList();
 //pageIdent();
brochuresLink();
//zebra-striping tables
 $("div#data-table table.zebra-stripe tr.table-data:odd").addClass("stripe-odd");
//
//Home page html/js slideshow requires home_slideshow.js
//
  $('html').addClass('hasJs');//adjust css for slide show
  preImg = $('<img/>').attr('src',$('#flashBanner ul li:first-child a').attr('title'));//preload first slide image
  $('#flashBanner')//poplulate content
    .prepend('<div class=\'bannerContainerNav\'></div>')//bottom nav bar
    .prepend('<div class=\'bannerBkg\'></div>')//slide image
    .prepend('<a href=\'#\' class=\'bannerLnk\'></a>');//slide link
  $('.bannerContainerNav').html($('#flashBanner ul'));//set navigation
  $('.bannerContainerNav ul li a').click(navClick);//set navigation link
  $activeSlide = $('#flashBanner ul li:first-child');//set first slide
  $('#flashBanner').animate({'opacity':'1.0'},300);//fade in slide show pieces
});
$(window).bind('load',function(){
  $('#flashBanner li a').each(function(){//preload slide show images
    preImg = $('<img/>').attr('src',$(this).attr('title'));
  });
  changeSlide();
  rotateBanner();
});
//-->
