//var errorObj = new error( {errorReporting: true} );

var onairObj;
var streamObj;

function initRadiostationParams()
{ setupZoom();//fancy zoom
	timeDiff=timeDiff("servertime");
	
	onairObj=new onair( 
  { objName: 'onairObj',
    onairURL: '/xml/onair.xml',
    voteURL: '/xml/vote.php',
    onairBlockID: 'currently_onair',

    onairTitleID: 'title',
    onairRatingID: 'rating',
    onairVoteID: 'vote',
    onairStartID: 'start',
    onairEndID: 'end',
    current: 1,
    next: 2,
    onairArtistStyle: 'artist',
    onairNoArtistStyle: 'hiddenartist',
    onairTitleStyle: 'title',
   	onairOnlyTitleStyle: 'titlebold',
    maxInterval: 300000,
    defaultInterval: 10000,
    timeDiff: timeDiff
  } );
  
  onairObj.initTimer();
  
}

function timeDiff(timeID)
{ 
	//serverUnixTime=serverUnixTime * 1000;//mili
	
  var clientDateObj= new Date;
  var clientTime=clientDateObj.getTime();
  
  serverUnixTime=document.getElementById(timeID).value;
  serverUnixTime=parseInt(serverUnixTime, 10);
  var serverDateObj = new Date();
  serverDateObj.setTime(serverUnixTime);
  var serverTime=serverDateObj.getTime();
  timeDiffSec = parseInt( (serverTime - clientTime), 10);
  return(timeDiffSec);
}

/*
MENU
*/
var activeMenuId;

function activeMenu(id)
{ if(id != activeMenuId)
  { if(activeMenuId != undefined)
      document.getElementById(activeMenuId).className='li';
    document.getElementById(id).className='activemenu';
    activeMenuId=id;
  }
  curtain(1);
}

function curtain(flag)
{ visibility='hidden';
  if(flag != undefined)
    visibility='visible';  
  document.getElementById('curtain').style.visibility=visibility;
  document.getElementById('status').style.visibility=visibility;
}
debugit = function(object,message)
{ var body = message + "\n";
  for (property in object)
  { if(typeof(object[property]) != 'function')
      body += property + "(" + typeof(object[property]) + ") : "+ object[property] + "\n";
  }
  alert(body); 
}

var messages = new Array();
var msgObj;
function register(message,type)
{ msgObj = document.getElementById('messages');
  msgObj.innerHTML +="[" + type + "] " + message + "<br />"; 

}
function exchangeElementId(id1,id2)
{ document.getElementById(id1).id="tempid";
  document.getElementById(id2).id=id1;
  document.getElementById('tempid').id=id2;
}
function exchangeParamById(id1,id2,param)
{ tmp=document.getElementById(id1)[param];
  document.getElementById(id1)[param]=document.getElementById(id2)[param];
  document.getElementById(id2)[param]=tmp;
}
function submitForm(id)
{ document.getElementById(id).submit();
}
function mblockToggle(id)
{ 
	tbObj=document.getElementById(id + '_tb');
	//alert(tbObj.className);
	
	if(tbObj.className != "udtoggle_right" || tbObj.className == undefined )
	{ Effect.SlideUp(id + "_table");
		tbObj.className="udtoggle_right";
	}
	else
	{ Effect.SlideDown(id + "_table");
		tbObj.className="udtoggle_down";
	}
	
}
function scheduleAnim(curPos,nxtPos)
{ //alert(curPos +" "+ nxtPos);
  id='sch';
	width=221;
	trans=(nxtPos-curPos) * -1 * width;
  //tbObj=document.getElementById(id);
  new Effect.Move(id, { x: trans, y: 0, mode: 'relative' });
  
}

/*
flash plejeris
*/

var FlashHelper =
{
/*
	movieIsLoaded : function (theMovie)
	{
		if (typeof(theMovie) != "undefined")
		{ return theMovie.PercentLoaded() == 100;
		}
		else
		{ return false;
		}
  },
*/
	getMovie : function (movieName)
	{
  	if (navigator.appName.indexOf ("Microsoft") !=-1)
  	{ return window[movieName];
  	}
	  else
	  { return document[movieName];
	  }
	}
};

function player(name)
{
	this.obj = FlashHelper.getMovie(name);
	/*
	if (!FlashHelper.movieIsLoaded(this.obj)) return;
	*/
	this.play = function () {
		this.obj.SetVariable( 'komanda', 'grojam');
	};

	this.stop = function () {
		this.obj.SetVariable( 'komanda', 'stabdom');
	};

	this.pause = function () {
		this.obj.SetVariable( 'komanda', 'pauze');
	};

	return this;
}

var playOld="";
var playNew="";

function playstart(name)
{ if(playNew!=name)
	{ playOld=playNew;
		playNew=name;
		if(playOld)
	    player(playOld).pause();
  }  
}
