var pausa = "no";

function playerReady(thePlayer) {
	player = document.getElementById(thePlayer.id);
	addListeners();
}

function addListeners() {
	if (player) { 
		player.addModelListener("STATE", "stateListener");
	} else {
		setTimeout("addListeners()",100);
	}
}

function stateListener(obj) { 

	currentState = obj.newstate; 

	if ((last != "wmv") && (Browser.Platform.name != "linux")) {

		if ((currentState == "COMPLETED")||(currentState == "PAUSED")) {
			//hor.resume();
			pausa = "no";
		}
		if ((currentState == "PLAYING")||(currentState == "BUFFERING")) {
			//hor.pause();
			pausa = "si";
		}
	}
}

function videocorrelati(id)
{
	$('NewsVertical').load("/get.php?op=videocorrelati&id="+id);
	//setTimeout("hor = new Ticker('TickerVertical');", 4000);
	if (typeof hor != "undefined") {
		hor.stop();
		hor.currentIndex = 0;
		hor.previousIndex = 5;
		hor.nextIndex = 1;
		//hor.clearChain();

	}
	hor = new noobSlide({box: $('NewsVertical'),currentIndex: 0, previousIndex: 5, nextIndex: 1,items: [0,1,2,3,4,5],size: 135,autoPlay: true,mode: 'vertical'});
}

function carousel()
{
	var mytimer = null;
	hor = new Ticker('TickerVertical');
}

