///<reference path="~/static/scripts/Jquery.IntelliSense.js" />
///<reference path="~/static/Main.js" />

var Players=[],VideoStart="media.israelnn.com" ;
Players.New = function (video,TVZone,size) {
	if (!TVZone) TVZone = 69; if (!size) size = {width:319,height:239}
	var id = Players.length;
	var p = new Player(id, video,size);
	Players.push(p);
	p.TVZone = TVZone;
	p.fA = Player.prototype.fA;
	return p;
}


function Player(id,video,size)
{
	this.video = video;
	this.size = size;
	var sBG = "",sHTML = [];
	this.id=id;
	var sPlayer = '<div style=color:white;><a style=color:white href=mms://'+VideoStart+video.url+'>Open Video</a>';

	if ($.browser.mozilla &&! this.CheckFFWMP() &&navigator.platform=='Win32')
	sPlayer  = "<div style=direction:rtl;color:white><a target=_blank href=http://port25.technet.com/pages/windows-media-player-firefox-plugin-download.aspx style=color:white>Windows Media player Firefox plugin.</a></div>";
	else if ($.browser.mozilla && this.CheckFFWMP()) {sPlayer = '<object id=Player'+id+' width="'+size.width+'" height="'+size.height+'" type="application/x-ms-wmp"><PARAM NAME="transparentatStart" VALUE="true"><PARAM NAME="stretchToFit" VALUE="false"><PARAM NAME="uimode" VALUE="none"><PARAM NAME="autoStart" VALUE="false"></object>';}
	if ($.browser.msie) {sPlayer =  '<object id=Player'+id+' classid=CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6 width="'+size.width+'" height="'+(size.height+65)+'"><PARAM NAME="stretchToFit" VALUE="false"><PARAM NAME="transparentatStart" VALUE="true"><PARAM NAME="autoStart" VALUE="false"></OBJECT>'}

	if (video.image>0) sBG = "background-image:url("+GetImage(video.image)+")";
	

	sHTML.push('<div class=VVideo style=width:'+size.width+'px;><div id=divVideoBG'+id+' style="width:'+size.width+'px;height:'+size.height+'px;direction:ltr;overflow:hidden;cursor:pointer;'+sBG+'" onclick=Players['+id+'].Play()><img class=VidLargePlay style=position:absolute;top:'+(size.height-74)/2+'px;left:'+(size.width-74)/2+'px src=/images/objects/shadaw.gif>'+sPlayer+'<div class=VideoLoadingOut> <span style=display:none id=divLoading'+id+'>wait...</span></div></div><div onmouseup=Players['+id+'].ChangePos(($.getMouseCoordsWithinEvent(arguments[0]).x/this.offsetWidth)*100) class=VPos><div id=VideoPosition'+id+'></div></div>');
	sHTML.push('<div class=VLine>\
	<div onclick=Players['+id+'].ChangeVolume(($.getMouseCoordsWithinEvent(arguments[0]).x/this.offsetWidth)*100) onmousedown=this.move=1;t=this;this.onclick.call();u=arguments[0]; onmouseup=this.move=0;clearTimeout(window.volto); onmousemove=if(this.move)Players['+id+'].ChangeVolume(($.getMouseCoordsWithinEvent(arguments[0]).x/this.offsetWidth)*100)  onmousedown=this.move=1 onmouseout=setTimeout("this.move=0;",100); class=VVol><div class=Line></div><span id=spnVolume'+id+'></span>&nbsp;</div>\
	<span class=VMute onclick="_(\'Player'+id+'\').settings.mute=_(\'Player'+id+'\').settings.mute==true?false:true;"></span>\
	<span class=VPlay id=VPlay'+id+' onclick="Players['+id+'].VPlayPause();"></span><img class=VFS onclick="Players['+id+'].FullScreen()" src=/images/objects/fs.gif>\
	<div class=VideoAd id=divVideoAd'+id+'></div>\
	</div><span class=VMarker id=VMarker'+id+'></span><span class=VLen id=VLen'+id+'>2</span><div class=VText id=divVidTitle'+id+'>'+video.title+'</div></div>')
//<span class=VStop onclick="Players['+id+'].Command(\'Stop\');">s</span>


	
	this.html = sHTML.string();
}

