function Coverflow(feedsource,element,options){

	if(window.location.href.indexOf('debug')  != -1) this.debug=true;
    this.feedurl = feedsource;
    if(options) this.options = options;

    element = $(element);

    $(element).css('overflow','hidden');
    $(element).html($('<div style="width:1200px"><div class="cfslidefx"></div><div class="cfslide"></div></div><div class="cfnavigation"><div class="cfLeftBtn">&lt;</div><div class="cfthumbsWrapper"><div class="cfthumbs"></div></div><div class="cfRightBtn">&gt;</div><div style="clear:both"></div></div>'));

    cfelements = [];

    this.clickThumb = function(e){
        
        $(element).find('.cfthumb').removeClass('active');
        showSlide(e.data.index);
    }

    this.scrollRight = function(e){
        wrapper= $(element).find('.cfthumbsWrapper');
        thumbs= $(element).find('.cfthumbs');
        
        $(element).find('.cfthumbs').animate({
            left: '-=200'
        },400);
    }

    this.scrollLeft = function(e){
        if( parseInt($(element).find('.cfthumbs').css('left')) >= 0 ) return;
        
        $(element).find('.cfthumbs').animate({
            left: '+=200'
        },400)
    }

    $(element).find('.cfLeftBtn').bind('click', {objReference:this}, this.scrollLeft);
    $(element).find('.cfRightBtn').bind('click', {objReference:this}, this.scrollRight);

    function slideClick(e){
        row = cfelements[e.data.index];
        if(row.embed){
            options.videoHandler(row.embed);
            return;
        }
        if(row.url){
            window.location.href = row.url;
            return;
        }
    }
    
    this.slideClick = function(e){
        slideClick(e);
    }

    function destroy(){
        $(element).html('');
    }
    
    function showSlide(index){
        row = cfelements[index];
        slideClass = row.slideClass ? row.slideClass : 'cfnormal';

        $(element).find('.cfslide').attr('class','cfslide cfslide_'+slideClass);
        $(element).find('.cfslidefx').attr('class','cfslidefx cfslide_'+slideClass);
        slideImg = $('<img src="'+row.slide+'" class="'+slideClass+'" />');
        $(slideImg).bind('click', {index:index}, slideClick);

        //For crossfading effects, save the old slide.
        $(element).find('.cfslidefx').html($(element).find('.cfslide').html()); 
        $(element).find('.cfslidefx').css('width','');

        $(element).find('.cfslide').html('');
        $(element).find('.cfslide').append(slideImg);
		
        if(row.embed) $(element).find('.cfslide').append($('<div class="cfvideobutton"></div>').bind('click', {index:index}, slideClick));

        if(row.title){
            infoOverlay = $('<div class="cfinfooverlay"></div>');
            titleLink = $('<a>').attr('href',row.url).text(row.title);
            
            $(infoOverlay).append(titleLink);

            if(row.description){
                infoDesc = $('<div></div>').html(row.description);
                $(infoOverlay).append(infoDesc);
            }
            $(element).find('.cfslide').append(infoOverlay);
        }


        $(element).find('.cfslidefx').animate( 
            {width:'0'},
            400
        );
        
        
        $(element).find('.cfthumb').removeClass('active');
        $($(element).find('.cfthumb').get(index)).addClass('active');

        if(options.onCloseHandler) options.onCloseHandler();
    }

    function clickThumb(e){
       showSlide(e.data.index);
    }
	
    
    this.onFeedData = function(data){
        json = eval(data);
        newWidth = 0;
        for(i=0; i<json.length; i++){
            row = json[i];
            newThumb = $('<div class="cfthumb" cfindex="'+i+'"><table><tr><td class="cfthumbwrap"><div><img src="'+row.thumb+'" /></div></td></tr></table></div>');
			if(this.debug) alert(row.thumb);
			
            $(newThumb).bind('click', {index:i}, clickThumb);

            cfelements.push(row);
            $(element).find('.cfthumbs').append(newThumb);

            newWidth += 110;
            
            if(options.onAddRowHandler){
                options.onAddRowHandler(row);
            }

        }
        $(element).find('.cfthumbs').css('width',newWidth+'px');
        
        showSlide(0);
    }
	if(this.debug) alert(feedsource);
    $.post(feedsource,{s:Math.random()},this.onFeedData);




}
