	var currentItem;
	var updateItem;
	var currentState;

	// this function is caught by the JavascriptView object of the player.
	function sendEvent(typ,prm) { $("playerID").sendEvent(typ,prm); };

	function getUpdate(typ,pr1,pr2,swf) {
		
		var htmlitem = $("item"); // html item container to update
		
		if (typ == "item") {
			currentItem = pr1;
		}
		else if(typ == "state" && pr1 == 2) {
			var obj = $("playerID").itemData(currentItem);
			if (typeof obj["duration"] != "undefined" && obj["duration"] > 0)
			{
				var song_id = obj["description"];
				
				new Ajax.Request('/ajax/getShabad.php', {
				  method: 'post',
				  parameters: "song_id="+song_id,
	       		onSuccess: function(resp){
	   	     		var shabadres = resp.responseText.evalJSON();
	   	     		if (shabadres.shabad_id) {
	   	     			htmlitem.innerHTML = "<a href='/pages/readshabad.php?shabad_id="+shabadres.shabad_id+"' target='_blank' class='readthisshabad'>Read this shabad</a>";
	   	     			new Effect.Highlight(htmlitem);
	   	     		} else {
	   	     			htmlitem.innerHTML = "";
	   	     		}
	      		}
				});
				
				if ($('shabad'+song_id)) { // only if we have a place to show shabads
					if ($$('#shabad'+song_id+' .readshabad').length > 0)
					{
						$$('.readthisshabad').first().observe('click', function(ev){	
							ev.stop();
							Control.Tabs.findByTabId('shabad'+song_id).setActiveTab('shabad'+song_id);
							var readShabadLink = $$('#shabad'+song_id+' .readshabad');
							Effect.ScrollTo('tabs_'+song_id);
							if (readShabadLink.length > 0)
								read_shabad(song_id);
						});
					}
				}		
				
			}
		}
		else if(typ == "state" && pr1 == 3) {
			currentState = pr1;
			updateItem = currentItem;
			setTimeout("getItemData(updateItem)",200);
			//alert("state update - state: " + pr1);
		}
		
		//var tmp = document.getElementById("item");
		//if (tmp) { tmp.innerHTML = "<b>Item:</b> " + currentItem; } 
	};
	function getItemData(idx) {
		//alert("getting Item data: " + currentItem + "state:" + currentState);
		var obj = $("playerID").itemData(idx);
		if (typeof obj["duration"] != "undefined" && obj["duration"] > 0)
		{
			new Ajax.Request("/updatesonghits.php?id="+obj["description"],
		  {
		    method:"get",
		    onSuccess: function(transport){
		      //var response = transport.responseText || "Song plays updated!";
		      var response = "Song plays updated for ";
		      $("item").innerHTML = response + obj["title"];
		    }.bind(this),
		    onFailure: function(){ var response = "Song plays update failed!"; $("item").innerHTML = response; }
		  });
		}
		else
			$("item").innerHTML = "Sorry, there is a problem with one of our file servers. Please try to reload the page."
	}
	
	// This is a javascript handler for the player and is always needed.
	function thisMovie(movieName) {
		if(navigator.appName.indexOf("Microsoft") != -1) {
			return window[movieName];
		} else {
			return document[movieName];
		}
	};
