(function ($) {
    var feedIdx = 0;
    var tweetIdx = 0;
    var latestTweetId = null;

    function formatText(index, panel) {
        return index + "";
    };


    function createSWFObject(_url) {
        // create video with default controls
        //BrandedName_5-17-11
        var BASE_URL = "http://www.census.gov/";  /* http://cww/ */   /*   need actual location */

        var flashvars = {};
        flashvars.ccMediaName = BASE_URL + "/slider_pm/video/" + _url + ".flv";    /*  need actual location  */
        flashvars.ccCaptionSource = BASE_URL + "/slider_pm/xml/captions/foo.xml";  /*  need actual location  */
        flashvars.ccPosterImage = BASE_URL + "cnmp/img/censusgov_slider_video2.jpg";     /*  need actual location  */
        flashvars.ccMediaAutoStart = "false";
        flashvars.ccMediaBufferTime = "3";
        flashvars.ccMediaWidth = "304";
        flashvars.ccMediaHeight = "150";
        flashvars.ccMediaRewind = "true";
        flashvars.ccCaptSourceType = "external";
        flashvars.ccCaptionLanguage = "en";
        flashvars.ccCaptionAutoHide = "false";
        flashvars.ccOverrideFileStyle = "false";
        flashvars.ccScaleVideo = "true";
        flashvars.ccEmbedSource = "";
        flashvars.ccPlayerControls = "/main/swf_flv/ccControls_coda_slider.swf"; /*  assets/swf/ccControls_coda_slider.swf  */    /*  need actual location  */
        //flashvars.ccMediaStream = "rtmp://stream.2010.census.gov/ondemand/video/stream/";
        var params = {};
        params.movie = "/main/swf_flv/ccPlayerAS3.swf";  /*   assets/swf/ccPlayerAS3.swf   */   /*  need actual location  */
        params.play = "true";
        params.menu = "false";
        params.quality = "best";
        params.scale = "exactfit";
        params.wmode = "transparent";
        params.allowfullscreen = "true";
        params.allowscriptaccess = "sameDomain";
        var attributes = {};
        attributes.id = "census_video_player_lg";
        attributes.name = "census_video_player_lg"

        swfobject.embedSWF("/main/swf_flv/ccPlayerAS3.swf", _url, "304", "221", "9.0.0", false, flashvars, params, attributes);   /*  need actual location  */
    }

    function sliderFeedSuccess(xml) {
        $("#slider").append('<ul></ul>');

        $(xml).find("slide").each(function () {

            var isVideo = $(this).children("video").text().length > 0;
            var innerHTML = "\n" + '<li>';
                
            if(isVideo){
                innerHTML += '<div id="' + $(this).children("video").text() + '"></div>';
            } else {
                innerHTML += '<a href="'+$(this).children("link").text()+'"><img src="' + $(this).children("image").text() + '" alt="' + $(this).children("alt").text() + '" /></a>';
            }

                innerHTML += '<span class="infoBox"><h3><a href="'+ $(this).children("link").text()+'">' + $(this).children("headline").text() + '</a></h3>';
                innerHTML += $(this).children("description").text() + '<br /><br /><a href="';
                innerHTML += $(this).children("link").text() + '"><img src="/cnmp/img/see_more_arrow.gif" alt="Read More on ' + $(this).children("headline").text() + '" /></a></span></li>';

            $("#slider ul").append(innerHTML);

            if(isVideo){
                createSWFObject( $(this).children("video").text() );
            }
        });

        $('.anythingSlider').anythingSlider({
            easing: "easeInOutExpo",        // Anything other than "linear" or "swing" requires the easing plugin
            autoPlay: true,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
            delay: 8000,                    // How long between slide transitions in AutoPlay mode
            startStopped: false,            // If autoPlay is on, this can force it to start stopped
            animationTime: 900,             // How long the slide transition takes
            hashTags: true,                 // Should links change the hashtag in the URL?
            buildNavigation: true,          // If true, builds and list of anchor links to link to each slide
            pauseOnHover: false,             // If true, and autoPlay is enabled, the show will pause on hover
            navigationFormatter: formatText, // Details at the top of the file on this use (advanced use)
            forwardText: "&gt;",            // Link text used to move the slider forward
            backText: "&lt;"                // Link text used to move the slider back
        });
    }

    $(document).ready(function () {
        $('#slider').data('ajaxQueue', [
      {
          type: 'GET', //Was POST
          url: '/cnmp/xml/mainslideshow.xml',
          dataType: 'xml',
          cache: false,
          success: sliderFeedSuccess
      }
    ]).ajaxQueue();
    });
})(jQuery);
