

try {
	gloader.load(["glow", "1", "glow.widgets", "glow.widgets.Carousel"],
            {
                    async: 	true,
                    onLoad: function(glow){

                            var $ = glow.dom.get;

                            glow.ready(function() {
                                    // Get all the carousels on a page
                                    var carousels = $('.photoCarousel ol, .audioCarousel ol');

                                    // Get the last item in the Carousel item and move it to the first place
                                    function moveToFront(orderedList){
                                            // When the carousel panel generates, the 2nd item in the list looks like it's the first visually as we
                                            // We have set the carousel size to 3 as most of the first item is hidden to the left,
                                            // We push the first item to the second place and let glow do it's magic (there's no function in glow to specify a nav start point)
                                            var lastCrslItem = $(orderedList).get("li")[$(orderedList).get("li").length -1];
                                            $(lastCrslItem).prependTo(orderedList);
                                    }


                                    // Build all the carousels on a page
                                    function buildCarousels(carousels, carouselConfig, carouselHolderLeft, pageNavMarginLeft, carouselWindowWidth, carouselWindowListLeft) {
                                            var carouselId = [];
                                            for(var i=0; i < carousels.length; i++){
                                                    moveToFront(carousels[i]);
                                                    carouselId[i] = new glow.widgets.Carousel(carousels[i], carouselConfig);
                                                    // Move the carousel to the left
                                                    if (carouselHolderLeft != null)
                                                        carouselId[i].element.get('.carouselHolder').css('left',carouselHolderLeft);
                                                    // Set the position of the buttons to where we want it (removing this takes it offscreen)
                                                    if ((pageNavMarginLeft != null) && ("undefined" != typeof carouselConfig.pageNav))
                                                        carouselId[i].element.get('.pageNav').css('margin-left',pageNavMarginLeft);
                                                    
                                                    if (carouselWindowWidth != null)
                                                        carouselId[i].element.get('.carousel-window').css('width',carouselWindowWidth);
                                                    
                                                    if (carouselWindowListLeft != null)
                                                        carouselId[i].element.get('.carousel-window ol').css('left',carouselWindowListLeft);
                                            }
                                    }


                                    buildCarousels($('.photoCarousel ol, .audioCarousel ol'), {loop: true, size: 3, step: 1, pageNav: true}, '-164px', '65px', '277px', '-179px');
                                    buildCarousels($('.videoCarousel ol'), {loop: true, size: 4, step: 1}, '-164px','70px', '529px', '-159px');


                                    function slideUp(element, seconds) {
                                        //collapse current item
                                        glow.anim.css(element, seconds, {
                                              'height': {to: '0'}
                                            },
                                            { tween: glow.tweens.easeBoth() }
                                            ).start();
                                        }

                                    function slideDown(element, seconds) {
                                        var parentid = glow.dom.get(element).parent().each(function(){
                                            //expand next item
                                            glow.anim.css(element, seconds, {
                                                "height" : {to: "265px"}
                                                },
                                                { tween: glow.tweens.easeBoth() }
                                                ).start();

                                            });	//end parent.each

                                        } //end slideDown

                                    //slidetoggle listener
                                    glow.events.removeAllListeners(".slide-control");

                                    // Restrict each playlist to only show 6 tracks.

                                    var playlists = $(".slide-item ul");
                                    
                                    playlists.each(function (item) {
                                        glow.dom.get(playlists[item]).get("li").slice(6).remove();
                                    });

                                    $(".slide-control").each(function (item) {
                                        glow.events.addListener(this, 'click', function () {
                                            $("#playlist .current-item").removeClass("current-item");
                                            $(this).addClass("current-item");

                                            $("#playlist .slide-item").each(function(){
                                                glow.dom.get(this).css("overflow", "hidden");
                                                slideUp(this, 0.5);
                                           })


                                            $("div#" + this.id + "-panel .slide-item").each(function(){
                                                slideDown(this, 0.5);
                                                glow.dom.get(this).css("overflow", "visible");
                                                })

                                            return false;
                                            });
                                        });

                                    //page elements

                                    //test for default variable
                                    try {
                                        if (playlistItemToShow != "a" && playlistItemToShow != "b" && playlistItemToShow != "c")
                                            playlistItemToShow = "a";
                                        }
                                    catch (e) {
                                        playlistItemToShow = "a";
                                        }

                                    glow.dom.get("#" + playlistItemToShow + "list-panel .slide-item").css("overflow", "visible").css("height", "265px");

                                    $("#"+playlistItemToShow+"list").addClass( "current-item" );
                            });

                    }
            });
} catch(e) {}


