var flashReady = false;
var flashApi;
var playerMovie;
var currentList;
var currentTitle = 'vid';
var currentScrollable = '#myplaylistMovie';
var currentClip = -1;
var tabsApi
var playerOptions = {
	canvas: { backgroundColor:'#00000',backgroundGradient: 'none'},
	plugins: { 
		audio: { url: 'swf/flowplayer.audio-3.1.2.swf' },
		controls: {
			progressColor: '#a8a8a8', borderRadius: '0', durationColor: '#c4c4c4', backgroundGradient: 'none',
			bufferColor: '#5e5e5e', buttonOverColor: '#6ae600', sliderColor: '#636363', bufferGradient: 'none',
			timeBgColor: '#555555', timeColor: '#a5ff24', tooltipTextColor: '#CCCCCC', tooltipColor: '#333333',
			tooltipGradient: 'none', volumeSliderColor: '#333333', buttonColor: '#636363', sliderGradient: 'none',
			backgroundColor: '#000000', progressGradient: 'medium', volumeSliderGradient: 'none',
			height: 24, opacity: 1.0, playlist: true, loop: true
		}
	},
	playlist: completePlaylist,
    //clip: { onBegin: startClip, onFinish  : endClip, onPause: endClip, onResume: startClip, onStop: endClip }
	clip: { scaling: 'fit', onBegin: startClip, onFinish: endClip, onBeforeFinish: beforeEndClip, onPause: pauseClip, onResume: resumeClip, onStop: stopClip }
}

function isReady(){
	return true;
}
function flashIsReady(){
	flashReady = true;
}

$(function() {

    var p = flowplayer("playerMovie", "swf/flowplayer-3.1.4.swf", playerOptions);
    playerMovie = p;
    flashApi = $("#wave").flashembed( { src: 'swf/wave.swf', width: 23 , height: 18 , allowscriptaccess: true, wmode: "window"});
	tabsApi = $("#panes").scrollable({size: 1}).navigator({ api:true, navi: "#tabs",  naviItem: 'a',  activeClass: 'current' });
	$(".scrollableMovie").scrollable({ next: ".scrollableMovie #down", prev: ".scrollableMovie #up", item: "a", items: ".listitemsMovie", vertical:true, size: 5, hoverClass: 'hover'}).circular().navigator().mousewheel();
	$(".scrollableRadio").scrollable({ next: ".scrollableRadio #down", prev: ".scrollableRadio #up", item: "a", items: ".listitemsRadio", vertical:true, size: 5, hoverClass: 'hover'}).circular().navigator().mousewheel();
	$("#myplaylistRadio a").click(playlistRadioClick);
	$("#myplaylistMovie a").click(playlistMovieClick);
	$("button[rel]").overlay({expose: '#000', effect: 'apple', onLoad: initialize});

	isReady();
});
function stopClip(){
	$("#wave object")[0].stopAnim(); 
}
function pauseClip(){
	$("#wave object")[0].stopAnim(); 
}
function resumeClip(){
	$("#wave object")[0].playAnim();
}
function endClip(){
	$("#wave object")[0].stopAnim();
    if( currentClip==completePlaylist.length-1){
        currentScrollable == '#myplaylistMovie';
        tabsApi.click(0);
        currentClip = -1;
    	playerMovie.play(0);
		playerMovie.stop();
    }
}
function beforeEndClip(){
	if( currentClip==radioIndex-1 ){
		playerMovie.stop();
	}
}
function startClip(){
	var p = playerMovie.isPaused();
//	alert(p);
	//if( !p ){
    	currentClip = currentClip + 1;
	    if( currentClip==radioIndex){
	        currentScrollable == '#myplaylistRadio';
	        tabsApi.click(1);
	    }
	
		if(!(currentScrollable == '#myplaylistRadio' && ( currentClip - radioIndex ) % 2 == 0)) $("#wave object")[0].playAnim();
		$('.radDesc').hide();
		$('.vidDesc').hide();
		var titleId = '#desc'+currentClip;
		$(titleId).show();
		var itemClass = '.i'+currentClip;
		unselectAllListItems()
		$(itemClass).addClass( "playing" );
//	}
}

function playlistRadioClick(){
	var item = $(this);
	unselectAllListItems()
    var index = parseInt(item.attr("id").substr(1))-1;
    currentClip = index-1;
	playerMovie.play(index);
	return false;
}
function playlistMovieClick(){
	var item = $(this);
	unselectAllListItems()
	item.addClass( "playing" );
    var index = parseInt(item.attr("id").substr(1));
    currentClip = index-1;
    playerMovie.play(index);
	return false;
}
function unselectAllListItems(){
	$(".clips a").removeClass( "playing" );
}

function initialize() {
	if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById("map_canvas"));
		var center = new GLatLng(48.8845765, 2.316997);
		map.setCenter(center, 15);
		map.setUIToDefault();
		var s = new GSize(16, -27);
		var opt = { pixelOffset: s };
		map.openInfoWindowHtml(map.getCenter(), '<div><img src="style/img/info-title.gif" width="253" height="28"></div><p>34 rue Dulong<br/>75017 Paris<br/><strong>Tel : </strong>+33 (0)1 01 01 01 01<br/>Email: <a href="mailto:hello@lesecouteurs.net">hello@lesecouteurs.net</a></p>', opt);
		var ico = new GIcon(G_DEFAULT_ICON);
		ico.image = "style/img/dot.png";
		ico.iconSize = new GSize(32, 32);
		markerOptions = { icon:ico };
		map.addOverlay(new GMarker(center, markerOptions));	   
	}
}

