﻿///<reference path="Jquery.IntelliSense.js" />
///<reference path="Main.js" />

var Players=[];
if(!View.PlayerSize) View.PlayerSize = {width:340,height:240};
Players.New = function (video,TVZone,size) {
	if(!TVZone) TVZone =190; if (!size) size = View.PlayerSize;
	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; this.errorCount=0;
	var sImg = "",sHTML = [];
	this.id=id;
	this.AdIn=false;
	var sl=$.browser.msie?false:this.CheckSL();
	if (!$.browser.msie&&!sl)
		{this.Silverlight=true; video=this.MakeUrl(video); sPlayer = "<div style=direction:rtl;position:absolute;text-align:right;background-color:black;height:"+(size.height-20)+"px;padding:10px;color:white;width:"+(size.width-40)+"px>עליך להתקין תוסף Silverlight לדפדפן שלך.<br/><a href=http://go2.microsoft.com/fwlink/?LinkID=114576&amp;v=2.0 style=color:white>לחץ כאן כדי להתקין את Silverlight</a><br/><br/>לחילופין נסה <a style=color:white onmouseover=this.href=Players["+id+"].MakeUrl(Players["+id+"].video).url href=#>לפתוח אותו בנגן חיצוני</a></div>"; this.Writed=DoNothing;}
	if (!$.browser.msie&&sl){ sPlayer = '<object type="application/x-silverlight-2" id="Player'+id+'" src=/static/images/objects/a7player.xap style=width:'+(size.width-20)+'px;height:'+size.height+'px"><param name="MinRuntimeVersion" value="2.0.31005.0"></param><param name=Source value=/static/images/objects/a7player.xap /></object>'; this.Silverlight=true}
	else if ($.browser.msie) {sPlayer =  '<object id=Player'+id+' classid=CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6  style=width:'+(size.width-20)+'px;height:'+(size.height+65)+'px"><PARAM NAME="stretchToFit" VALUE="true"><PARAM NAME="uimode" VALUE="full"><PARAM NAME="autoSize" VALUE="false"><PARAM NAME="autoStart" VALUE="true"></OBJECT>'}

	sImg = size.height>30? "<img id=imgVideo"+id+" style=position:Absolute;height:"+size.height+"px;"+(!this.size.height?'visibility:hidden':'')+" src="+(!video||!video.image||this.audio?sStaticURL+'/images/radio/audio-video.jpg':GetImage(video.image,(size.width-20),size.height))+">":"";
	sHTML.push('<div class=VVideo style=width:'+size.width+'px;><div  id=divVidTitle'+id+' '+(Players.DisableTitle?'style=height:8px;font-size:1px;color:Black':"")+' class=VVideoT></div><div id=divVideoBG'+id+' style="margin:0 10px;width:'+(size.width-20)+'px;height:'+size.height+'px;direction:ltr;overflow:hidden;cursor:pointer;" onclick=Players['+id+'].Play()>'+sImg+'<img class=VidLargePlay id=VidLargePlay'+id+' style=position:absolute;top:'+(size.height-74)/2+'px;left:'+(size.width-84)/2+'px;'+(!this.size.height?'visibility:hidden':'')+' src='+sStaticURL+'images/objects/play.png>'+sPlayer+'<div class=VideoLoadingOut style=top:'+((size.height/2)+60)+'px dir=rtl> <span style=display:none id=divLoading'+id+'>טוען...</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 style="background-position:'+(size.width/2-20)+'px -45px">\
	<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" id=VMute'+id+' onclick="Players['+id+'].Mute()"></span>\
	<span class="VButton VPlay" id=VPlay'+id+' onclick="Players['+id+'].VPlayPause();"><span></span></span><span class="VButton VStop" onclick="Players['+id+'].Command(\'Stop\');"><span></span></span><span'+(size.height<30?' style=visibility:hidden':'')+' class="VButton VFS" onclick="Players['+id+'].FullScreen()"><span></span></span>\
	</div> <div class=VText style="background-position:'+(size.width/2-140)+'px -82px" ><span class=VMarker id=VMarker'+id+'></span><div id=divVidInf'+id+'></div></div> </div>');
	if(size.width>380) if (Info.View.a.length==0) {Info.Add(211,"divVidInf"+id,{text:1}); setTimeout("Players["+id+"].UpdateInf()",25000);} else this.UpdateInf(1);
	this.html = sHTML.string();
}

