/*

  (Early beta) jQuery UI CoverFlow 2.2 App for jQueryUI 1.8.9 / core 1.6.2
  Copyright Addy Osmani 2011.
  
  With contributions from Paul Bakhaus, Nicolas Bonnicci
  
*/
var coverflowApp = coverflowApp || {};
$(function () {

    
    coverflowApp = {

        defaultItem: 3,
        //default set item to be centered on
        defaultDuration: 1200,
        //animation duration
        html: $('#demo-frame div.wrapper').html(),
        imageCaption: $('.demo #imageCaption'),
        sliderCtrl: $('.demo #slider'),
        coverflowCtrl: $('.demo #coverflow'),
        coverflowImages: $('.demo #coverflow').find('img'),
        coverflowItems: $('.demo .coverflowItem'),
        sliderVertical: $(".demo #slider-vertical"),


        origSliderHeight: '',
        sliderHeight: '',
        sliderMargin: '',
        difference: '',
        proportion: '',
        handleHeight: '',

        listContent: "",


        artist: "",
        album: "",
        sortable: $('#sortable'),
        scrollPane: $('#scroll-pane'),

        setDefault: function () {
            this.defaultItem -= 1;
            $('.coverflowItem').eq(this.defaultItem).addClass('ui-selected');
        },

        setCaption: function (caption) {
            this.imageCaption.html(caption);
        },

        init_coverflow: function (elem) {

            this.setDefault();
            this.coverflowCtrl.coverflow({
                item: coverflowApp.defaultItem,
                duration: 1200,
                select: function (event, sky) {
                    coverflowApp.skipTo(sky.value);
                }
            });



            //Skip all controls to the current default item
            this.skipTo(this.defaultItem);

            //
            //this.init_slider(this.sliderCtrl, 'horizontal');
            //this.init_slider($("#slider-vertical"), 'vertical');
            //change the main div to overflow-hidden as we can use the slider now
            this.scrollPane.css('overflow', 'hidden');

            //calculate the height that the scrollbar handle should be
            this.difference = this.sortable.height() - this.scrollPane.height(); //eg it's 200px longer 
            this.proportion = this.difference / this.sortable.height(); //eg 200px/500px
            this.handleHeight = Math.round((1 - this.proportion) * this.scrollPane.height()); //set the proportional height


            //
            //this.init_mousewheel();
            //this.init_keyboard();
            this.sortable.selectable({
                stop: function () {
                    var result = $("#select-result").empty();
                    $(".ui-selected", this).each(function () {
                        var index = $("#sortable li").index(this);
                        coverflowApp.skipTo(index);
                    });
                }
            });
        },

        skipTo: function (itemNumber, hide) {
            this.coverflowCtrl.coverflow('select', itemNumber, hide);
        },
		
		refresh: function () {
            this.coverflowCtrl.coverflow('_create');
        }
    };

    coverflowApp.init_coverflow();

	loopFlow();
	
});
	var current = 2;
	var dum = 1;
	
	function loopFlow() {
		if (current == 17)
		{
			current = 2;
			coverflowApp.skipTo(current++, true);
			var t=setTimeout("loopFlow();",100);	
		}
		else {
			coverflowApp.skipTo(current++, false);
			var t=setTimeout("loopFlow();",2000);
		}		
	};
