// carousel...
var iV = 0
var tV = 0;

function carouselVideo(dir,width,n) {
    clearTimeout(tV);
	if(dir == 'next') { iV++ ; } else { iV-- ; }

	$('#carousel-video .c').animate({
		left: -width*iV 
	}, 'fast', function() {
		
		if(iV >= n) { 
			$('#carousel-video .c').css('left',n*width); 
			$('#carousel-video .c').animate({ 
				left:0  
			},'fast'); 
			iV = 0 ;
		} else if(iV <= -1) {
		$('#carousel-video .c').css('left',-n*width); 
			$('#carousel-video .c').animate({ 
				left:-(n-1)*width
			},'fast'); 
			iV = n-1 ;
		}
        tV = setTimeout('carouselVideo("next", '+width+', '+n+')', 10000);
	});
}

$(document).ready(function() {
	var widthV = $('#carousel-video .c li:eq(0)').width() ;
	var nV = $('#carousel-video .c li').size() ;

	if(nV <= 1) {
        $('#carousel-video .prev, #carousel-video .next').hide();
    } else {
        tV = setTimeout('carouselVideo("next", '+widthV+', '+nV+')', 10000);
    }

	$('#carousel-video .c').css('width', nV*widthV);
	$('#carousel-video .prev, #carousel-video .next').click(function() {
		$('#carousel-video #flash').empty(); //remove video, if shown
		$('#carousel-video #flash').css({ top:'300px' }); //hide #flash div
		$('#carousel-video .c').css('top','0'); //show carousel
		carouselVideo($(this).attr('class'), widthV, nV); //rotate carousel
		
		return false ;
	});

    //functions
         
    var so = new SWFObject("player.swf", "player", "516", "293", "8", "#ffffff");
    so.addParam('wmode','transparent')
    so.addVariable('id', '<cfoutput>#id#</cfoutput>');
    so.write("flash");

    $('#carousel-video li a[rel="video"]').click(function() {
        clearTimeout(tV); //stop rotation
        VId = $(this).attr('href').substr(4) ; //id of the video to show
        so.addVariable('id',VId); //add variable to flash
        so.write('flash'); //load flash, video according to VId
        $('#carousel-video #flash').css({ //move #flash to top so it's displayed
            top:'0'
        });
        $('#carousel-video .c').css('top','269px'); //hide carousel
        return false ;
    });

});
// ...carousel