Player.prototype = {Volume: 100,AdIn:true,lastState:-1,Writed:false,
CheckFFWMP: function() {
	for ( var i in navigator.plugins ) {
		var n = navigator.plugins[i].name;
		if ( n != null && n.indexOf("Windows Media") >= 0 && n.indexOf("Microsoft") == 0 )
			return true;
	}
	return false;
	},
Command: function(command) {var p= _("Player"+this.id); if($.browser.msie) eval("p.controls."+command+"()"); else eval("p.controls."+command.toLowerCase()+"()");},
Play: function() {this.Command("Play");},
VPlayPause: function() {var MP = _('Player'+this.id); if (MP.playState==3) this.Command("Pause"); else  this.Play();},
UpdateMP: function()
	{ 
	var MP = _('Player'+this.id),x,iPos;
	if(MP.playState==2||MP.playState==3)
		{
		iPos = Math.floor((MP.controls.currentPosition/MP.currentMedia.duration)*100+0.999999999)+1
		_("VideoPosition"+this.id).style.width=(iPos/100)*this.size.width+"px"
		//MP.style.width=this.width;MP.style.height='304px';
	} ;
	d=_("VPlay"+this.id).style.backgroundPosition = "0px "+ (MP.playState==3?17:0)+"px"
	_("VMarker"+this.id).innerHTML = MP.controls.currentPositionString;
	if(MP.currentMedia) _("VLen"+this.id).innerHTML = MP.currentMedia.durationString;
	},
ChangePos: function(value) {if (this.AdIn) return false; MP =_("Player"+this.id); MP.controls.currentPosition=MP.currentMedia.duration*(value/100);/* UpdateMP(this.id);*/ },
ChangeVolume: function(value) {if (value<10||!value) return;value+=5; if (value>100)value=100;
	this.Volume=value; _('Player'+this.id).settings.volume=this.Volume; _('spnVolume'+this.id).style.left=((value-6)/2)+"px";},
FullScreen: function() {var MP =_("Player"+this.id);if (MP.playState== 3||MP.playState==2||MP.playState == 6) MP.fullScreen = true;},
IsLoad: function()
	{	var p=_('Player'+this.id),ps = p.playState,load = _('divLoading'+this.id);
		if(ps>1&&ps<6) {load.style.display="none"; p.style.visibility='';}
		else {load.style.display=(ps!=1&&ps!=8&&ps!=10)?"":"none"; p.style.visibility='hidden';}},
Writed: function() {this.Writed=true;this.ChangeVolume(this.Volume); ExectueJS("http://click.inn.co.il/video.php?site=1&zone="+this.TVZone+"&video="+this.id+"&rnd="+new Date().getTime());this.IsLoad();
//_('Player'+this.id).onClick=function() {alert};
	("<script for=Player"+this.id+" event=Click>if (Players["+this.id+"].AdIn) {x = window.open(Players["+this.id+"].a.link); if (!x) location.href=Players["+this.id+"].a.link}</script>").write();
	$(".VidLargePlay").css("opacity",.6);
	 },
fA :function(a) {if (a.url) {_('Player'+this.id).URL='mms://'+VideoStart+a.url; this.a=a;  this.AdIn =true;_('divVideoAd'+this.id).innerHTML=a.html.replaceStr('phpAdsNew','phpAdsNew-en-new');}
	else {_("Player"+this.id).URL = 'mms://'+VideoStart+this.video.url; this.AdIn = false;}},
ReplaceUrl: function(id) { try {this.IsLoad() } catch(e) {}
	p=_("Player"+this.id);
	if (this.AdIn&&(p.playState==8||this.lastState==3&&p.playState==1))
	{	ExectueUrl(this.a.logurl);
		this.AdIn = false;
		this.SetVideo(this.video); 
		this.Play();
	}
	},
	SetVideo: function (video) {if (video.url.indexOf(":")==-1) video.url = "mms://media.israelnn.com/inntv-eng/"+video.url; this.video=video; _("divVidTitle"+this.id).innerHTML = video.title; _("divVideoBG"+this.id).style.backgroundImage="url("+GetImage(video.image)+")"; if(!this.AdIn) _("Player"+this.id).URL=this.video.url; this.Play()}
}
function CheckPState()
{
	var played=false;
	for (var i=0;i<Players.length;i++)
	  if (Players[i].Writed) {
		var player = _("Player"+i);
		var p = Players[i];
		if (player.playState==8||(player.playState==1&&p.lastState==3)) p.ReplaceUrl()
		if(p.lastState != player.playState) p.lastState = player.playState;
		p.IsLoad()
		p.UpdateMP()
		if (player.playState>1&&player.playState<8) played=true;
	}
	setTimeout(CheckPState,played?200:1000);
}
setTimeout(CheckPState,500);
$(document).ready(function () {$('Video').disableSelection();})