window.addEvent('domready', function() {



	$('embed').addEvent('click', function(e) {
		e.stop();
		var myFx = new Fx.Scroll(window).toElement('wrapper');
		$('messaggi-video').setStyle('visibility', 'visible');
		$('messaggi-video').setStyle('top', '0');
		if(last == 'wmv') $('video').setStyle('visibility', 'hidden');
		$('messaggi-video').load('/get.php?op=embed&id='+lastid);
		if(last == 'mp4') $('mpl').sendEvent('PLAY', 'false');
	});

	$('livespace').addEvent('click', function(e) {
		e.stop();
		if(last=="mp4")
		{
			var obj = '%3Cembed+src%3D%22http%3A%2F%2Fwww.41agenziatv.com%2Finc%2Fswf%2Fplayer.swf%22+width%3D%22400%22+height%3D%22333%22+bgcolor%3D%22%23ffffff%22+frontcolor%3D%22%23ffffff%22+screencolor%3D%22%23292929%22+allowscriptaccess%3D%22always%22+allowfullscreen%3D%22true%22+flashvars%3D%22stretching%3Dfill%26controlbar%3Dover%26skin%3Dhttp%3A%2F%2Fwww.41agenziatv.com%2Finc%2Fswf%2Fstylish.swf%26image%3Dhttp%3A%2F%2Fwww.41agenziatv.com%2Finc%2Fphp%2Fimg.php%3Fparametri%3D'+lastid+'%2C400%2C333%26file%3Dhttp%3A%2F%2Fwww.41agenziatv.com%2Finc%2Fphp%2Fget_movie.php%3Fparametri%3D'+lastid+'%2C.m4v%22+%2F%3E';
		}
		else
		{
			var obj = '%3Ca+href%3D%22http%3A%2F%2Fwww.41agenziatv.com%2F%3Fvideo%3D'+lastid+'%22%3E%3Cimg+src%3D%22http%3A%2F%2Fwww.41agenziatv.com%2Finc%2Fphp%2Fimg.php%3Fparametri%3D1044%2C400%2C333%22%3E%3C%2Fa%3E';
		}
		window.open('http://spaces.live.com/BlogIt.aspx?Title='+$("titolo").get('html')+'&description='+obj+'&SourceURLu=http%3A%2F%2Fwww.41agenziatv.com%2F%3Fvideo%3D'+lastid,"mywindow","status=1,toolbar=1,location=1,menubar=1,directories=1,resizable=1,scrollbars=1"); 
	});
	
	$('myspace').addEvent('click', function(e) {
		e.stop();
		if(last=="mp4")
		{
			var obj = '%3Cembed+src%3D%22http%3A%2F%2Fwww.41agenziatv.com%2Finc%2Fswf%2Fplayer.swf%22+width%3D%22400%22+height%3D%22333%22+bgcolor%3D%22%23ffffff%22+frontcolor%3D%22%23ffffff%22+screencolor%3D%22%23292929%22+allowscriptaccess%3D%22always%22+allowfullscreen%3D%22true%22+flashvars%3D%22stretching%3Dfill%26controlbar%3Dover%26skin%3Dhttp%3A%2F%2Fwww.41agenziatv.com%2Finc%2Fswf%2Fstylish.swf%26image%3Dhttp%3A%2F%2Fwww.41agenziatv.com%2Finc%2Fphp%2Fimg.php%3Fparametri%3D'+lastid+'%2C400%2C333%26file%3Dhttp%3A%2F%2Fwww.41agenziatv.com%2Finc%2Fphp%2Fget_movie.php%3Fparametri%3D'+lastid+'%2C.m4v%22+%2F%3E';
		}
		else
		{
			var obj = '%3Ca+href%3D%22http%3A%2F%2Fwww.41agenziatv.com%2F%3Fvideo%3D'+lastid+'%22%3E%3Cimg+src%3D%22http%3A%2F%2Fwww.41agenziatv.com%2Finc%2Fphp%2Fimg.php%3Fparametri%3D1044%2C400%2C333%22%3E%3C%2Fa%3E';
		}
		window.open('http://www.myspace.com/index.cfm?fuseaction=postto&t='+$("titolo").get('html')+'&c='+obj+'&u=http%3A%2F%2Fwww.41agenziatv.com%2F%3Fvideo%3D'+lastid+'&l=1',"mywindow","status=1,toolbar=1,location=1,menubar=1,directories=1,resizable=1,scrollbars=1"); 
	});

	$('facebook').addEvent('click', function(e) {
		e.stop();
		window.open('http://www.facebook.com/share.php?u=http://www.41agenziatv.com/?video='+lastid,"mywindow","width= 600, height=500, status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=0"); 
	});
	
	$('digg').addEvent('click', function(e) {
		e.stop();
		window.open('http://digg.com/submit?phase=2&title='+$("titolo").get('html')+'&bodytext='+$("desc").get('html')+'&url=http://www.41agenziatv.com/?video='+lastid,"mywindow","status=1,toolbar=1,location=1,menubar=1,directories=1,resizable=1,scrollbars=1"); 
	});
	
	$('stumble').addEvent('click', function(e) {
		e.stop();
		window.open('http://www.stumbleupon.com/submit?url=http://www.41agenziatv.com/?video='+lastid+'%26title%3D'+$("titolo").get('html'),"mywindow","status=1,toolbar=1,location=1,menubar=1,directories=1,resizable=1,scrollbars=1"); 
	});

	$('linkvideo').addEvent('click', function(e) {
		e.stop();
		var myFx = new Fx.Scroll(window).toElement('wrapper');
		$('messaggi-video').setStyle('visibility', 'visible');
		$('messaggi-video').setStyle('top', '0');
		if(last == 'wmv') $('video').setStyle('visibility', 'hidden');
		$('messaggi-video').load('/get.php?op=linkvideo&id='+lastid);
		if(last == 'mp4') $('mpl').sendEvent('PLAY', 'false');
	});

	$('sendvideo').addEvent('click', function(e) {
		e.stop();	
		var myFx = new Fx.Scroll(window).toElement('wrapper');
		$('messaggi-video').setStyle('visibility', 'visible');
		$('messaggi-video').setStyle('top', '0');
		if(last == 'wmv') $('video').setStyle('visibility', 'hidden');
		$('messaggi-video').load('/get.php?op=send&id='+lastid);
		if(last == 'mp4') $('mpl').sendEvent('PLAY', 'false');
		setTimeout("val = new validate('form_41',{css:'#FFFFFF'});", 1000);
	});

});

 function chiudim() {
	$('messaggi-video').empty();
	$('messaggi-video').setStyle('visibility', 'hidden');
	if(last == 'wmv') $('video').setStyle('visibility', 'visible');
	$('messaggi-video').setStyle('top', '-999px');
	if (last == 'mp4') {
		//if (obj.newstate == "PAUSED") $('mpl').sendEvent('PLAY', 'true');
	}
}

function inviavideo() {
	$('mess-interno').setStyle('visibility', 'hidden');
		var ajax = new Request.HTML({
		url: '/inc/php/form.php?op=formvideo',
	//	encoding: 'iso-8859-1',
		onSuccess: function(html, responseElements, responseHTML){
			$('messaggi-video').set('html',responseHTML);
			$('mess-interno').setStyle('visibility', 'visible');
		},
		onFailure: function(){
			$('messaggi-video').set('html', 'Richiesta fallita.');
		}		
	}).post($('form_41'));

}
