/* tabbed prodsol */
YAHOO.util.Event.onContentReady("prodsol", function (ev) {
    // Add listeners to links in tabs
    anchors = YAHOO.util.Dom.getElementsByClassName('yuitab', 'a', 'prodsoltabs');
    for (i = 0, len = anchors.length; i < len; i++) {
        anchor = anchors[i];

        // Prevent the tab links from working as links
        YAHOO.util.Event.addListener(anchor, "click", function (evt) {
            YAHOO.util.Event.preventDefault(evt);
        });

        // Style the tabs and their content during mouseover
        YAHOO.util.Event.addListener(anchor, "mouseover", function (evt) {
            id = this.getAttribute("id");
            section = id.substr(7) || "1";
            try {
                // Style the selected tab
                YAHOO.util.Dom.addClass('tablink' + section, 'tabactive');

                // Display desired panel
                YAHOO.util.Dom.addClass('tabcontent' + section, 'ps_content_on');

                // Hide whichever panels were previously visible
                ar = YAHOO.util.Dom.getElementsByClassName('ps_content', 'div', 'prodsol');
                for (i = 0, len = ar.length; i < len; i++) {
                    if (ar[i].getAttribute("id") !== 'tabcontent' + section) {
                        YAHOO.util.Dom.removeClass(ar[i], 'ps_content_on');
                    }
                }

                // Hide whichever tabs were previously selected
                ar = YAHOO.util.Dom.getElementsByClassName('yuitab', 'a', 'prodsoltabs');
                for (i = 0, len = ar.length; i < len; i++) {
                    if (ar[i].getAttribute("id") !== 'tablink' + section) {
                        YAHOO.util.Dom.removeClass(ar[i], 'tabactive');
                    }
                }
            } catch (error) {
                //alert(error.message);
            }
        });
    }
});

/* feature slider */
YAHOO.util.Event.onContentReady("promocontainer", function (ev) {
	
    var tabs = YAHOO.util.Dom.get("promo-nav-1").getElementsByTagName('a');
    var mousedTab = 0;

    // Style the first tab
    YAHOO.util.Dom.addClass("promo1", "current");

    // Create the carousel widget
    var carousel = new YAHOO.widget.Carousel("promocontainer");

    // Adjust the display style of the promo panels
    // By default they're hidden to avoid annoying stacking effect during page load
    // Add listeners to the promo panels
    promos = YAHOO.util.Dom.getElementsByClassName('panel', 'div', 'promocontainer');
    for (i = 0, len = promos.length; i < len; i++) {
        promo = promos[i];
        promo.style.display = "block";
        YAHOO.util.Event.addListener(promo, "mouseover", function (evt) {
            carousel.stopAutoPlay();
        });
        YAHOO.util.Event.addListener(promo, "mouseout", function (evt) {
            carousel.startAutoPlay();
        });
    }

    // Handle tabs when beforeScroll event occurs
    carousel.on("beforeScroll", function (obj) {
        var currentPromo = obj.first + 1;
        var nextPromo = obj.last + 1;
        if (obj.dir == 'forward' && mousedTab == 0) {
            YAHOO.util.Dom.addClass("promo" + nextPromo, "current");
            YAHOO.util.Dom.removeClass("promo" + currentPromo, "current");
        } 
        if (obj.dir == 'backward' && mousedTab == 0) {
            YAHOO.util.Dom.addClass("promo1", "current");
            YAHOO.util.Dom.removeClass("promo" + currentPromo, "current");
        }
    });

    // Add listener to carousel when aferScroll event occurs
    // If tab is moused over, rescroll the carousel when its done scrolling
    carousel.on("afterScroll", function (obj) {
        if (mousedTab !== 0) {
            section = parseInt(mousedTab.substr(5)) - 1;
            carousel.stopAutoPlay();
            carousel.set("animation", { speed: 0 });
            carousel.scrollTo(section);
        }
    });

    // Handle tabs during mouseover event
    YAHOO.util.Event.addListener(tabs, "mouseover", function (evt) {
        // Style this tab
        id = this.getAttribute("id");
        YAHOO.util.Dom.addClass(id, "current");
        mousedTab = id;
        // Destyle other tabs
        for (x = 0, len = tabs.length; x < len; x++) {
            tabid = tabs[x].getAttribute("id");
            if (id !== tabid) {
                YAHOO.util.Dom.removeClass(tabid, "current");
            }
        }
        // Scroll to desired promo
        section = parseInt(id.substr(5)) - 1;
        carousel.stopAutoPlay();
        carousel.set("animation", { speed: 0 });
        carousel.scrollTo(section);
    });

    // Handle tabs during mouseout event
    YAHOO.util.Event.addListener(tabs, "mouseout", function (evt) {
        // Destyle this tab
        id = this.getAttribute("id");
        YAHOO.util.Dom.removeClass(id, "current");
        mousedTab = 0;
        // Restart carousel
        carousel.set("animation", { speed: 1 });
        carousel.startAutoPlay();
    });

    // Configure the carousel and begin it
    carousel.set("autoPlayInterval", 12000);  /* delay in milliseconds */
    carousel.set("animation", { speed: 1 });  /* speed of animation in seconds */
    carousel.set("numVisible", 1);  /* number of panels to display at once */
    carousel.set("isCircular", true);  /* make the widget circular (looping) */
    carousel.render();
    carousel.startAutoPlay();
});