Player.prototype = { Volume: 100, Silverlight: false, lastState: -1, IsWrited: false, loggedC: [],
	CheckSL: function (version) {
		try {
			var control = null;
			try {
				control = new ActiveXObject('AgControl.AgControl');
				if (version == null) return true;
				control = null;
			}
			catch (e) {
				if (navigator.plugins["Silverlight Plug-In"]) return true;
			}
		}
		catch (e) {
			return false;
		}
	},
	Command: function (command) { var p = _("Player" + this.id); if (this.Silverlight) eval("p.Content.p." + command + '()'); else eval("p.controls." + command + "()"); },
	Play: function () { if (!this.UrlSetted) this.SetURL(this.ActiveUrl); this.Command("Play"); this.LogC() }, Stop: function () { this.Command("Stop"); }, Pause: function () { this.Command("Pause"); },
	LogC: function () { var t = this; if (t.loggedC[this.video.id]) return; t.loggedC[this.video.id] = true; clearTimeout(this.logTO); if (typeof (this.video.type) == 'number') this.logTO = setTimeout(function () { Info.LogC(t.video.type, 0, t.video.id, 301) }, 2000); },
	Mute: function () { this.IsMute = !this.IsMute; var p = _("Player" + this.id); if (this.Silverlight) p.Content.p.Mute(this.IsMute); else p.settings.mute = p.settings.mute == true ? false : true; _("VMute" + this.id).style.backgroundPosition = '0 -' + (this.IsMute ? 17 : 30) + 'px' },
	VPlayPause: function () { if (this.playState == 3) this.Command("Pause"); else this.Play(); },
	UpdateMP: function () {
		var MP = _('Player' + this.id), x, iPos, sPos, playState;
		if (this.Silverlight) {
			var o = MP.Content.p; playState = o.PlayState(); sPos = o.PositionString().split(","); iPos = o.PositionInt();
			sPos = View.AddZero(sPos[0]) + ":" + View.AddZero(sPos[1]) + "/" + View.AddZero(sPos[2]) + ":" + View.AddZero(sPos[3])
		}
		else { sPos = MP.controls.currentPositionString + (MP.currentMedia ? " / " + MP.currentMedia.durationString : ""); playState = MP.playState; iPos = (MP.currentMedia ? Math.floor((MP.controls.currentPosition / (MP.currentMedia.duration > 0 ? MP.currentMedia.duration : 0)) * 100 + 0.999999999) : 0); }
		if (playState == 2 || playState == 3 && iPos != Infinity) {
			if (!this.Silverlight && !isNaN(iPos) && iPos != Infinity && MP.currentMedia.duration || iPos > 0) { _("VideoPosition" + this.id).style.width = (iPos / 100) * (this.size.width - 20) + "px" };
		};
		this.playState = playState;
		$("#VPlay" + this.id + " span").css("backgroundPosition", "-" + (playState == 3 ? 120 : 13) + "px -20px")
		_("VMarker" + this.id).innerHTML = sPos;
	},
	ChangePos: function (value) { if (this.AdIn) return false; MP = _("Player" + this.id); if (!this.Silverlight) MP.controls.currentPosition = MP.currentMedia.duration * (value / 100); else MP.Content.p.SetPosition(value); },
	ChangeVolume: function (value) {
		if (value < 10 || !value) return; value += 5; if (value > 100) value = 100;
		this.Volume = value; if (this.Silverlight) _('Player' + this.id).Content.p.SetVolume(value); else _('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), load = $('#divLoading' + this.id), other = $("#imgVideo" + this.id +",#VidLargePlay" + this.id);
		var bHidePlayer=this.audio&&!this.AdIn;
		if (this.playState > 1 && this.playState < 5) { load.hide(); other.hide(); p.style.visibility = this.size.height && (!bHidePlayer) ? '' : 'hidden'; if(bHidePlayer) $("#imgVideo" + this.id).show() }
		else { if ((this.Silverlight && this.playState != 5 || !this.Silverlight && this.playState != 1 && this.playState != 8 && this.playState != 6 && this.playState != 10) && this.playState) load.show(); else load.hide(); other.show(); p.style.visibility = 'hidden'; }
		p.style.height = this.size.height + (this.Silverlight ? 0 : 65) + "px"; p.style.width = (this.size.width - 20) + "px";
	},
	Writed: function () {
		this.IsSLLoad = function () { var t = this; if (this.IsWrited === true) return false; try { o = _('Player' + t.id).Content.p.SetVolume(1); this.Writed2() } catch (e) { setTimeout("Players[" + this.id + "].IsSLLoad()", 1000); } }
		if (this.Silverlight) this.IsSLLoad(); else this.Writed2();
	},
	Writed2: function () {
		this.ChangeVolume(this.Volume); this.SetVideo(this.video, 1); this.IsLoad();
		this.IsWrited = true;

		if (this.Silverlight) { }
		else { var s = 'Players[' + this.id + '].Clicked();'; if (this.TVZone > -1 && this.size.height > 10) ('<script for="Player' + this.id + '" event="Click">'+s+'</script>').write(); }
	},
	Changed: function () {
		p = _("Player" + this.id);
		if (this.Silverlight) { }
		else {
			if (p.lastDur != p.currentMedia.durationString) {
				this.AdUrl = "";
				for (var i = 0; i < p.currentMedia.attributeCount; i++) {
					var s = p.currentMedia.getAttributeName(i), v = p.currentMedia.getItemInfo(s)
					if (s == "AdLog") ExecuteUrl(v + "&_" + new Date().getTime());
					else if (s == "AdUrl") this.AdUrl = v;
				}
				this.AdIn=!!this.AdUrl;
				p.lastDur = p.currentMedia.durationString;
			}
		}
	},
	Clicked: function (url) { if (!url) url = this.AdUrl; if (!url) return false; var a = window.open(url, "icvtAD"); if (!a) location.href = url; },
	SetURL: function (url, notplay) { this.ActiveUrl = url; if (notplay) return false; this.LogC(); if (this.TVZone != -1 && this.size.height > 10) url = sOXMVCURL + "admin/OpenxAdministration/ASX?Zones=" + this.TVZone + "," + (this.TVZone + 1) + "&File=" + url; if (this.Silverlight) _('Player' + this.id).Content.p.SetUrl(url); else _('Player' + this.id).URL = url; this.UrlSetted = true },
	SetVideo: function (video, notplay) { this.audio= video &&(video.audio|| video.url.indexOf('.mp3')>0||video.url.indexOf('.wma')>0);  this.UrlSetted = false; video = this.MakeUrl(video); this.video = video; _("divVidTitle" + this.id).innerHTML = video.title; if (this.size.height>30) _("imgVideo" + this.id).src = !video.image?sStaticURL+'/images/radio/audio-video.jpg':GetImage(video.image, (this.size.width - 20), this.size.height); if (_("Player" + this.id)) this.SetURL(this.video.url, notplay); },
	MakeUrl: function (video) { if (video.url.indexOf(":") == -1) video.url = sMediaURLStart + video.url.replaceStr("//", "/"); return video },
	Dispose: function () { Players.remove(this.id); },
	UpdateInf: function (preload) { setTimeout("Players[" + this.id + "].UpdateInf()", 60000); if (preload || this.playState == 3) Info.LoadOne(211, "divVidInf" + this.id, { text: 1 }); }
}
function CheckPState()
{
	var played=false;
	for (var i=0;i<Players.length;i++)
	  if (Players[i]&&Players[i].IsWrited) {
		var player = _("Player"+i), p = Players[i], playState;
		p.UpdateMP()
		if(p.Silverlight) {p.IsLoad()}
		else {c=_("Player0").error.errorCount;  if(p.errorCount<c){p.errorCount=c;var err=player.error.item(c-1);
			if (err.errorCode==-1072885579&&player.URL.indexOf("File")>-1)player.URL=player.URL.split("File=")[1];
			else  location.href='/More/ActivePage.aspx/WMPErrors?error='+err.errorCode+";"+Escape(err.errorDescription); } }
		if (p.playState==3) {p.Changed()}
		if(p.playState>3&&p.bIsChanged) p.bIsChanged=false;
		if(p.lastState*1 != p.playState*1) p.lastState = p.playState;
		p.IsLoad()
		
		if (p.playState>1&&p.playState<8) played=true;
	}
	setTimeout(CheckPState,played?200:1000);
}


Maps = {
HTML: function(map) {
	var flashvars='dataPath='+Escape('/Controls/AjaxForm.ashx?action=map&map='+map.id);
	var size = ' width=450 height=363';
	return '<object style="border: solid 1px black" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" '+size+'  align="middle">\
 <param name="allowScriptAccess" value="sameDomain" /><param name="allowFullScreen" value="false" /><param name=flashvars value="'+flashvars+'" />\
<param name="movie" value="/static/cab/map.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" />	<embed src="/static/cab/map.swf"  style="border: solid 1px black" quality="high" bgcolor="#ffffff" flashvars='+flashvars+' '+size+' name="map" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" /></object>'
}
}
$(document).ready(function () {$('.VVideo').disableSelection();setTimeout(CheckPState,1500);})



function Album(id,pictures)
 { this.id=++iAutoNum;
   this.iAlbum=id; this.aImages=pictures;
   this.HTML=("<div id=divAlbumMiddleContent"+this.id+" class=divAlbumMiddleContent></div><div id=divAlbumHideIfOne"+this.id+" class=divRandN><div id=divAlbumRandN"+this.id+"></div><div id=divAlbumRandN2"+this.id+"></div><div id=divATitle"+this.id+"></div></div>")
   Album.Arr[this.id]=this;
   
 }
Album.Arr =[];
Album.GetImage= function(album,image,width,height){ return sStaticURL+"Resizer.ashx?source=albums&image="+image+"&a="+width+"&b="+height}
Album.prototype = {ActiveImage:0,
Init: function() {this.Items=this.aImages;this.iPages = Math.floor((this.aImages.length-1)/5+0.99999);this.Update(0); if(this.aImages.length==1) $("#divAlbumHideIfOne"+this.id).hide()},
Items:[],Page:0,URLStart:"",
	Update: function(page) {var s=["<table><tr>"];
	var end= (page+1)*5; if (end>this.aImages.length)end=this.aImages.length;
	 for(var i=page*5;i<end;i++){ s.push("<td><span class='img Link'  onclick=Album.Arr["+this.id+"].SetImage("+i+")><img src="+Album.GetImage(this.iAlbum , this.aImages[i].id ,136,83)+"&autocrop=1></td>");}
	 s.push("</td></tr></table>");
	 _("divAlbumRandN2"+this.id).innerHTML = ("<div class=BackNextButtons><span class='Button' style=float:right;"+(page==0?";color:gray":"cursor:pointer onclick=Album.Arr["+this.id+"].Update(Album.Arr["+this.id+"].Page-1);")+">&#9658;</span>  <span class='Button' style=float:left;"+(page>=(this.iPages-1) ?"color:gray":"cursor:pointer onclick=Album.Arr["+this.id+"].Update(Album.Arr["+this.id+"].Page+1);")+">&#9668;</span> </div>");
	 var d=_("divAlbumRandN"+this.id); 
	 $(d).animate({marginRight:this.Page>page?-300:300,opacity:0},500,(function(page,tid) {return function () {
	 d.innerHTML=s.string();$(d).css("margin-right",Album.Arr[tid].Page<page?-300:300).animate({marginRight:0,opacity:1}); Album.Arr[tid].Page=page;}})(page,this.id))
	
}, SetImage: function (id)
{
	_("divAlbumMiddleContent"+this.id+"").innerHTML = "<div style=text-align:center;height:334px><img  border=0 src="+Album.GetImage(this.iAlbum , this.aImages[id].id ,460,330)+ "&autocrop=1></div>";
	_("divATitle"+this.id).innerHTML= this.aImages[id].title
	iActiveImage = id;
}};

function SimpleAlbum(id,pictures)
{	var s="";
	for (var i=0;i<pictures.length;i++)
		s+= "<div style=margin-top:10px;text-align:center><img  border=0 src="+Album.GetImage(this.iAlbum , pictures[i].id ,460,950)+"><br/><b>"+pictures[i].title+"</b> "+pictures[i].credit+"</div>";
	return s;
}
if (!window.Radio) {
	Radio = { OpenPlayer: function (a, b) { Windows.Audio('#2#' + b) } }
}
