﻿aVI = new Array();

function VPlayPause(id) {MP = document.getElementById('Player'+id); if (MP.playState==3) MP.controls.Pause(); else  MP.controls.Play();}


function CheckFFWMP() {
	var is_WMP;
	for ( var i in navigator.plugins ) {
		var n = navigator.plugins[i].name; //alert(n);
		if ( n != null && n.indexOf("Windows Media") >= 0 && n.indexOf("Microsoft") == 0 )
			return true;
	}
	return false;
}


var iVolume = 100;
function AddZero(time) { if (time>10) return time; else return "0"+time}
function PaseTime(time){
	return Math.floor(AddZero(time/60)) + ":" + AddZero(Math.floor(time-(Math.floor(time/60))*60))
}
function UpdateMP(id)
{ 
	MP = document.getElementById('Player'+id);
	if(MP.playState==2||MP.playState==3)
		{
		iPos = Math.floor((MP.controls.currentPosition/MP.currentMedia.duration)*100+0.999999999)+1
		
		for (i=iPos;i<101;i++)	document.getElementById('pos'+id+'-'+ i).style.backgroundColor ='white';
		for (i=1;i<iPos;i++) document.getElementById('pos'+id+'-' + i).style.backgroundColor ='#4A80A6';
		MP.style.width='319px';MP.style.height='304px';
	} ;
	if (MP.playState==3) x ="pause";
	else x = "play";
	document.getElementById("VPlay"+id).firstChild.src="/images/invideo/a"+x+".png";
	document.getElementById("VMarker"+id).innerHTML = MP.controls.currentPositionString;
	document.getElementById("VLen"+id).innerHTML = MP.currentMedia.durationString;
}

function ChangePos(id,value)
{if (aVI[id].AdIn) return false; 	MP =document.getElementById("Player"+id); MP.controls.currentPosition=MP.currentMedia.duration*(value/100); UpdateMP(id); }

function ChangeVolume(id,value) {if (value>49) return false;
iVolume=value*2
 document.getElementById('Player'+id).settings.volume=iVolume;
 for (i=value;i<50;i++)
	document.getElementById('volume'+id+'-' + i).style.backgroundColor ='';
 for (i=1;i<value;i++)
	document.getElementById('volume'+id+'-' + i).style.backgroundColor ='#4A80A6';
}
function FullScreen(id)
{	MP =document.getElementById("Player"+id);
	if (MP.playState == 3 || MP.playState == 2 || MP.playState == 6) 
		MP.fullScreen = true;
}


function IsLoad(id)
{	if(navigator.userAgent.indexOf("MSIE")==-1) return false;
	var ps = document.getElementById('Player'+id).playState;
	if(ps<=2||ps==10) {document.getElementById('Player'+id).style.display='none'; document.getElementById('divLoading'+id).style.display="none";} else {
	if(ps==9||ps==6||ps==7) {document.getElementById('divLoading'+id).style.display="";  document.getElementById('divLoading'+id).innerHTML = 'Loading...'; document.getElementById('Player').style.display='none';}
	else {
	 document.getElementById('divLoading'+id).style.display="none"; document.getElementById('Player'+id).style.display='';}}
}

function fA (id) {if (aVI[id] && aVI[id].Url) {document.getElementById('Player'+id).URL='mms://msmedia.a7.org/arutz7/eng-video/'+aVI[id].Url; aVI[id].AdIn=true;document.getElementById('divVideoAd'+id).innerHTML=aVI[id].HTML;}
	else {document.getElementById("Player"+id).URL = Elements[id][2]; aVI[id].AdIn = false;}}

function ReplaceUrl(id) { try {IsLoad(id) } catch(e) {}
	if (document.getElementById("Player"+id).playState==8&&aVI[id].AdIn)
	{
		document.getElementById("Img").innerHTML = aVI[id].Img;
		aVI[id].AdIn = false;
		document.getElementById("Player"+id).URL = Elements[id][2];
		setTimeout("try {document.getElementById('Player"+id+"').controls.Play()} catch(e) {document.getElementById('Player"+id+"').controls.play();}",1000);//
	}
}

function CheckPState(id)
{	player = document.getElementById("Player"+id);
	if (player.playState==8||(player.playState==1&&Elements[id][4]==3)) ReplaceUrl(id)
	if(Elements[id][4] != player.playState) Elements[id][4] = player.playState;
	IsLoad(id)
	setTimeout(function () {CheckPState(id)},500);
}



