﻿/****** To minify this file, go to: http://refresh-sf.com/yui/ ******/

var flashReady = false;
var pageURL = window.location.protocol + "//" + window.location.host + window.location.pathname;
pageURL = pageURL.substr(0, pageURL.lastIndexOf("/") + 1);

//function eiReady() {
//    flashReady = true;
//    clearInterval();
//}

jQuery(document).ready(function () {

   


    //make flash visible so it can return flashReady
    //$('#contentContainer #topBox .WOflash').css("position", "absolute").css("top", "0px").css("height", "1px").css("width", "1px");
    //$('#contentContainer #topBox .item').css("position", "absolute").css("z-index", "10");

    //External Controls
    function mycarousel_initCallback(carousel) {
        jQuery('.jcarousel-control a').bind('click', function () {
            carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
            jQuery(".jcarousel-control a").removeClass('selected');
            jQuery(this).addClass('selected');
            return false;
        });

        jQuery('.jcarousel-scroll select').bind('change', function () {
            carousel.options.scroll = jQuery.jcarousel.intval(this.options[this.selectedIndex].value);
            return false;
        });

        // Pause autoscrolling if the user puts the cursor over the clip.
        carousel.clip.hover(function () {
            carousel.stopAuto();
        }, function () {
            carousel.startAuto();
        });

        // Pause autoscrolling if the user puts the cursor over the anchor.
        jQuery('.jcarousel-control a').hover(function () {
            carousel.stopAuto();
        }, function () {
            carousel.startAuto();
        });
    };

    function mycarousel_itemFirstInCallbackBeforeAnimation(carousel, item, idx) {
        //remove selected class from anchor
        jQuery(".jcarousel-control a").removeClass('selected');
        $(".jcarousel-clip").animate({
            opacity: 0.7
        }, 0);

        /** END Flash Animation ***/

        //        if (flashReady == false) {
        //            //alert("Please wait a few moments until the page has loaded and try again. - hidden");
        //            setInterval("eiReady()", 500);

        //        }
        //        else {

        //            flashIDNum = idx;
        //            var flashObj = document.getElementById('flashMovie' + flashIDNum);
        //            if (flashObj) {
        //                flashObj.eiHidden();
        //            }
        //        }
        return false;

    };

    //add class to external control link to show which item is currently visible
    function mycarousel_itemFirstInCallbackAfterAnimation(carousel, item, idx) {
        $(".jcarousel-clip").animate({
            opacity: 1
        }, 1000);
        switch (idx) {
            case 1:
                itemNum = "#carousel1";
                break;
            case 2:
                itemNum = "#carousel2";
                break;
            case 3:
                itemNum = "#carousel3";
                break;
            case 4:
                itemNum = "#carousel4";
                break;
            case 5:
                itemNum = "#carousel5";
                break;
            case 6:
                itemNum = "#carousel6";
                break;
            default:
                itemNum = "#carousel1";
        }
        jQuery(".jcarousel-control a" + itemNum).addClass('selected');

        /*** START animation ***/
        //        if (flashReady == false) {
        //            //alert("Please wait a few moments until the page has loaded and try again. - Visible");
        //            setInterval("eiReady()", 500);
        //        }
        //        else {
        //            flashIDNum = idx;

        //remove class that hide swfs off screen - needed so that flash can become 'ready'
        //$('#contentContainer #topBox .WOflash').css("position", "static").css("top", "auto").css("width", "640px").css("height", "200px");

        //            var flashObj = document.getElementById('flashMovie' + flashIDNum);
        //            if (flashObj) {
        //                flashObj.eiVisible();
        //            }
        //       }

    };

    //get rid of no javascript class and styles
    $("div").removeClass("NoJS");
    //Make carousel
    jQuery("#mycarousel").jcarousel({
        //vertical: true,
        scroll: 1,
        auto: 20,
        visible: 1,
        animation: 0,
        wrap: "both",
        initCallback: mycarousel_initCallback,
        itemFirstInCallback: {
            onBeforeAnimation: mycarousel_itemFirstInCallbackBeforeAnimation,
            onAfterAnimation: mycarousel_itemFirstInCallbackAfterAnimation
        },
        // This tells jCarousel NOT to autobuild prev/next buttons
        buttonNextHTML: null,
        buttonPrevHTML: null
    });

    

    function mycarousel_initCallback_new(carousel) {
        // Pause autoscrolling if the user moves with the cursor over the clip.
        carousel.clip.hover(function () {
            carousel.stopAuto();
        }, function () {
            carousel.startAuto();
        });
    };
    /*jQuery("#mycarousel-new").jcarousel({
            animation: 'fast',
            easing: 'swing',
            scroll: 1,
            visible: 1,
            auto: 20,
            wrap: 'both',
            initCallback: mycarousel_initCallback_new,
            // This tells jCarousel NOT to autobuild prev/next buttons
            buttonNextHTML: null,
            buttonPrevHTML: null
        });
   */

});
