var PlayListByCategorie = function(){

	var itemRecord = Ext.data.Record.create([
	   {name: 'title'},
	   {name: 'description'},
	   {name: 'file', mapping: 'content'},
	   {name: 'duration'},
	   {name: 'start'},
	   {name: 'image', mapping: 'thumbnail'}
	]);
	// parser le fichier XML contenu dans response
	var myReader = new Ext.data.XmlReader({
	   record: "item"           // The repeated element which contains row information
	}, itemRecord);

	return {
		changePL : function(catId) {
			
			plStore = new Ext.data.Store( {
				reader: myReader
				, baseParams : {
					categorie : catId
				}
				, url : 'http://www.ville-larochesuryon.fr/video/playlist/playlist.php'
			});
			plStore.load({
				callback: PlayListByCategorie.loadedPL
			}
			);
		}
		, loadedPL : function(r, options, success) {
			if(success) {
				var player = PlayListByCategorie.getPlayer('video');
				var items = new Array();
				// This is a javascript handler for the player and is always needed.
				for(i = 0; i < r.length; i++) {
					r[i].get('thumbnail');
					items.push({
						file : r[i].get('file')
						, type:"video"
						, title: r[i].get('title')
						, image: r[i].get('image')
						, duration: r[i].get('duration')
						, description: r[i].get('description')
						, start: r[i].get('start')
					});
				}
				player.sendEvent("LOAD",items);		
			}
			else {
//				Ext.Msg.alert('Vidéothèque', 'Impossible de charger la playlist!');
			}
		}
		, getPlayer : function (movieName) {
 			// if(navigator.appVersion.indexOf("MSIE 6.0") != -1) {
//				alert("Microsoft " + document.getElementById(movieName));
				// console.debug(document.getElementById(movieName));
				// console.debug(document.applets[0]);
				// return document.applets[0];		
//				return document.getElementById(movieName)				
			// } else {  
				return document.getElementById(movieName);
//			}
		}
		, init : function() {
//			PlayListByCategorie.changePL(0);
			 var s1 = new SWFObject('http://www.ville-larochesuryon.fr/video/player.swf','video','400','500','9','#a5c5da');
			  s1.addVariable ('width', '400'); 
			  s1.addVariable ('height', '500');
			  s1.addParam('allowfullscreen','true');
			  s1.addParam('allowscriptaccess','always');
			  s1.addParam('wmode','opaque');
			  s1.addParam('flashvars','file=http://www.ville-larochesuryon.fr/video/playlist/playlistUne.php&playlist=bottom&screencolor=#a5c5da&frontcolor=#005c98&lightcolor=#ffd204');
			  s1.write('videotheque');		
		}				
	}
}();
Ext.onReady(PlayListByCategorie.init, PlayListByCategorie, true);