/* "Latest News" scrolling news ticker */
var lineHeight = 25;
var Scroller;

// Default interval between animations
intervalDuration = 5;

// Number of copies of the headlines we'll make
var headlineCopies = 3;

// Pause the scroll = 0, animate the scroll = 1
var pauseScrollingHeadlines = 0;

// Maximum times the scroller will scroll in each loop before fading out
var scrollerLimit = 0;
var computeScrollerLimit = function() {
    var headlineItemsArray = YAHOO.util.Dom.get("scroller").getElementsByTagName('a');
    var headlineItems = headlineItemsArray.length;
    scrollerLimit = headlineItems + (headlineItems * headlineCopies) + 1;
}

function SASscroller(position, height) {
    if (position < scrollerLimit) {
        if (pauseScrollingHeadlines == 0) {
            // Scroll down
            var anim = new YAHOO.util.Scroll('scroller');
            anim.attributes.scroll = {to: [0, height]};
            anim.duration = 1;
            anim.method = YAHOO.util.Easing.easeNone;
            anim.animate();
            // Do this again
            setTimeout('SASscroller(' + (position + 1) + ',' + (height + lineHeight) + ')', intervalDuration * 1000);
        } else if (pauseScrollingHeadlines == 1) {
            // Cursor is over a headline so pause
            setTimeout('SASscroller(' + position  + ',' + height + ')', intervalDuration * 1000);
        }
    } else {
        // Last headline has scrolled into view
        // so now loop back to the first headline.

        // Fade out
        var anim1 = new YAHOO.util.Anim('scroller');
        anim1.attributes.opacity = {from: 1, to: 0 };
        anim1.duration = '.5'; /* speed of animation in seconds */
        anim1.method = YAHOO.util.Easing.easeNone; /* type of animation */
        anim1.animate();

        // Scroll to top
        var anim2 = new YAHOO.util.Scroll('scroller');
        anim2.attributes.scroll = {to: [0, 0]};
        anim2.duration = 0;
        anim2.method = YAHOO.util.Easing.easeNone;

        // Fade in
        var anim3 = new YAHOO.util.Anim('scroller');
        anim3.attributes.opacity = {from: 0, to: 1 };
        anim3.duration = '.5';
        anim3.method = YAHOO.util.Easing.easeNone;

        // Perform the 2nd animation when 1st finishes
        anim1.onComplete.subscribe(function() {
            anim2.animate();
        });

        // Perform the 3rd animation when 2nd finishes
        anim2.onComplete.subscribe(function() {
            anim3.animate();
        });

        // Restart the scoll from the beginning
        setTimeout('SASscroller(2, 25)', intervalDuration * 1500);
    }
}

YAHOO.util.Event.onContentReady("scroller", function (ev) {
	
    // Calculate when to end the loop
    computeScrollerLimit();
    
    // Clone the group of headlines
    Scroller = YAHOO.util.Dom.get("scroller");
    var headlines = YAHOO.util.Dom.getChildren("scroller");
    var i = 1;
    while (i <= headlineCopies) {
        for (b = 0, len = headlines.length; b < len; b++) {
            Scroller.appendChild(headlines[b].cloneNode(true));
        }
        i++;
    }

    // Set variable that pauses scroller during mouseover
    YAHOO.util.Event.addListener(Scroller, "mouseover", function (evt) {
        pauseScrollingHeadlines = 1;
    });
    YAHOO.util.Event.addListener(Scroller, "mouseout", function (evt) {
        pauseScrollingHeadlines = 0;
    });
    
    // Set scroller to initial position
    var anim = new YAHOO.util.Scroll('scroller');
    anim.attributes.scroll = {to: [0, 0]};
    anim.duration = 0;
    anim.method = YAHOO.util.Easing.easeNone;
    anim.animate();

    // Begin the scroll routine
    setTimeout('SASscroller(2, 25)', 5000);
});


function openSurvey() 
{ 
window.open('http://deploy.ztelligence.com/start/survey/survey_taking.jsp?PIN=164B6Z9V6CPFJ','survey','height=675,width=650,scrollbars=no');
}  

