var pic_url="http://85.204.163.233:8080/snapshot.html";

var noframepath="http://www.livetraffic.ro/img/noimage.jpg";

var ErrorPath="http://www.livetraffic.ro/img/livetraffic.gif";

var GetItOn=1;

var recordmult=0;

var mode=0;

var buffer= new Image();

var aktiv=null;

var bmenu=0;//show live info : data and time





function DoComplete()

{

	debugmsg("DoComplete() buffer.src="+buffer.src);

	document.CamPic.src = buffer.src;

	GetItOn = 1;	

}

function LoadError()

{

	document.CamPic.src=noframepath;

	GetItOn = 1;

}

function setmode(playermode) 

{

//debugmsg("setmode:# mode: " + mode + " pmode: " + playermode);



	if (aktiv) 

	{

		window.clearInterval(aktiv);

		aktiv = null;

	}	

	switch(playermode)

	{

		case 1:

			recordmult=1; //1 frame/s

			aktiv=window.setInterval("Animation()",1000*recordmult);

			GetItOn=1;	

			Animation(); 

			break;
		case 0:
		case 2:

			recordmult=3; //3 sec

			aktiv=window.setInterval("Animation()",1000*recordmult);

			GetItOn=1;	

			Animation(); 

			break;

		case 3:

			recordmult=5; //5 sec

			aktiv=window.setInterval("Animation()",1000*recordmult);

			GetItOn=1;	

			Animation(); 

			break;

		case 4:

			recordmult=0.5; // 2 frame/s

			aktiv=window.setInterval("Animation()",1000*recordmult);

			GetItOn=1;	

			Animation(); 

			break;

		default:

			recordmult=0;

			break;

	}		 



}





function Animation()

{		

	  if (GetItOn == 1)		 	

	  {

			GetItOn = 0;

			//debugmsg("Animate:#"+" aktiv="+aktiv);

			document.CamPic.onerror=document.CamPic.onload=null;

			buffer.onerror= LoadError;

			buffer.onload = DoComplete;

			buffer.src = pic_url + "?rand=" + Math.floor(Math.random()*1000000);

			//debugmsg( "Animate:# url :"+ buffer.src );			

			DoComplete();

	}



}

function init(pic,speed) 

{

	if ( document.all && (navigator.platform.substr(0,3) != "Mac") ) {

		document.CamPic.insertAdjacentHTML("AfterEnd","<img border=0 style=\"display:none;\" name=dbbuffer></b>");

		buffer=document.dbbuffer;

	}

	pic_url=pic;

	debugmsg( "init:# url :"+ pic_url );			

	setmode(speed); 

}

//----------------------------------------------------------------------------

// menu for player and live info



function playmenu(){



if( !document.createElement || !document.childNodes ) {

        window.alert('Your browser is not DOM compliant');

} else {

        var div = document.getElementById('bmenu');

        if( document.getElementById('control')){

                var control = document.getElementById('control');

                div.removeChild(control);

                var p,a,img;

                divctrl=document.createElement('div');

                divctrl.id='control';

                p = document.createElement('p');

                // add start

                a = document.createElement('a');

                a.href='http://www.livetraffic.ro/cam';

                img = document.createElement('img');

                img.src='http://www.livetraffic.ro/player_files/player_begin_sw.gif';

                a.appendChild(img);

                p.appendChild(a);

                //add fast backward

                a = document.createElement('a');

                a.href='http://www.livetraffic.ro/cam';

                img = document.createElement('img');

                img.src='http://www.livetraffic.ro/player_files/player_fbackw_sw.gif';

                a.appendChild(img);

                p.appendChild(a);

                //add step backward

                a = document.createElement('a');

                a.href='http://www.livetraffic.ro/cam';

                img = document.createElement('img');

                img.src='http://www.livetraffic.ro/player_files/player_backw_sw.gif';

                a.appendChild(img);

                p.appendChild(a);

                //add play

                a = document.createElement('a');

                a.href='http://www.livetraffic.ro/cam';

                img = document.createElement('img');

                img.src='http://www.livetraffic.ro/player_files/player_play_sw.gif';

                a.appendChild(img);

                p.appendChild(a);

                //add step forward

                a = document.createElement('a');

                a.href='http://www.livetraffic.ro/cam';

                img = document.createElement('img');

                img.src='http://www.livetraffic.ro/player_files/player_forw_sw.gif';

                a.appendChild(img);

                p.appendChild(a);

                //add fast forward

                a = document.createElement('a');

                a.href='http://www.livetraffic.ro/cam';

                img = document.createElement('img');

                img.src='http://www.livetraffic.ro/player_files/player_fforw_sw.gif';

                a.appendChild(img);

                p.appendChild(a);

                //add end

                a = document.createElement('a');

                a.href='http://www.livetraffic.ro/cam';

				img = document.createElement('img');

                img.src='http://www.livetraffic.ro/player_files/player_end_sw.gif';

                a.appendChild(img);

                p.appendChild(a);

                divctrl.appendChild(p);

                div.appendChild(divctrl);

        }

   }

}

function liveinfo(){



if( !document.createElement || !document.childNodes ) {

        window.alert('Your browser is not DOM compliant');

} else {

        var div = document.getElementById('bmenu');

        if( document.getElementById('control')){

                var control = document.getElementById('control');

                div.removeChild(control);

                var p,span;

                divctrl=document.createElement('div');

                divctrl.id='control';

                p =  document.createElement('p');

                span = document.createElement('span');

                span.id='info';

                span.innerHTML='Actalizat: 11/11/2007 22:11';

                p.appendChild(span);

                divctrl.appendChild(p);

                div.appendChild(divctrl);

        }

    }

}





function live_play(){



if ( bmenu == 1 ){

        playmenu();

        bmenu=0;

}

else{

        liveinfo();

        bmenu=1;

}

}



//----------------------------------------------------------------------------

//ads img

var menu=0;



function golive(){



if( !document.createElement || !document.childNodes ) {

        window.alert('Your browser is not DOM compliant');

} else {

        var div = document.getElementById('camd');

        if( document.getElementById('ads')){



                var ads = document.getElementById('ads');

                div.removeChild(ads);

                var p,img;

                p = document.createElement('p');

                img = document.createElement('img');

                img.id='CamPic';

                img.src='http://85.204.163.233/cam/current.gif';

				img.alt='imagini trafic camera podul grand/truda';

                p.appendChild(img);

                div.appendChild(p);

        }

		if (document.all && document.all.CamPic)

			document.all.CamPic.style.width='auto'; 

		init('http://85.204.163.233:80/cam/current.gif',1); 

   }

}

//----------------------------------------------------------------------------

	// If the debug window exists, then write to it

	function debugmsg(text) {

	  if (window.top.debugWindow && ! window.top.debugWindow.closed) {

		window.top.debugWindow.document.write(text+"\n");

	  }

	}

	// If the debug window exists, then close it

	function hideDebug() {

	  if (window.top.debugWindow && ! window.top.debugWindow.closed) {

		window.top.debugWindow.close();

		window.top.debugWindow = null;

	  }

	}

	function showDebug() {

	window.top.debugWindow =

	  window.open("",

				  "Debug",

				  "left=0,top=0,width=300,height=700,scrollbars=yes,"

				  +"status=yes,resizable=yes");

	window.top.debugWindow.opener = self;

	// open the document for writing

	window.top.debugWindow.document.open();

	window.top.debugWindow.document.write(

	  "<HTML><HEAD><TITLE>Debug Window</TITLE></HEAD><BODY><PRE>\n");

	}