// JavaScript Document
/* <![CDATA[ */
 
var blipurl = 'http://blip.tv/?1=1&s=posts&skin=rss';
 
var currentPlaylist = null;
var currentLength = 0;
var currentItem = -1; 
var previousItem = -1; 
var currentMute = false; 
var currentVolume = 80; 
var currentPosition = 0; 
var currentState = 'NONE';
var currentLoaded = 0;
var currentRemain = 0;
 
var player = null;
function playerReady(thePlayer) {
	player = window.document[thePlayer.id];
	addListeners();
}
 
function timer2(yyy){
window.document.getElementById('testdiv' + yyy).style.backgroundColor = '#3f021a'
}


function addListeners() {
	if (player) { 
		player.addControllerListener("ITEM", "itemListener");
		player.addControllerListener("MUTE", "muteListener");
 
		player.addModelListener("LOADED", "loadedListener");
		player.addModelListener("STATE", "stateListener");
		player.addModelListener("TIME", "positionListener");
 
		player.addViewListener("VOLUME", "volumeListener");
	} else {
		setTimeout("addListeners()",100);
	}
}
 
 
function stateListener(obj) { //IDLE, BUFFERING, PLAYING, PAUSED, COMPLETED
	currentState = obj.newstate; 
	previousState = obj.oldstate; 
 
	var tmp = document.getElementById("stat");
	if (tmp) { 
		tmp.innerHTML = "current state: " + currentState + 
		"<br>previous state: " + previousState; 
	}
	
}
 
 
function positionListener(obj) { 
	currentPosition = obj.position; 
	var tmp = document.getElementById("tim");
	if (tmp) { tmp.innerHTML = "position: " + currentPosition; }
}
 
 
function loadedListener(obj) { 
	currentLoaded = obj.loaded; 
	currentRemain = obj.total - currentLoaded;
	var tmp = document.getElementById("ldd");
	var	quale = "testdiv" + currentItem;
	var	quale_no = "testdiv" + previousItem;
	window.document.getElementById(quale).style.backgroundColor = "#3f021a";
	window.document.getElementById(quale_no).style.backgroundColor = "#1b1b1b";
	if (tmp) { 
		tmp.innerHTML = "bytes loaded: " + currentLoaded +
				"<br>bytes remaining: " + currentRemain; 
	}
}
 
 
function volumeListener(obj) { 
	currentVolume = obj.percentage; 
	var tmp = document.getElementById("vol");
	if (tmp) { tmp.innerHTML = "volume: " + currentVolume; }
}
 
 
function muteListener(obj) { 
	currentMute = obj.state; 
	var tmp = document.getElementById("mut");
	if (tmp) { tmp.innerHTML = "mute: " + currentMute; }
}
 
 
function itemListener(obj) { 

	if (obj.index != currentItem) {
 		previousItem = currentItem;
		currentItem = obj.index;
 
		if (previousItem == -1) { getPlaylistData(); }
 
		var tmp = document.getElementById("itm");
		if (tmp) { 
			tmp.innerHTML = "current item: " + currentItem +
				"<br>previous item: " + previousItem;
		}
 
		var tmp = document.getElementById("item");
		if (tmp) { 
					tmp.innerHTML = "item: " + currentItem; 
					
					}
			

		var tmp = document.getElementById("pid"); 
		if (tmp) { 
			tmp.innerHTML = "(received from the player with the id: <i><b>" + obj.id + "</b></i>)"; 
		} 
 
		printItemData(currentItem);
	}
}
 
 
function printItemData(theIndex) {
	var plst = null;
	plst = player.getPlaylist();
 
	if (plst) {
		stringa = plst[currentItem].title;
		stringat = plst[currentItem].description;
				var temp = new Array();
					temp 			= stringa.split('-');
					idfilmato 		=	temp[0];
					idcat 			= temp[1];
				var temp1 	= new Array();
					temp1			= stringat.split('|');
					tt 					= temp1[0];
					tt2 				= temp1[1];
		stringacurr = plst[0].description;
		stringaprox = plst[1].description;
		stringaprox2 = plst[2].description;
		stringaprox3 = plst[3].description;
		var curr = new Array();
					curr 			= stringacurr.split(' | ');
					titolo_c		= curr[0];
					sottotitolo_c  	= curr[1];
				var prox = new Array();
					prox 			= stringaprox.split(' | ');
					titolo_n		= prox[0];
					sottotitolo_n  	= prox[1];
				var prox2 = new Array();
					prox2 			= stringaprox2.split(' | ');
					titolo_p		= prox2[0];
					sottotitolo_p  	= prox2[1];
				var prox3 = new Array();
					prox3 			= stringaprox3.split(' | ');
					titolo_pp		= prox3[0];
					sottotitolo_pp 	= prox3[1];
				// 
		stringacurrID = plst[0].title;
		stringaproxID = plst[1].title;
		stringaprox2ID = plst[2].title;
		stringaprox3ID= plst[3].title;
				var currID = new Array();
					currID 			= stringacurrID.split('-');
					filmato			= currID[0];
					//sottotitolo_c  	= currID[1];
				var proxID = new Array();
					proxID 			= stringaproxID.split('-');
					filmato_n		= proxID[0];
					//sottotitolo_n  	= prox[1];
				var prox2ID = new Array();
					prox2ID			= stringaprox2ID.split('-');
					filmato_p		= prox2ID[0];
					//sottotitolo_p  	= prox2[1];
				var prox3ID = new Array();
					prox3ID 		= stringaprox3ID.split('-');
					filmato_pp		= prox3ID[0];
					//sottotitolo_pp 	= prox3[1];
					window.document.getElementById("attuale").innerHTML = "<span>" + tt + "</span>";
			window.document.getElementById("testdiv0").innerHTML = "<a href=\"#\" style=\"text-decoration:none; color: #FFFFFF;\" onclick=\"parent.document.player1.sendEvent(\'ITEM\',0); setTimeout(\'timer2(0)\', 3000); \">" + titolo_c + "</a>";
			window.document.getElementById("testdiv1").innerHTML = "<a href=\"#\" style=\"text-decoration:none; color: #FFFFFF;\" onclick=\"parent.document.player1.sendEvent(\'ITEM\',1); setTimeout(\'timer2(1)\', 3000); \">" + titolo_n + "</a>";
			window.document.getElementById("testdiv2").innerHTML = "<a href=\"#\" style=\"text-decoration:none; color: #FFFFFF;\" onclick=\"parent.document.player1.sendEvent(\'ITEM\',2); setTimeout(\'timer2(2)\', 3000); \">" + titolo_p + "</a>";
			window.document.getElementById("testdiv3").innerHTML = "<a href=\"#\" style=\"text-decoration:none; color: #FFFFFF;\" onclick=\"parent.document.player1.sendEvent(\'ITEM\',3); setTimeout(\'timer2(3)\', 3000); \">" + titolo_pp + "</a>";
						//window.document.getElementById("codice").innerHTML = bbb;
			//parent.ajaxpage('inc_extra.asp?id_video_nn='+ idfilmato, 'extra');
			parent.ajaxpage('inc_scheda.asp?id_video_n='+ idfilmato, 'boxscheda');
			//alert('pagina= ' + idfilmato + '.html');
			parent.animatedcollapse.hide('boxbanner');
       	//alert('Now Playing idfilmato=' + idfilmato + ' and idcat='+ idcat);

	} 	
}

