
/*** GESTIONE DEL PLAYER ***/
var playlist = [];
var current = 0;
var player = null; 

function stateListener(obj) { //IDLE, BUFFERING, PLAYING, PAUSED, COMPLETED
	currentState = obj.newstate; 
	previousState = obj.oldstate; 
	if ((currentState == "COMPLETED")&&(previousState == "PLAYING")) {
		if (current == playlist.length)
			current = 0;
		else
			current ++;
		loadTrack(playlist[current]);
		
	}
}

function playerReady(thePlayer) { 
	player = window.document[thePlayer.id];
	player.addModelListener("STATE", "stateListener");
}
function loadTrack(src){
	player.sendEvent('STOP');
	player.sendEvent('LOAD', src);
	player.sendEvent('START');

}
function changeTrack(e){
	// deseleziono eventuali valori correnti
	$.each($(".img_item"), function(){
		var img = $(this).children()[0];
		img.src = "/library/img/player_play.png";
	});

	// seleziono l'immagine associata e la cambio
	var img = $(this).prev().children()[0];
	img.src = "/library/img/player_stop.png";
	loadTrack( $(this).attr('href') );
	return false;
}

function createPlayer() {

	var flashvars = {
			file: '/XML/playlist.xml', 
			autostart:"true",
			playlist: 'top',
			playlistsize : 250
	}
	var params = {

			
			allowfullscreen:"true", 
			allowscriptaccess:"always",
			wmode: "opaque",
			width: '100%',
			height: 270
	}
	var attributes = {
			id:"player1",  
			name:"player1"
	}

	swfobject.embedSWF("../library/swf/player.swf", "player", "100%", "270", "9.0.115", false, flashvars, params, attributes);
	
}

/**** FINE GESTIONE DEL PLAYER ***/


/**** GESTIONE DEL SLIDESHOW ***/

function createSlideshow(){
	$.get("/it/ajax_slideshow.php", function(data){

		$('#photos').html(data);
		$('#photos').galleryView({
			panel_width: 500,
			panel_height: 250,
			transition_speed: 1500,
			transition_interval: 5000,
			nav_theme: 'dark',
			border: '1px solid white',
			pause_on_hover: true
		});	
			    Cufon.replace('h2');

	});

}


/**** FINE GESTIONE DEL SLIDESHOW ***/
$(document).ready(function(){

    $(document).pngFix(); 
	
	createPlayer();
	createSlideshow();

});