function loadContent( controllerUrl, contentPart, contentParam, contentDestiny ){

	var opt = {
		   method: "get",
	  asynchronous: true,
	    parameters: { contentPart: contentPart, contentParam: contentParam },
             onSuccess: function(t) {
             
             				for(var i=1; i<=7; i++)
             				{
             					var temp = "li_day_" + i;
             					var tempElement = $(temp);
             					if(tempElement)
             					{
             					  if(i<7)
             					  {
             					  	tempElement.className = "";
             					  }else{
             					  	tempElement.className = "last";
             					  }
             					}
             				}
             				
             				var temp = "li_day_" + contentParam;
             				var tempElement = $(temp);
             				if(tempElement)
             				{
             					if(contentParam < 7)
             					{
             						tempElement.className = "selected";
             					}else{
             						tempElement.className = "last selected";
             					}
             				}
             
					if(t.responseText && $(contentDestiny))
					{
						$(contentDestiny).innerHTML = t.responseText;
					}
		                     },
             onFailure: function(t) { return false; }
			
	}
	
	new Ajax.Request( controllerUrl, opt );
}

function reloadCurrentShow()
{
	var opt = {
				method: "get",
				asynchronous: true,
				parameters: 
							{
								contentPart: 'get_current_show_player'
							},
				onSuccess: function(t)
							{
								if(t.responseText && $('programName'))
								{
								      if($('programName').innerHTML != t.responseText)
								      {
									$('programName').innerHTML = t.responseText;
								      }
								}
							},
            onFailure: function(t) { return false; }
	}
	
	new Ajax.Request( 'ajax-controller/', opt );
}

function chartVote( controllerUrl, contentPart, voteSong, voteShow, contentDestiny )
{
	var opt = {
				method: "get",
				asynchronous: true,
				parameters: 
							{
								contentPart: contentPart, 
								voted: voteSong,
								show: voteShow 
							},
				onSuccess: function(t)
							{
								if(t.responseText && $(contentDestiny))
								{
									$(contentDestiny).innerHTML = t.responseText;
								}
							},
            onFailure: function(t) { return false; }
	}
	
	new Ajax.Request( controllerUrl, opt );
}

var currentSong = "";
var tempElementId = 0;
var tempContent = "";
var currentChartLinkElement = 0;
var smallPaused = false;

function createNewPlayer( songPath, targetId )
{

    if(currentSong && document.getElementById('smallPlayerChartList'))
    {
    	currentSong = 0;
    	document.getElementById('smallPlayerChartList').innerHTML = "";
    	currentChartLinkElement.className = "play";
    	currentChartLinkElement = 0;
    } 

	if(tempElementId != 0)
	{
		document.getElementById(tempElementId).innerHTML = tempContent; 
	}
	
	tempContent = document.getElementById(targetId).innerHTML
	tempElementId = targetId;
	
	var arhivePlayerSwf = new SWFObject("/fileadmin/template/player/playerik_mp3.swf","archivePlayer","145","26","8");
	
	arhivePlayerSwf.addParam("allowfullscreen","false");
	arhivePlayerSwf.addParam("allowscriptaccess","always");
	arhivePlayerSwf.addVariable("cesta", songPath );
	arhivePlayerSwf.addVariable("enablejs","true");
	arhivePlayerSwf.addParam("wmode", "transparent");
	arhivePlayerSwf.addVariable("javascriptid", "archivePlayer");
	arhivePlayerSwf.write(targetId);
	
}

function createNewSmallChartListPlayer( songPath, chartLinkElement )
{

	if(currentChartLinkElement)
	{
		currentChartLinkElement.className = "play";
	}

	if(chartLinkElement)
	{
		chartLinkElement.className = "play playing";
	}
	
	currentChartLinkElement = chartLinkElement;

	if(tempContent!="" && document.getElementById(tempElementId))
	{
		document.getElementById(tempElementId).innerHTML = tempContent; 
		tempContent = "";
		tempElementId = 0;
	}

	if(songPath == currentSong && $('chartlistplayer'))
	{
	
		if(smallPaused == false)
		{
			//pause
			$('chartlistplayer').sendEvent("PLAY", "false");
			smallPaused = true;
			
			if(currentChartLinkElement)
			{
				currentChartLinkElement.className = "play";
			}
			
		}else{
			
			//resume
			$('chartlistplayer').sendEvent("PLAY", "true");
			smallPaused = false;
			
			if(currentChartLinkElement)
			{
				currentChartLinkElement.className = "play playing";
			}
		}
		
	}else{

		var smallPlayerSwf = new SWFObject("/fileadmin/template/player/player.swf","chartlistplayer","1","1","8");
	
		smallPlayerSwf.addParam("allowfullscreen","false");
		smallPlayerSwf.addParam("allowscriptaccess","always");
		smallPlayerSwf.addVariable("file", songPath );
		smallPlayerSwf.addVariable("shuffle","false"); 
		smallPlayerSwf.addVariable("enablejs","true");
		smallPlayerSwf.addVariable("javascriptid", "chartlistplayer");
		smallPlayerSwf.write("smallPlayerChartList");
		
		currentSong = songPath;
	}
}


function playerReady(obj)
{
	$('chartlistplayer').sendEvent("VOLUME", "100");
	$('chartlistplayer').sendEvent("PLAY", "true");
	$('chartlistplayer').addModelListener("STATE", "stateTracker");
}

function stateTracker(obj)
{ 
	if(obj.newstate == "COMPLETED")
	{
		currentSong = 0;
		currentChartLinkElement.className = "play";
	}
}

function getCurrentSong()
{
	var tempSong = "";
	
	var opt = {
			method: "get",
			asynchronous: true,
                        requestHeaders: { 
                                          "Pragma":            "no-cache", 
                                          "Cache-Control":     "no-store, no-cache, must-revalidate, post-check=0, pre-check=0", 
                                          "Expires":           0, 
                                          "Last-Modified":     new Date(0), // January 1, 1970 
                                          "If-Modified-Since": new Date(0) 
	                                                },
			onSuccess: function(t)
						{
							tempSong = t.responseText;
							//tempSong = actualSong + " zajtra ";
							if(tempSong != actualSong)
							{
								var beziaciText = document.getElementById('current_song_flash');
								if(beziaciText)
								{
									beziaciText.SetVariable("texty", "--- " + tempSong + " ---");
									actualSong = tempSong;
									
								}else{
									
									thisMovie("current_song_flash").SetVariable("texty", "--- " + tempSong + " ---");
									actualSong = tempSong;
								}
							}
						},
        onFailure: function(t) { return false; }
	}

	//new Ajax.Request("/song/get_current_song.php", opt );
	new Ajax.Request("/currentsong.txt", opt);
	
}
var actualSong = "";
var newSongInterval = setInterval("getCurrentSong()", 10000);