function VideoElement(ElementId,sVideoURL,iVideoImage) {
	var id =Elements.length;
	aVI[id] = new Array();
	aVI[id].AdIn = true;
	Elements[id] = [ElementId,1,sVideoURL,iVideoImage];
	iShowV[id] =false;
	sPlayer = '<div style=color:white;><a style=color:white href='+sVideoURL+'>Click to start video</a> in external player';

	if (navigator.userAgent.indexOf("Firefox") > -1 &&!CheckFFWMP() &&navigator.platform=='Win32')
	sPlayer  = "<div style=color:white>Please Install Windows Media Player plugin for Firefox.<br><a target=_blank href=http://port25.technet.com/pages/windows-media-player-firefox-plugin-download.aspx style=color:white>Click here to install</a></div>";
	else if (navigator.userAgent.indexOf("Firefox") > -1 && CheckFFWMP()) {sPlayer = '<div align=center><object id=Player'+id+' width="319" height="304"  type="application/x-ms-wmp"><PARAM NAME="transparentatStart" VALUE="true"><PARAM NAME="stretchToFit" VALUE="true"><PARAM NAME="autoStart" VALUE="false"></OBJECT></div>'; document.getElementById("divElement"+ElementId).innerHTML = sPlayer; sPlayer="";}
	if (navigator.userAgent.indexOf("MSIE") > -1) {sPlayer =  '<object id=Player'+id+' classid=CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6 width="319" height="304"><PARAM NAME="enableContextMenu" VALUE="false"><PARAM NAME="stretchToFit" VALUE="false"><param name=url value=""><PARAM NAME="transparentatStart" VALUE="true"><PARAM NAME="autoStart" VALUE="false"></OBJECT>'}
	sBG = "";
	if (iVideoImage>0) sBG = "background-image:url(/static/pictures/resized/319-239/"+Math.floor(iVideoImage/1000)+"/"+iVideoImage+".jpg)";
	if (sPlayer != "") {
	sHTML = '<div class=VideoIn dir=ltr unselectable=on><div style="width:319px;height:239px;direction:ltr;overflow:hidden;position:absolute;ofveflow:hidden;left:11px;top:32px;'+sBG+'">'+sPlayer+'<div class=VideoLoadingOut><span style=display:none id=divLoading'+id+'></span></div></div><div class=VideoAd id=divVideoAd'+id+'></div><br /><div style="width:302px; font-size:1px; position:absolute; top: 305px; left:21px; border: solid 1px #426E84"><span id=pos'+id+'-0 style="display:none"></span>';

	for(i=1;i<101;i++)
	{
		sHTML += "<span onClick='ChangePos("+id+"," + i + ");'  id=pos"+id+"-" + i + " style='display:inline-block;width:3px;height:2px;background-color:white;'> </span>";
	}


	sHTML += '</div><br /><span class=VMarker id=VMarker'+id+'>1</span><span class=VLen id=VLen'+id+'>2</span>\
	<div class=VPlay id=VPlay'+id+' onclick="VPlayPause('+id+');"><img src=/images/invideo/aplay.png /></div>\
	<span class=VStop onclick="document.getElementById(\'Player'+id+'\').controls.Stop();">&nbsp;</span>\
	<span class=VMute onclick="document.getElementById(\'Player'+id+'\').settings.mute=document.getElementById(\'Player'+id+'\').settings.mute==true?false:true;">&nbsp;</span>\
	<span class=VFS   onclick="FullScreen('+id+')"></span>\
	<span class=VMinus onclick="ChangeVolume('+id+',iVolume/2-4)">&nbsp;</span>\
	<span class=VPlus onclick="ChangeVolume('+id+',iVolume/2+4)">&nbsp;</span>\
	<div class=VVol>'

	for(i=1;i<50;i++)
		sHTML += "<span onClick='ChangeVolume("+id+"," + i + ");' style='display:inline-block;width:1px;height:10px' id=volume"+id+"-" + i + "> </Span>";

	sHTML +='</div></div>';
	
	div = document.createElement("div");
	div.align='center';
	div.innerHTML = sHTML;
	document.getElementById("divElement"+ElementId).innerHTML="";
	document.getElementById("divElement"+ElementId).appendChild(div);
	
	
	//document.getElementById('Player'+id).playStateChange = IsLoad;
	document.getElementById('Player'+id).URL = sVideoURL;
	IsLoad(id);
	try {window.setInterval(function() {UpdateMP(id)},100); ChangeVolume(id,33);} catch(e){}
	}
		
	s= "<SCRI"+"PT FOR=Player"+id+" event=PlayStateChange>ReplaceUrl("+id+")</SCRIPT><script FOR=Player"+id+" event=Click>if (aVI["+id+"].AdIn) {x = window.open(aVI["+id+"].Link); if (!x) location.href=aVI["+id+"].Link}</script>"
	document.write(s)
	document.getElementById("Player"+id).stretchToFit = false
}

function ElementsAfterAll() {
	var s="";
	for (i=0;i<Elements.length;i++)
		if (Elements[i][1]==1) s+= "<script src=http://click.inn.co.il/videoInfo2_.php?zone=69&video="+i+"></script><script>setTimeout(function() {fA("+i+")},800);</script>";
	document.write("<style>.VideoIn {width:342px;height:363px;margin:10px 0px 10px 0px; background-image:url(/images/invideo/videobg.png); position: relative; direction:ltr} .VideoLoadingOut {position:absolute;top:220px;right:120px;color:white;text-align:right} .VideoLoadingOut span {display:inline-block;background-image:url(/images/invideo/load.gif);padding:0px 7px 0px 7px;width:66px;height:16px;overflow:hidden;font-weight:bold;}\
.VideoAd {position:absolute;left:105px;top:278px;}\
.VPlay {width:22px;height:22px;padding:10px 5px 0px 5px; cursor:pointer; position:absolute;top:310px;left:80px; text-align:center;}\
.VStop {position:absolute;top:324px;left:112px; width:17px;height:17px;cursor:pointer;}\
.VMute {position:absolute;top:324px; left:134px;height:17px;width:17px;cursor:pointer;}\
.VMinus {position:absolute;top:324px; left:153px;height:17px;width:10px;cursor:hand}\
.VPlus {position:absolute;top:324px; left:212px;height:17px;width:15px;cursor:hand}\
.VVol {position:absolute;top:328px; left:163px;direction:ltr;font-size:5px} \
.VText {position:absolute;top:43px;width:260px;left:4px;text-align:center}\
.VMarker {position:absolute;top:314px; left:4px;height:17px;width:50px;color:white; text-align:right} .VLen {position:absolute;top:314px;text-align:right;right:4px;height:17px;width:90px;color:white;}\
.VFS {width:29px;height:23px; cursor:pointer; position:absolute;top:310px;left:233px; text-align:center;padding-top:7px;padding-left:2px} </style><div style=display:none id=Img></div>"+s);
}