function getPlaylistData() { 
	var plst = null;
	plst = player.getPlaylist();
 
	if (plst) { 
		currentPlaylist = plst; 
 

		var txt = ''; 
		for(var i in currentPlaylist) { 
			txt += '<input type="checkbox" id="cb' + i + '" checked="checked" /> &nbsp; ';
			txt += currentPlaylist[i].title;
			txt += '<br />';
		}
		var tmp = document.getElementById("plstDat");
		if (tmp) { tmp.innerHTML = txt; }
	}	
}
 
 
function loadCheckedPlaylistData() { 
	if (currentPlaylist) { 
		var j = 0; 
		var lst = new Array();
		for(var i in currentPlaylist) { 
			if(document.getElementById('cb' + i).checked) {
				lst[j] = {
					author:currentPlaylist[i].author,
					description:currentPlaylist[i].description,
					duration:currentPlaylist[i].duration,
					file:currentPlaylist[i].file,
					link:currentPlaylist[i].link,
					
					image:currentPlaylist[i].image,
					start:currentPlaylist[i].start,
					title:currentPlaylist[i].title,
					type:currentPlaylist[i].type
				}
				j++;
			}
		}
		if(lst.length > 0) { player.sendEvent('LOAD', lst); }
	}	
}
 
 
function getLength() { currentLength = player.getPlaylist().length; return(currentLength); };
 
 
function loadFile(theFile) { currentItem = -1; previousItem = -1; player.sendEvent('LOAD', theFile); };
 
function createPlayer(theFile) {
            var flashvars = {
                    file:theFile, 
                    autostart:"false", 
                    shuffle:"false", 
                    //playlistsize:"150",
                   	//playlist:"bottom"
					controlbar:"bottom",
					skin:"modieus.swf",
					repeat:"list",
					//plugins:"sharing-1",
					//plugins:"fbit-1",
					
					//dock:"true"
					plugins: "sharing-2",
					 'sharing.code': 'true',
        'sharing.link': 'true'

					//'sharing.code': "%3Cembed%20src%3D%22http%3A%2F%2Fwww.frontieratv.it%2Fplayer.swf%22%20flashvars%3D%22file%3D..%2Fpublic%2Ffilmati%bunny.mp4%22%20width%3D%22400%22%20height%3D%22300%22%20%2F%3E"
            }
            var params = {
                    allowfullscreen:"true", 
                    allowscriptaccess:"always",
					wmode: "transparent"
            }
            var attributes = {
                    id:"player1",  
                    name:"player1"
            }
            swfobject.embedSWF("player.swf", "mplayer", "435", "270", "9.0.115", false, flashvars, params, attributes);
}
/* ]]> */

